Navigation - Drawer
Drawer
Source Code
import 'package:flutter/material.dart';
void main() {
runApp( MaterialApp(
title:" Drawer ",
home:Scaffold(appBar: AppBar(title: Text(' Drawer ',),),
body: Material(
child: Center(
child:
NavDrawerExample()
,
),
) ,
),
));
}
class NavDrawerExample extends StatelessWidget {
const NavDrawerExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
const drawerHeader = UserAccountsDrawerHeader(
accountName: Text('User Name'),
accountEmail: Text('user.name@email.com'),
currentAccountPicture: CircleAvatar(
backgroundColor: Colors.white,
child: FlutterLogo(size: 42.0),
),
otherAccountsPictures: <Widget>[
CircleAvatar(
backgroundColor: Colors.yellow,
child: Text('A'),
),
CircleAvatar(
backgroundColor: Colors.red,
child: Text('B'),
)
],
);
final drawerItems = ListView(
children: <Widget>[
drawerHeader,
ListTile(
title: const Text('To page 1'),
onTap: () => Navigator.of(context).push(_NewPage(1)),
),
ListTile(
title: const Text('To page 2'),
onTap: () => Navigator.of(context).push(_NewPage(2)),
),
ListTile(
title: const Text('other drawer item'),
onTap: () {},
),
],
);
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.amber,
title: const Text('Drawer example'),
),
body: const Center(
child: Text('Swip or click upper-left icon to see drawer.'),
),
drawer: Drawer(
child: drawerItems,
));
}
}
// <void> means this route returns nothing.
class _NewPage extends MaterialPageRoute<void> {
_NewPage(int id)
: super(builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page $id'),
elevation: 1.0,
),
body: Center(
child: Text('Page $id'),
),
);
});
}
Comments
Post a Comment