282 lines
9.0 KiB
Dart
282 lines
9.0 KiB
Dart
// import 'package:cheminova/provider/user_provider.dart';
|
|
// import 'package:cheminova/screens/change_password_screen.dart';
|
|
// import 'package:cheminova/screens/home_screen.dart';
|
|
// import 'package:cheminova/screens/login_screen.dart';
|
|
// import 'package:cheminova/screens/profile_screen.dart';
|
|
// import 'package:flutter/material.dart';
|
|
// import 'package:provider/provider.dart';
|
|
//
|
|
// class CommonDrawer extends StatelessWidget {
|
|
// const CommonDrawer({super.key});
|
|
//
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// return Drawer(
|
|
// child: ListView(
|
|
// padding: EdgeInsets.zero,
|
|
// children: <Widget>[
|
|
// SizedBox(
|
|
// height: 150,
|
|
// child: DrawerHeader(
|
|
// decoration: const BoxDecoration(
|
|
// color: Colors.black87,
|
|
// ),
|
|
// child: Consumer<UserProvider>(
|
|
// builder: (context, userProvider, child) {
|
|
// if (userProvider.isLoading) {
|
|
// return const Center(child: CircularProgressIndicator());
|
|
// } else if (userProvider.user != null) {
|
|
// return Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// mainAxisAlignment: MainAxisAlignment.start,
|
|
// children: [
|
|
// Text(
|
|
// userProvider.user!.name,
|
|
// style: const TextStyle(
|
|
// color: Colors.white,
|
|
// fontSize: 18,
|
|
// ),
|
|
// ),
|
|
// Text(
|
|
// userProvider.user!.uniqueId,
|
|
// style: const TextStyle(
|
|
// color: Colors.white,
|
|
// fontSize: 20,
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// );
|
|
// } else {
|
|
// return const Text(
|
|
// 'No User Data',
|
|
// style: TextStyle(
|
|
// color: Colors.white,
|
|
// fontSize: 18,
|
|
// ),
|
|
// );
|
|
// }
|
|
// },
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ListTile(
|
|
// leading: const Icon(Icons.home),
|
|
// title: const Text('Home'),
|
|
// onTap: () {
|
|
// Navigator.pushReplacement(
|
|
// context,
|
|
// MaterialPageRoute(builder: (context) => const HomePage()),
|
|
// );
|
|
// },
|
|
// ),
|
|
// ListTile(
|
|
// leading: const Icon(Icons.account_circle),
|
|
// title: const Text('Profile'),
|
|
// onTap: () {
|
|
// Navigator.push(
|
|
// context,
|
|
// MaterialPageRoute(
|
|
// builder: (context) {
|
|
// return const ProfileScreen();
|
|
// },
|
|
// ),
|
|
// );
|
|
// },
|
|
// ),
|
|
// ListTile(
|
|
// leading: const Icon(Icons.settings),
|
|
// title: const Text('Change Password'),
|
|
// onTap: () {
|
|
// Navigator.push(
|
|
// context,
|
|
// MaterialPageRoute(
|
|
// builder: (context) => const ChangePasswordPage()),
|
|
// );
|
|
// },
|
|
// ),
|
|
// ListTile(
|
|
// leading: const Icon(Icons.exit_to_app),
|
|
// title: const Text('Logout'),
|
|
// onTap: () {
|
|
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
// Provider.of<UserProvider>(context, listen: false)
|
|
// .clearUserProfile();
|
|
// });
|
|
// Navigator.pushReplacement(
|
|
// context,
|
|
// MaterialPageRoute(builder: (context) => const LoginPage()),
|
|
// );
|
|
// },
|
|
// ),
|
|
//
|
|
//
|
|
// 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),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
//
|
|
// ],
|
|
// ),
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
import 'package:cheminova/provider/user_provider.dart';
|
|
import 'package:cheminova/screens/change_password_screen.dart';
|
|
import 'package:cheminova/screens/home_screen.dart';
|
|
import 'package:cheminova/screens/login_screen.dart';
|
|
import 'package:cheminova/screens/profile_screen.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class CommonDrawer extends StatefulWidget {
|
|
const CommonDrawer({super.key});
|
|
|
|
@override
|
|
State<CommonDrawer> createState() => _CommonDrawerState();
|
|
}
|
|
|
|
class _CommonDrawerState extends State<CommonDrawer> {
|
|
|
|
|
|
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) {
|
|
return Drawer(
|
|
child: Column(
|
|
children: <Widget>[
|
|
SizedBox(
|
|
height: 150,
|
|
width:double.infinity,
|
|
child: DrawerHeader(
|
|
decoration: const BoxDecoration(
|
|
color: Colors.black87,
|
|
),
|
|
child: Consumer<UserProvider>(
|
|
builder: (context, userProvider, child) {
|
|
if (userProvider.isLoading) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else if (userProvider.user != null) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
userProvider.user!.name,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 18,
|
|
),
|
|
),
|
|
Text(
|
|
userProvider.user!.uniqueId,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
} else {
|
|
return const Text(
|
|
'No User Data',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 18,
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.home),
|
|
title: const Text('Home'),
|
|
onTap: () {
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => const HomePage()),
|
|
);
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.account_circle),
|
|
title: const Text('Profile'),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return const ProfileScreen();
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.settings),
|
|
title: const Text('Change Password'),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const ChangePasswordPage()),
|
|
);
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.exit_to_app),
|
|
title: const Text('Logout'),
|
|
onTap: () {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
Provider.of<UserProvider>(context, listen: false)
|
|
.clearUserProfile();
|
|
});
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => const LoginPage()),
|
|
);
|
|
},
|
|
),
|
|
const Spacer(), // Push the version text to the bottom
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 16.0),
|
|
child: Text(
|
|
'Version: $_appVersion',
|
|
style: TextStyle(color: Colors.grey[600], fontSize: 12),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|