简体   繁体   中英

Why does my AppBar title change indentation?

I have a simple app with 2 pages. The main.dart file has 1 page set as home property of the MaterialApp as such:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MyApp',
      theme: ThemeData(
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyFirstPage(),
    );
  }
}

The first time this page loads up, the title is close to the left edge of the screen. On this first page I have a button that sends me to my second page using:

Navigator.push(context, PageRouteBuilder(pageBuilder: (_, a1, a2) => MySecondPage()));

On this page the title in the AppBar has a left indentation.

Likewise, I have a button on my second page that sends me to my first page using the same method as above with Navigator.push. This time however, the title of the page is indented the same as on my second page.

Why does my first page have that lack of indentation the first time it is opened? I suspect it is because it is accessed using the home property, but I still do not understand how I can change this.

It happens because when you push a page onto another, there is supposed to be a back button on the left of the title in the AppBar.

But when you launch the very first time. The FirstPage is the only widget on the activity stack so there is no back button to goto the previous activity.

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