后退按钮不能与SafeArea View一起使用

时间:2019-01-05 13:03:47

标签: android ios flutter

嘿,我在下面的屏幕上使用SafeAreaBackButton。此处的后退按钮不适用于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,
                  ),
                ),
              ],
            )
          ],
        ),
      )),
    );
  }
}

2 个答案:

答案 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在它们之间导航。