简体   繁体   中英

Doesn't back button work with SafeArea View

Hey I have below screen where I am using SafeArea and BackButton . Here back button is not working with SafeArea.

Does anyone know how to fix the issue ?

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,
                  ),
                ),
              ],
            )
          ],
        ),
      )),
    );
  }
}

Removing the MaterialApp from your build function will do the trick! Use MaterialApp only for root page. Use Scaffold for routed pages and it will automatically create back button in AppBar.

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

Look at this example https://flutter.io/docs/cookbook/navigation/navigation-basics#complete-example

You need MaterialApp as the root of the app. After that, you can create as many page widgets as you want.

Then use Navigator to navigate between them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM