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'),
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
),
],
)),
);
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'),
)
],
)),
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(),
),
),
],
),
),
);
}
}
xxxxxxxxxx
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text(
'Navigation Drawer',
),
backgroundColor: const Color(0xff764abc),
),
drawer: Drawer(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: [
const UserAccountsDrawerHeader( // <-- SEE HERE
decoration: BoxDecoration(color: const Color(0xff764abc)),
accountName: Text(
"Pinkesh Darji",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
accountEmail: Text(
"pinkesh.earth@gmail.com",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
currentAccountPicture: FlutterLogo(),
),
ListTile(
leading: Icon(
Icons.home,
),
title: const Text('Page 1'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
leading: Icon(
Icons.train,
),
title: const Text('Page 2'),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
body: Center(
child: Column(
children: [
SizedBox(
height: 50,
),
],
),
),
);