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/颤振 (20272(: ═══╡ 控件库捕获的异常 ╞══════════════════════════════════════════════════════════════ I/颤振 (20272(:在构建 _BodyBuilder 时抛出以下断言: I/flutter (20272(: 不正确地使用了 ParentDataWidget。 I/Flutter (20272(:展开的小部件必须放在 Flex 小部件中。 I/颤振 (20272(:扩展(无深度,弯曲:1,脏(根本没有 Flex 祖先。 I/flutter (20272(:违规扩展的父级的所有权链为: I/flutter (20272(: _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← I/颤振 (20272(: AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#9611b 墨迹 I/颤振 (20272(:渲染器] ← 通知侦听器 ← 物理模型 ← ⋯ I/颤振 (20272(: I/颤振 (20272(:导致错误的相关小部件是: I/颤振 (20272(:脚手架 file:///Users/macbook/AndroidStudioProjects/monmercato/lib/Screens/Login.dart:37:12
您收到错误是因为您正在使用Expanded
小部件来包装您的Column
。
要解决此问题,请尝试:
1( 移除包装Column
的Expanded
小部件
2( 如果您希望小部件采用屏幕高度,请删除Expanded
小部件并用Container
包装Column
小部件(为容器提供宽度和高度属性(
检查下面的代码,它工作正常:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor:Colors.white,
Container(
// give the container your preferred height here
height: MediaQuery.of(context).size.height,
// give the container your preferred width here
width: MediaQuery.of(context).size.width,
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,)
],
),
),
],
),
)
],
),
),
],
),
),
);
我希望这有所帮助。
您只需删除第一个扩展的小部件。
Scaffold(
backgroundColor: Colors.white,
body: Column(// remove Expandede
children: <Widget>[