简体   繁体   中英

AppBar not showing in scaffold

I've being studying Flutter for about 4 days, it's becoming tedius, now I want put something together. I want to show a different AppBar content at each screen. But it seems my Scaffold's AppBar is begin ignored.

Here's my code:

class Login extends StatelessWidget{

  Widget build(BuildContext context){
    return  Scaffold(appBar: AppBar(title:Text( 'Identification') ), body: Stack( children: [RaisedButton( child: Text("logar"), onPressed: () => {
    Navigator.pushNamed(context, '/other-screen')
    })]));
  }
}

The app bar above it seems invisible, doesn't show

class MyApp extends StatelessWidget {

 // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'title placedholder',
      initialRoute: '/',

      routes: {
        '/' : (BuildContext context) => Login(),
        '/other-screen' : (BuildContext context) => Scaffold(body: Row(children: <Widget>[],))
      },

I have copied your code into DartPad and the first AppBar seems to be Ok. The problem is with your second page.

Every time you create a new Scaffold, you need to add an AppBar to it.

Try running flutter clean and then running it again.

I find this fixes most issues when the code is correct but the application doesn't reflect the intended behaviour.

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