import 'package:cheminova/controller/home_controller.dart'; import 'package:cheminova/models/user_model.dart'; import 'package:cheminova/screens/authentication/change_password_screen.dart'; import 'package:cheminova/screens/authentication/login_screen.dart'; import 'package:cheminova/screens/authentication/profile_screen.dart'; import 'package:cheminova/screens/home_screen.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; class MyDrawer extends StatefulWidget { final UserModel? userModel; MyDrawer({super.key, this.userModel}); @override State createState() => _MyDrawerState(); } class _MyDrawerState extends State { final homecontroller = Get.put(HomeController()); // Initialize HomeController @override Widget build(BuildContext context) { final user = homecontroller.user; // Get the current user from HomeController return Drawer( child: ListView( padding: EdgeInsets.zero, children: [ SizedBox( height: 150, // Drawer header displaying user information child: DrawerHeader( decoration: const BoxDecoration( color: Colors.black87, ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ Text( user!.name ?? "username", style: const TextStyle( color: Colors.white, fontSize: 18, ), ), Text( user!.uniqueId ?? 'Employee ID', style: const TextStyle( color: Colors.white, fontSize: 20, ), ), ], ), ), ), // Navigation tile for Home ListTile( leading: const Icon(Icons.home), title: const Text('Home'), onTap: () { Navigator.pushAndRemoveUntil( context, MaterialPageRoute(builder: (context) => const HomeScreen()), (route) => false, // Remove all previous routes ); }, ), // Navigation tile for Profile ListTile( leading: const Icon(Icons.account_circle), title: const Text('Profile'), onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) => ProfileScreen()), ); }, ), // Navigation tile for Change Password ListTile( leading: const Icon(Icons.settings), title: const Text('Change Password'), onTap: () { Navigator.push( context, MaterialPageRoute(builder: (context) => ChangePasswordScreen()), ); }, ), // Navigation tile for Logout ListTile( leading: const Icon(Icons.exit_to_app), title: const Text('Logout'), onTap: () { logoutBox(context); }, ), ], ), ); } } // Function to display logout confirmation dialog Future logoutBox(BuildContext context) { Size size = MediaQuery.of(context).size; return showDialog( context: context, builder: (BuildContext context) { return AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(6.0), ), backgroundColor: Colors.white, alignment: Alignment.center, title: const Text('Are you sure you want to log out?'), titleTextStyle: const TextStyle( fontSize: 20, fontWeight: FontWeight.w400, color: Colors.black), actionsAlignment: MainAxisAlignment.center, actionsPadding: const EdgeInsets.only(left: 10, right: 10, bottom: 20), actions: [ Row( children: [ Expanded( child: SizedBox( height: (size.height / 50.52) * 2, child: ElevatedButton( style: ButtonStyle( elevation: MaterialStateProperty.all(0), backgroundColor: MaterialStateProperty.all( Colors.black), shape: MaterialStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(6.0), )), ), onPressed: () async { Navigator.pop(context); }, child: const Text( "No", style: TextStyle( fontSize: 17, color: Colors.white, fontWeight: FontWeight.w500), ), ), ), ), const SizedBox(width: 5), Expanded( child: SizedBox( height: (size.height / 50.52) * 2, child: ElevatedButton( style: ButtonStyle( elevation: MaterialStateProperty.all(0), backgroundColor: MaterialStateProperty.all(Colors.white), shape: MaterialStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(6.0), side: const BorderSide( color: Colors.purple, width: 1))), ), onPressed: () async { Navigator.pushAndRemoveUntil( context, MaterialPageRoute( builder: (context) => LoginScreen()), (route) => false, ); }, child: const Text( "Yes", style: TextStyle( fontSize: 17, color: Colors.purple, fontWeight: FontWeight.w500), ), ), ), ), ], ) ], ); }, ); }