ios - 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):
解决方案
您只需删除 First Expanded Widget。
Scaffold(
backgroundColor: Colors.white,
body: Column(// remove Expandede
children: <Widget>[
推荐阅读
- python - 如何遍历 Pandas DF 中的列以检查某个值并返回同一行但来自不同列的值?
- android - How Could I use array to show match Imageview?
- c# - 从应用程序外部的任何地方获取选定的文本
- git - 如何将 git 存储库一分为二,但同时保留两者的 git 历史记录?
- jpa - 如何使用 JPA/EJB3 和 WildFly 读取未提交的数据?
- amcharts4 - Amcharts4 numberFormatter 百分比不起作用
- php - 使用保护的经过身份验证的用户出错并且可以访问某些模型
- css - 鼠标离开目标时背景过渡闪烁
- c# - 从另一个窗口窗体访问变量并将其传递给其他 .exe 程序:
- java - 在远程服务器上执行 ssh 以跳转到另一台服务器并使用 Java 和 JSch 在那里执行进一步的命令