import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green, // Set the app's primary theme color
),
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Grouped Drawer Example'),
),
drawer: buildGroupedDrawer(context),
body: Center(
child: Text('Grouped Items Nabigation Drawer'),
),
);
}
// Function to build the grouped drawer
Widget buildGroupedDrawer(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
// Drawer header
DrawerHeader(
decoration: BoxDecoration(
color: Colors.green,
),
child: Text(
'Grouped Items Nabigation Drawer',
style: TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
// First group with ExpansionTile
ExpansionTile(
title: Text('Group 1'),
children: <Widget>[
ListTile(
title: Text('Element 1.1'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Element 1.2'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Element 1.3'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Element 1.4'),
onTap: () {
Navigator.pop(context);
},
),
],
),
// Second group with ExpansionTile
ExpansionTile(
title: Text('Group 2'),
children: <Widget>[
ListTile(
title: Text('Element 2.1'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Element 2.2'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Element 2.3'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
title: Text('Element 2.4'),
onTap: () {
Navigator.pop(context);
},
),
],
),
],
),
);
}
}