首页 > 解决方案 > 后退按钮不适用于 SafeArea 视图

问题描述

嘿,我在下面的屏幕上使用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,
                  ),
                ),
              ],
            )
          ],
        ),
      )),
    );
  }
}

标签: androidiosflutter

解决方案


从你的构建函数中删除MaterialApp就可以了!仅用于MaterialApp根页面。用于Scaffold路由页面,它会自动在 AppBar 中创建返回按钮。

appBar:  PreferredSize(child: AppBar(
    elevation: 0.0,
  ),
      preferredSize: Size.fromHeight(0.0)
  )

推荐阅读