flutter 使用SngleChildScrollView时呈现库捕获到异常

ijxebb2r  于 2023-06-07  发布在  Flutter
关注(0)|答案(1)|浏览(196)

使用SingleChildScrollview时出现此错误

Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderRepaintBoundary#f9e13 relayoutBoundary=up1 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
box.dart:1
Failed assertion: line 1966 pos 12: 'hasSize'
class MyApp extends StatelessWidget {
  const MyApp({super.key});
 
  
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home:DefaultTabController(
          length: 2,
          child: Scaffold(
            backgroundColor: Colors.white,
            appBar: AppBar(
              elevation: 0.0,
              backgroundColor: Colors.white,
              bottom:const TabBar(
                labelColor: Color.fromARGB(255,255, 166, 159,),
                unselectedLabelColor: Color.fromARGB(255,105, 112, 114,),
                indicatorColor: Color.fromARGB(255,255, 166, 159,),
                indicatorWeight: 2,
                indicatorPadding: EdgeInsets.only(left: 24.5,right: 24.5),
                indicatorSize: TabBarIndicatorSize.tab,
                tabs: [
                   Tab(
                    height: 30,
                      child: Text("3112 Followers",style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold),),
                    ),
                    Tab(
                    child: Text("376 Subscribers",style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold),),
                    ),
                ],
                   )
              ,
              leading: 
                const  IconButton(
                  icon: Icon(Icons.arrow_back),
                  color: Color.fromARGB(255, 8, 13, 15),
                  iconSize: 39,
                  onPressed: null      ),
              title: const Text('Phil Schuster\'s guppies',style: TextStyle(color: Color.fromARGB(255, 5, 16, 20,),fontSize: 20,fontWeight: FontWeight.bold),),
            ),
            
        body:
          SingleChildScrollView(
            child: TabBarView(
                       children: [
                            Column(
                              
                                children: <Widget>[
                                  const SizedBox(height: 16,),
                                  SizedBox(
                                    height: 48,
                                    width: 366,
                                    child: Container(
                                      
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(12),
                                        color: const Color.fromARGB(255,247, 247, 247),
                                      ),
                                      child:
                                            
                                              TextFormField(
                                              
                                              decoration: const InputDecoration(
                                                hintText: "Search",
                                                prefixIcon: Icon(Icons.search),
                                                prefixIconColor: Color.fromARGB(255,116, 114, 114, ),
                                                hintStyle: TextStyle(color: Color.fromARGB(255,161, 161, 161,),fontSize: 18,fontWeight: FontWeight.bold),
                                                border: InputBorder.none,
                                              ),
                                                                          
                                                                          
                                                                        
                                                                           ),
                                            
                                        
                                      
                                      
                                    
                                    ),
                          
                                  ),
                                  const SizedBox(height: 24,),
                                   SizedBox(
                                    width: 366,
                                    child:
                                         Column(
                                          children: [
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/1.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Emma Jensen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("emma_jensen_02",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                                               const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/2.jpg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Alfred Hansen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("alfred_hansen",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                                             const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/3.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Alberte Jorgensen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("alberte_jorgensen",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                                              const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/4.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Marie Olsen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("marie_olsen",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                                              const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/5.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Sofia Andersen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("sofia_andersen",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                                              
                                               const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/6.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Melissa Pohl",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("melissa_pohl",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                          
                                              const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/7.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Christian Larsen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("christian_larsen",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                          
                                                const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/8.jpg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Mikkel Rasmussen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("mikkel_rasmussen",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                                              ],
                                            )
                            
                            
                                        )
                                   
                                    
                                  
                                ],
                            ),
                            Column(
                              
                                children: <Widget>[
                                  const SizedBox(height: 16,),
                                  SizedBox(
                                    height: 48,
                                    width: 366,
                                    child: Container(
                                      
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(12),
                                        color: const Color.fromARGB(255,247, 247, 247),
                                      ),
                                      child:   TextFormField(
                                              
                                              decoration: const InputDecoration(
                                                hintText: "Search",
                                                prefixIcon: Icon(Icons.search),
                                                prefixIconColor: Color.fromARGB(255,116, 114, 114, ),
                                                hintStyle: TextStyle(color: Color.fromARGB(255,161, 161, 161,),fontSize: 18,fontWeight: FontWeight.bold),
                                                border: InputBorder.none,
                                              ),
                                                                          
                                                                          
                                                                        
                                                                           ),
                                            
                                      
                                    
                                    ),
                          
                                  ),
                                  const SizedBox(height: 24,),
                                   SizedBox(
                                    width: 366,
                                    child:
                                         Column(
                                          children: [
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
  
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/5.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Sofia Andersen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("sofia_andersen",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                                              
                                               const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/6.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Melissa Pohl",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("melissa_pohl",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              height: 1,
                                              child: Container(
                                                color: const Color.fromARGB(255,225, 225, 225),
                                              ),
                                              ),
                          
                                              const SizedBox(height: 12,),
                                            const Row(
                                              children: [
                                                CircleAvatar(
                                                  radius: 26,
                                                  backgroundImage: AssetImage('assets/images/7.jpeg'),
                                                ),
                                                SizedBox(width: 16,),
                                                Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    Text("Christian Larsen",style: TextStyle(color: Color.fromARGB(255, 6, 16, 20,),fontSize: 18,fontWeight: FontWeight.bold),),
                                                    SizedBox(height: 9,),
                                                    Text("christian_larsen",style: TextStyle(color: Color.fromARGB(127, 6, 16, 20),fontSize: 14,fontWeight: FontWeight.bold),),
                                                  ],
                                                )
                          
                                              ],
                                            ),
                                            const SizedBox(height: 12,),
                                            SizedBox(
                                              width: 366,
                                              ]

它不应该给出那个错误

ghhkc1vu

ghhkc1vu1#

基本上你的错误的意思是没有屏幕的大小,所以,你需要给予高度的SingleChildScrollView。要解决这个问题,只需在SingleChildScrollView之前使用SizedBox widget

body: SizedBox(
   height: MediaQuery.of(context).size.height,
   width: MediaQuery.of(context).size.width,
   child: SingleChildScrollView(
     child:......
   ),
),

相关问题