How to add navigation drawer & silver AppBar to below dart code?

Viewed 471
```
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'demo',
      theme: ThemeData(
        primarySwatch: Colors.teal,
      ),
      home: Scaffold(
        appBar: AppBar(title: Text('demo title'),centerTitle: true,),
        body: //how can I add navigation drawer and Silver AppBar,
      ),
    );
  }
}


````
  1. This code indicates to the homepage of my flutter app

  2. I want to add a navigation drawer and sliverAppBar to the home page of this app

  3. But I don't know how to do this? 4.Please help me. How can I add navigation drawer in the above code [homepage of app]

Is there any easier way to add a navigation drawer to flutter [beginner level]

2 Answers

Add drawer to Scaffold

Scaffold(
        appBar: AppBar(title: Text('demo title'),centerTitle: true,),
        body: BodyLayout(),
        drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text('Drawer Header'),
            ),
            ListTile(
              title: Text('Example'),
              onTap: () {
              },
            ),
          ],
        ),
      ),
      ),

You can add drawer: Drawer(), to your scaffold. This gives you the hamburguer icon and a backdrop when clicked. From there you have freedom to create your tiles with your desired routes

Related