Diego Alves
Diego Alves

Reputation: 2687

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

Upvotes: 0

Views: 6370

Answers (2)

Sam
Sam

Reputation: 348

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.

Upvotes: 1

siega
siega

Reputation: 2887

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.

Upvotes: 2

Related Questions