【发布时间】:2020-12-08 14:53:08
【问题描述】:
我在 android studio 中创建了一个应用程序来从一个屏幕导航到另一个屏幕。这里将两个无状态小部件创建为两个屏幕,并且都包含一个按钮来相互导航页面。 但是,当我运行该应用程序时,我的 android 手机上会生成一个红屏,我收到一条错误消息
exception 'Column's children must not contain any null values, but a null value was found at index 0'.
我在下面提供了我的代码:
首屏
class FirstScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("First Screen"),
),
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
center(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('assets/new 7wonders.jpg'),
fit: BoxFit.cover,
),
),
),
Text('New 7 Wonders',
style: TextStyle(fontSize: 40, fontStyle: FontStyle.italic),
),
RaisedButton(
child: Text("Bang Here"),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => SecondScreen()));
},
color: Colors.red,
textColor: Colors.yellow,
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
splashColor: Colors.grey,
)
],
),
),
),
);
}
center({BoxDecoration decoration}) {}
}
第二屏
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Screen"),
),
body: RaisedButton(
child: Text("Go to First page"),
onPressed:() {
Navigator.pop(context);
},
),
);
}
}
【问题讨论】:
-
如果我的回答对您原帖中指定的问题有帮助,请采纳。如果没有,请提供更多详细信息说明为什么没有。
-
它帮助了我。解决方案就在现场。
标签: android-studio flutter flutter-layout