432 lines
15 KiB
Dart
432 lines
15 KiB
Dart
// 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<MyDrawer> createState() => _MyDrawerState();
|
|
// }
|
|
//
|
|
// class _MyDrawerState extends State<MyDrawer> {
|
|
// 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: <Widget>[
|
|
// 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);
|
|
// },
|
|
// ),
|
|
//
|
|
//
|
|
//
|
|
//
|
|
// SizedBox(
|
|
// height: 700,
|
|
// child: Padding(
|
|
// padding: const EdgeInsets.all(8.0),
|
|
// child: Center(
|
|
// child: Text(
|
|
// 'Version 2.0.0',
|
|
// style: TextStyle(color: Colors.grey[600], fontSize: 12),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// }
|
|
// }
|
|
// // 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<Color>(
|
|
// Colors.black),
|
|
// shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
// 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<Color>(Colors.white),
|
|
// shape:
|
|
// MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
// 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),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// )
|
|
// ],
|
|
// );
|
|
// },
|
|
// );
|
|
// }
|
|
|
|
|
|
|
|
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';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
|
|
class MyDrawer extends StatefulWidget {
|
|
final UserModel? userModel;
|
|
|
|
MyDrawer({super.key, this.userModel});
|
|
|
|
@override
|
|
State<MyDrawer> createState() => _MyDrawerState();
|
|
}
|
|
|
|
class _MyDrawerState extends State<MyDrawer> {
|
|
final homecontroller = Get.put(HomeController()); // Initialize HomeController
|
|
String _appVersion = '';
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_getAppVersion();
|
|
}
|
|
|
|
Future<void> _getAppVersion() async {
|
|
PackageInfo packageInfo = await PackageInfo.fromPlatform(
|
|
|
|
);
|
|
setState(() {
|
|
_appVersion = packageInfo.version; // 1.0.0
|
|
});
|
|
}
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final user = homecontroller.user; // Get the current user from HomeController
|
|
return Drawer(
|
|
child: Column(
|
|
children: <Widget>[
|
|
SizedBox(
|
|
height: 150,
|
|
width: double.infinity,
|
|
// Drawer header displaying user information
|
|
child: DrawerHeader(
|
|
//padding: EdgeInsets.zero,
|
|
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);
|
|
},
|
|
),
|
|
// Spacer to push the version text to the bottom
|
|
const Spacer(),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Center(
|
|
child: Text(
|
|
'Version: $_appVersion',
|
|
style: TextStyle(color: Colors.grey[600], fontSize: 12),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// 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<Color>(
|
|
Colors.black),
|
|
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
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<Color>(Colors.white),
|
|
shape:
|
|
MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
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),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|