xxxxxxxxxx
// Full Code
return Scaffold(
appBar: AppBar(title: const Text("Flutter CRUD")),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
ListTile(
leading: Icon(Icons.list),
title: Text('READ'),
onTap: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (BuildContext context) => const HomePage(),
),
);
},
),
ListTile(
leading: Icon(Icons.search),
title: Text('SELECT'),
onTap: () {
Navigator.pop(context);
},
),
],
)),
);
xxxxxxxxxx
Scaffold(
drawer: Drawer(
child: ListView(
children: [
ListTile(
leading: Icon(Icons.message),
title: Text('Messages'),
),
ListTile(
leading: Icon(Icons.account_circle),
title: Text('Profile'),
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
),
],
)),
);
xxxxxxxxxx
Scaffold(
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
DrawerHeader(
child: Text("Header")),
ListTile(
title: Text("Home"))
]),
),
);
xxxxxxxxxx
Scaffold(
drawer: Drawer(
child: ListView(
children: [
ListTile(
leading: Icon(Icons.message),
title: Text('Messages'),
),
ListTile(
leading: Icon(Icons.account_circle),
title: Text('Profile'),
)
],
)),
body: Container(child: Center(child: InkWell(child: Text("Click to show drawer"), onTap: (){ Scaffold.of(context).openDrawer();})))
);
xxxxxxxxxx
class DrawerTutorial extends StatelessWidget {
const DrawerTutorial({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Drawer Tutorial"),
),
drawer: Drawer(
child: ListView(
children: const [
DrawerHeader(
child: Center(
child: Text(
"Welcome to AllAboutFlutter.com",
),
),
decoration: BoxDecoration(color: Colors.blue),
),
ListTile(
title: Text("Website for Flutter"),
),
ListTile(
title: Text(
"Subscribe to get notified for new tutorials.",
),
),
],
),
),
body: Center(
child: Wrap(
alignment: WrapAlignment.spaceAround,
children: [
RichText(
text: const TextSpan(
text: "Press the ",
style: TextStyle(color: Colors.black, fontSize: 32),
children: [
WidgetSpan(
child: Icon(
Icons.menu,
size: 32,
)),
TextSpan(text: " button to open the drawer"),
],
),
),
],
),
),
);
}
}
xxxxxxxxxx
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
var scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: ThemeData(
// Define the default Brightness and Colors
brightness: Brightness.dark,
primaryColor: Colors.lightBlue[800],
accentColor: Colors.cyan[600],
),
home: Scaffold(
key: scaffoldKey,
drawer: new Drawer(
child: new ListView(),
),
body: Stack(
children: <Widget>[
new Center(
child: new Column(
children: <Widget>[],
)),
Positioned(
left: 10,
top: 20,
child: IconButton(
icon: Icon(Icons.menu),
onPressed: () => scaffoldKey.currentState.openDrawer(),
),
),
],
),
),
);
}
}