Drawer - Building menus in your Flutter APP
Menus are a
quite important part of any APP, because it makes possible to users to navigate
through the APPs screens.
For
building Menus with Flutter a simple alternative is based on the usage of Drawer
class.
In the block
of code below, you can see it is just a Widget, composed by a header, with its
title, and then can have a set of ListTile widgets, which will represent it
menu item. These items may be composed by icons, titles, and of course the
action that is triggered with they are clicked.
class
NavDrawer extends StatelessWidget
{
@override
Widget build(BuildContext
context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text(
'Menu',
style: TextStyle(color:
Colors.white,
fontSize: 25),
),
decoration: BoxDecoration(
color: Colors.grey,
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage('assets/images/cover.jpg'))),
),
ListTile(
leading: Icon(Icons.input),
title: Text('Messages
Demo'),
onTap: () => {Navigator.push(
context, MaterialPageRoute(builder: (context) => MessagesExample()))},
),
Then, once
the Drawer is defined you can use that in your another screens, assigning a drawer
object to their drawer attribute, as we have in this example below:
Widget build(BuildContext context) {
return Scaffold(
drawer: NavDrawer(),
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
This will make your interface looks like this: You can take a copy of a full working example here: https://github.com/rafaelqg/flutter_dart_example A video class explaining this code is available here:
https://www.youtube.com/watch?v=kPFMmaWhnTU
Comments
Post a Comment