title: Flutter navigation with generalized AppBar
body: <p>I am currently writing a Flutter app. I have got a class AdvancedAppBar which extends AppBar and is used as gerneralized AppBar for most of the screens. It is is a separate file. The AdvancedAppBar has a FlatButton and a PopUpMenu as children. By pushing these buttons I would like to navigate to another screen.
  At the moment, I use the Navigator class for navigation between the screens but as far as I know, this assumes a BuildContext and I don't know how or if it is possible at all to define a BuildContext for an AppBar. </p>
  
  <p>How can realize this navigation?</p>
  
  <pre><code>class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        theme: ThemeData(
          primarySwatch: Colors.blue
        ),
        initialRoute: '/',
        routes: {
          '/': (context) =&gt; HomeScreen(),
          '/notifications': (context) =&gt; NotificationScreen(),
        },
      );
    }
  }
  
  
  class HomeScreen extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: new AdvancedAppBar(),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: &lt;Widget&gt;[
              new MaterialButton(
                height: 40.0,
                minWidth: 300.0,
                color: Colors.blue,
                textColor: Colors.white,
                child: new Text("Nachrichten", textScaleFactor: 2.0,),
                onPressed: (){
                  Navigator.pushNamed(context, '/notifications');
                  },
              )
            ],
          ),
        ),
      );
    }
  }
  
  
  class AdvancedAppBar extends AppBar{
  
  
    AdvancedAppBar({Key key}) : super(
          key: key,
          title:
          Container(child: ConstrainedBox(
          constraints: BoxConstraints.expand(),
            child: FlatButton(
            onPressed: () {
              // here I would like to navigate to another screen
            },
           padding: EdgeInsets.all(0.0),
           child: Image.asset('assets/images/Logo.png')
           )
           )
           ),
          actions: &lt;Widget&gt;[
            PopupMenuButton&lt;PopUpStates&gt;(
    onSelected: (PopUpStates result) {
      switch (result) {
        case PopUpStates.settings: {
        // here I would like to navigate to another screen
        } 
          break;
        case PopUpStates.logout: {
        // here I would like to navigate to another screen
        } 
        break;
        default:
      }},
    itemBuilder: (BuildContext context) =&gt; &lt;PopupMenuEntry&lt;PopUpStates&gt;&gt;[
      const PopupMenuItem&lt;PopUpStates&gt;(
        value: PopUpStates.settings,
        child: Text('Einstellungen'),
      ),
      const PopupMenuItem&lt;PopUpStates&gt;(
        value: PopUpStates.logout,
        child: Text('Ausloggen'),
      ),
    ],
  )
          ],
          automaticallyImplyLeading: false
    );
  
  }
  
  
  </code></pre>