首页 > 解决方案 > ParentWidget 的使用不正确。展开的小部件必须放在 flex 小部件内

问题描述

Widget build(BuildContext context) {
return Scaffold(
  backgroundColor:Colors.white,
  body:Expanded(
    child: Column(
     children: <Widget>[
       Container(
         child: Column(
           children: <Widget>[
             Container(
               width: MediaQuery.of(context).size.width*0.9,
               height: MediaQuery.of(context).size.height*0.22,
               color: Colors.white,
               child: Column(
                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
                 children: <Widget>[
                   SizedBox(height: 36.0,),

                   Row(
                     mainAxisAlignment: MainAxisAlignment.spaceBetween,
                     children: <Widget>[
                       Text("MON COMPTE",style: TextStyle(fontSize:30,fontWeight:FontWeight.bold),),
                       Container(
                         height: 50.0,
                         width: 50.0,
                         child: FloatingActionButton(
                           backgroundColor: Color(0xffd57031),
                           onPressed: (){

                           },
                           child: Icon(Icons.help_outline,size: 30.0,),),
                       ),
                     ],
                   ),
                   Row(
                     mainAxisAlignment: MainAxisAlignment.spaceBetween,
                     children: <Widget>[
                       Container(
                           decoration: BoxDecoration(

                               border:Border(bottom: BorderSide(color: Color(0xffd57031),width: check?3.0:1.0))
                           ),
                           width: MediaQuery.of(context).size.width/2.2,
                           child: FlatButton(onPressed: (){
                             setState(() {
                               check = true;

                             });
                             ctrl.animateToPage(0, duration: Duration(milliseconds: 200), curve: Curves.fastOutSlowIn);
                           }, child: Text("Se connecter",style:TextStyle(color: Color(0xffd57031),fontSize: 20,fontWeight: FontWeight.bold)))),
                       Container(
                           decoration: BoxDecoration(
                               border:Border(bottom: BorderSide(color: Color(0xffd57031),width: check?1.0:3.0))
                           ),
                           width: MediaQuery.of(context).size.width/2.31,
                           child: FlatButton(onPressed: (){
                             setState(() {
                               check = false;

                             });
                             ctrl.animateToPage(1, duration: Duration(milliseconds: 200), curve: Curves.fastOutSlowIn);
                           }, child: Text("S'inscrire",style:TextStyle(color: Color(0xffd57031),fontSize: 20,fontWeight: FontWeight.bold)))),
                     ],
                   )
                 ],
               ),

             ),
             Container(
               height:MediaQuery.of(context).size.height*0.78,
               child: PageView(
                 controller: ctrl,
                 children: <Widget>[
                   Container(
                     child: Column(
                       mainAxisAlignment: MainAxisAlignment.start,
                       children: <Widget>[
                         SizedBox(height:20.0),
                         txtField("E-mail"),
                         SizedBox(height:20.0),
                         txtField("Mot de passe"),
                         SizedBox(height:40.0),
                         Container(
                             decoration: BoxDecoration(
                               boxShadow: [
                                 BoxShadow(
                                     color: Colors.black12,
                                     blurRadius: 20.0,
                                     spreadRadius: 5.0
                                 )
                               ],
                             ),
                             width: MediaQuery.of(context).size.width*0.7,
                             height: 50.0,
                             child: FlatButton(onPressed: (){}, child: Text("Se connecter",style: TextStyle(color:Colors.white,)),color: Color(0xffd57031),)),
                         SizedBox(height:40.0),
                         Text('Mot de passe oublié ?',style: TextStyle(color:Color(0xffd57031),),),

                         Divider(color: Color(0xffd57031),thickness: 1.5,indent: 112.0,endIndent: 125,height:1,)
                       ],
                     ),
                   ),

                 ],
               ),
             )
           ],
         ),
       ),
     ],
    ),
  ),
);

} 并且有错误 I/flutter (20272): ══╡ WIDGETS LIBRARY ╞═══════════════════════␐═══════════ ═══════════════════════════════ I/flutter(20272):在构建_BodyBuilder时抛出了以下断言:I/flutter( 20272):ParentDataWidget 的使用不正确。I/flutter (20272):扩展的小部件必须放在 Flex 小部件内。I/flutter (20272): Expanded(no depth, flex: 1, dirty) 根本没有 Flex 祖先。I/flutter (20272):违规 Expanded 父级的所有权链为:I/flutter (20272):_BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← I/flutter (20272): AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#9611b ink I/flutter (20272): 渲染器] ← NotificationListener ← PhysicalModel ← ⋯ I/flutter (20272): I/flutter (20272):

标签: iosflutterdartmobilewidget

解决方案


您只需删除 First Expanded Widget。

Scaffold(
      backgroundColor: Colors.white,
      body: Column(// remove Expandede
        children: <Widget>[

推荐阅读