Drawer (App Drawer) Simple UI Two

import "package:flutter/material.dart";

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "App Drawer",
debugShowCheckedModeBanner: false,
theme: ThemeData(
appBarTheme: const AppBarTheme(
backgroundColor: Colors.grey,
centerTitle: true,
),
),
home: const AppDrawerTwo(),
);
}
}

class AppDrawerTwo extends StatefulWidget {
const AppDrawerTwo({super.key});

@override
State<AppDrawerTwo> createState() => _AppDrawerTwoState();
}

class _AppDrawerTwoState extends State<AppDrawerTwo> {
var currentPage = DrawerSections.values;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("App Drawer"),
),
drawer: Drawer(
child: SingleChildScrollView(
child: Column(
children: [
const MyHeaderDrawer(),
myDrawerList(),
],
),
),
),
);
}

Widget myDrawerList() {
return Container(
padding: const EdgeInsets.only(top: 15.0),
child: Column(
/// Show the list of menu drawer
children: [
menuItem(1, "Dashboard", Icons.dashboard_outlined,
currentPage == DrawerSections.dashboard ? true : false),
menuItem(2, "Contacts", Icons.people_alt_outlined,
currentPage == DrawerSections.contacts ? true : false),
menuItem(3, "Events", Icons.event,
currentPage == DrawerSections.events ? true : false),
menuItem(4, "Notes", Icons.notes,
currentPage == DrawerSections.notes ? true : false),
menuItem(5, "Settings", Icons.settings_outlined,
currentPage == DrawerSections.settings ? true : false),
menuItem(6, "Notifications", Icons.notifications_outlined,
currentPage == DrawerSections.notifications ? true : false),
menuItem(7, "Privacy policy", Icons.privacy_tip_outlined,
currentPage == DrawerSections.privacy_policy ? true : false),
menuItem(8, "Send feedback", Icons.feedback_outlined,
currentPage == DrawerSections.send_feedback ? true : false),
],
),
);
}

Widget menuItem(int id, String title, IconData icon, bool selected) {
return Material(
color: selected ? Colors.grey[300] : Colors.transparent,
child: InkWell(
onTap: () {
Navigator.pop(context);
setState(
() {
if (id == 1) {
currentPage == DrawerSections.dashboard;
} else if (id == 2) {
currentPage == DrawerSections.contacts;
} else if (id == 3) {
currentPage == DrawerSections.events;
} else if (id == 4) {
currentPage == DrawerSections.notes;
} else if (id == 5) {
currentPage == DrawerSections.settings;
} else if (id == 6) {
currentPage == DrawerSections.notifications;
} else if (id == 7) {
currentPage == DrawerSections.privacy_policy;
} else if (id == 8) {
currentPage == DrawerSections.send_feedback;
}
},
);
},
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
children: [
Expanded(
child: Icon(
icon,
size: 20.0,
color: Colors.black,
),
),
Expanded(
flex: 1,
child: Text(
title,
style: const TextStyle(color: Colors.black, fontSize: 16.0),
),
),
],
),
),
),
);
}
}

enum DrawerSections {
dashboard,
contacts,
events,
notes,
settings,
notifications,
privacy_policy,
send_feedback
}

class MyHeaderDrawer extends StatefulWidget {
const MyHeaderDrawer({super.key});

@override
State<MyHeaderDrawer> createState() {
return MyHeaderDrawerState();
}
}

class MyHeaderDrawerState extends State<MyHeaderDrawer> {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.green[700],
width: double.infinity,
height: 200.0,
padding: const EdgeInsets.only(top: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.only(bottom: 10.0),
height: 70.0,
decoration: const BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage("assets/images/Lord-Hanuman.jpg"),
),
),
),
const Text(
"Rapid Tech",
style: TextStyle(color: Colors.white, fontSize: 20.0),
),
Text(
"info@rapidtech.dev",
style: TextStyle(color: Colors.grey[200], fontSize: 14.0),
),
],
),
);
}

} 



Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter