嘿,我在下面的屏幕上使用SafeArea
和BackButton
。此处的后退按钮不适用于SafeArea。
有人知道如何解决此问题吗?
class _ProfileScreenState extends State<ProfileScreen> {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new SafeArea(
child: Scaffold(
body: new Column(
children: <Widget>[
new Stack(
children: <Widget>[
Stack(
children: <Widget>[
new Row(
children: <Widget>[
new Expanded(
child: new Image.asset('assets/images/profile.jpg',
fit: BoxFit.fill, height: 250),
),
],
),
new Container(
alignment: Alignment.topLeft,
margin: EdgeInsets.only(top: 220, left: 22),
child: new Text("Eilly",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 15)),
)
],
),
new Container(
alignment: Alignment.topLeft,
child: new BackButton(
color: Colors.white,
),
),
],
)
],
),
)),
);
}
}
答案 0 :(得分:2)
从构建函数中删除MaterialApp
可以解决问题! MaterialApp
仅用于根页面。将Scaffold
用于路由页面,它将自动在AppBar中创建后退按钮。
appBar: PreferredSize(child: AppBar(
elevation: 0.0,
),
preferredSize: Size.fromHeight(0.0)
)
答案 1 :(得分:1)
看这个例子https://flutter.io/docs/cookbook/navigation/navigation-basics#complete-example
您需要MaterialApp
作为应用程序的根目录。
之后,您可以根据需要创建任意数量的page widgets
。
然后使用Navigator
在它们之间导航。