[Drawer] 2. get company usr & fix css

This commit is contained in:
Stephen
2024-01-17 12:08:53 +07:00
parent e7685e8576
commit b3c9ac534d

View File

@@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
@@ -12,9 +13,12 @@ import '../provider/current_user_provider.dart';
import '../screen/login/logout_provider.dart'; import '../screen/login/logout_provider.dart';
class CustomDrawer extends HookConsumerWidget { class CustomDrawer extends HookConsumerWidget {
// final String userCompany;
const CustomDrawer({ const CustomDrawer({
super.key, Key? key,
}); // required this.userCompany,
}) : super(key: key);
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
@@ -22,6 +26,26 @@ class CustomDrawer extends HookConsumerWidget {
final isLoading = useState(false); final isLoading = useState(false);
final errorMessage = useState(""); final errorMessage = useState("");
final successMessage = useState(""); final successMessage = useState("");
final M_CompanyName = useState("-");
Future<String> getCompanyName() async {
final shared = await SharedPreferences.getInstance();
String M_CompanyName = "-";
if (shared != null) {
final bearerString = shared.get(Constant.bearerName).toString();
final xmodel = jsonDecode(bearerString);
if (xmodel != null) {
M_CompanyName = xmodel["model"]["M_CompanyName"];
}
}
if (M_CompanyName == "0") {
// throw BaseRepositoryException(message: 'Invalid Company ID');
}
return M_CompanyName;
}
useEffect(() { useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
@@ -34,6 +58,7 @@ class CustomDrawer extends HookConsumerWidget {
// Navigator.popAndPushNamed(context, loginRoute); // Navigator.popAndPushNamed(context, loginRoute);
return; return;
} }
M_CompanyName.value = await getCompanyName();
}); });
return () {}; return () {};
}, []); }, []);
@@ -69,175 +94,229 @@ class CustomDrawer extends HookConsumerWidget {
final currentMenu = ref.read(currentPageProvider); final currentMenu = ref.read(currentPageProvider);
return Drawer( return Drawer(
child: ListView( elevation: 0,
// padding: EdgeInsets.only( shape: RoundedRectangleBorder(
// top: Constant.getActualYPhone(context: context, y: 10), borderRadius: BorderRadius.all(Radius.circular(0))
// ), ),
children: [
DrawerHeader( child: Container(
// decoration: BoxDecoration( child: ListView(
// color: Colors.blue, // padding: EdgeInsets.only(
// ), // top: Constant.getActualYPhone(context: context, y: 10),
child: // ),
Image(image: AssetImage('images/logo_sismedika_landscape.png')), children: [
), Container(
ListTile(
leading: Icon( // decoration: BoxDecoration(
Icons.home, // border: Border(bottom: BorderSide(color: Colors.transparent)) // <--- use the global theme to change the dividerColor property
color: (currentMenu == 0) // ),
? Constant.pcBtnBackgroundColor child:
: Constant.textGreyv2, Image(image: AssetImage('images/logo_sismedika_landscape.png')),
), ),
title: Text(
'Home', SizedBox(
style: TextStyle( height: Constant.getActualYPhone(context: context, y: 8),
),
Padding(
padding: EdgeInsets.only(
top: Constant.getActualYPhone(context: context, y: 10),
bottom: Constant.getActualYPhone(context: context, y: 10),
right: Constant.getActualXPhone(context: context, x: 24),
left: Constant.getActualXPhone(context: context, x: 24),
),
child: Container(
width: Constant.getActualXPhone(context: context, x: 300),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: Constant.getActualXPhone(context: context, x: 24),
right: Constant.getActualXPhone(context: context, x: 71),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Constant.textGrey.withOpacity(0.16),
),
child: Padding(
padding: EdgeInsets.only(
left: Constant.getActualXPhone(context: context, x: 8),
right: Constant.getActualXPhone(context: context, x: 8),
),
child: Text(
M_CompanyName.value,
style: Constant.body3(context: context).copyWith(
fontWeight: FontWeight.w700,
color: Constant.textGreyv2,
backgroundColor: Constant.textGrey.withOpacity(0.16),
),
),
),
),
),
),
ListTile(
leading: Icon(
Icons.home,
color: (currentMenu == 0) color: (currentMenu == 0)
? Constant.pcBtnBackgroundColor ? Constant.pcBtnBackgroundColor
: Constant.textGreyv2, : Constant.textGreyv2,
), ),
title: Text(
'Home',
style: TextStyle(
color: (currentMenu == 0)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
),
// tileColor: (currentMenu == 0)
// ? Constant.pcBtnBackgroundColor
// : Colors.transparent,
onTap: () {
// Handle navigation to Home screen
Navigator.pop(context);
ref.read(currentPageProvider.state).update((state) => 0);
Navigator.pushNamed(context, homeRoute);
},
), ),
// tileColor: (currentMenu == 0) ListTile(
// ? Constant.pcBtnBackgroundColor leading: Icon(
// : Colors.transparent, Icons.money,
onTap: () {
// Handle navigation to Home screen
Navigator.pop(context);
ref.read(currentPageProvider.state).update((state) => 0);
Navigator.pushNamed(context, homeRoute);
},
),
ListTile(
leading: Icon(
Icons.money,
color: (currentMenu == 1)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
title: Text(
'Transaksi',
style: TextStyle(
color: (currentMenu == 1) color: (currentMenu == 1)
? Constant.pcBtnBackgroundColor ? Constant.pcBtnBackgroundColor
: Constant.textGreyv2, : Constant.textGreyv2,
), ),
title: Text(
'Transaksi',
style: TextStyle(
color: (currentMenu == 1)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
),
// tileColor: (currentMenu == 1)
// ? Constant.pcBtnBackgroundColor
// : Colors.transparent,
onTap: () {
// Handle navigation to Transaksi screen
Navigator.pop(context);
ref.read(currentPageProvider.state).update((state) => 1);
Navigator.pushNamed(context, transaksiRoute);
},
), ),
// tileColor: (currentMenu == 1) ListTile(
// ? Constant.pcBtnBackgroundColor leading: Icon(
// : Colors.transparent, Icons.history,
onTap: () {
// Handle navigation to Transaksi screen
Navigator.pop(context);
ref.read(currentPageProvider.state).update((state) => 1);
Navigator.pushNamed(context, transaksiRoute);
},
),
ListTile(
leading: Icon(
Icons.history,
color: (currentMenu == 2)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
title: Text(
'History Transaksi',
style: TextStyle(
color: (currentMenu == 2) color: (currentMenu == 2)
? Constant.pcBtnBackgroundColor ? Constant.pcBtnBackgroundColor
: Constant.textGreyv2, : Constant.textGreyv2,
), ),
title: Text(
'History Transaksi',
style: TextStyle(
color: (currentMenu == 2)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
),
// tileColor: (currentMenu == 2)
// ? Constant.pcBtnBackgroundColor
// : Colors.transparent,
onTap: () {
// Handle navigation to User screen
Navigator.pop(context);
ref.read(currentPageProvider.state).update((state) => 2);
Navigator.pushNamed(context, historyTransaksiRoute);
},
), ),
// tileColor: (currentMenu == 2) ListTile(
// ? Constant.pcBtnBackgroundColor leading: Icon(
// : Colors.transparent, Icons.feed,
onTap: () {
// Handle navigation to User screen
Navigator.pop(context);
ref.read(currentPageProvider.state).update((state) => 2);
Navigator.pushNamed(context, historyTransaksiRoute);
},
),
ListTile(
leading: Icon(
Icons.feed,
color: (currentMenu == 3)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
title: Text(
'Report',
style: TextStyle(
color: (currentMenu == 3) color: (currentMenu == 3)
? Constant.pcBtnBackgroundColor ? Constant.pcBtnBackgroundColor
: Constant.textGreyv2, : Constant.textGreyv2,
), ),
title: Text(
'Report',
style: TextStyle(
color: (currentMenu == 3)
? Constant.pcBtnBackgroundColor
: Constant.textGreyv2,
),
),
// tileColor: (currentMenu == 3)
// ? Constant.pcBtnBackgroundColor
// : Colors.transparent,
onTap: () {
// Handle navigation to Transaksi screen
Navigator.pop(context);
ref.read(currentPageProvider.state).update((state) => 3);
Navigator.pushNamed(context, reportRoute);
},
), ),
// tileColor: (currentMenu == 3) // ListTile(
// ? Constant.pcBtnBackgroundColor // title: Text(
// : Colors.transparent, // 'User',
onTap: () { // style: TextStyle(
// Handle navigation to Transaksi screen // color: (currentMenu == 4)
Navigator.pop(context); // ? Constant.textWhite
ref.read(currentPageProvider.state).update((state) => 3); // : Constant.textBlack,
Navigator.pushNamed(context, reportRoute); // ),
}, // ),
), // tileColor: (currentMenu == 4)
// ListTile( // ? Constant.pcBtnBackgroundColor
// title: Text( // : Colors.transparent,
// 'User', // onTap: () {
// style: TextStyle( // // Handle navigation to User screen
// color: (currentMenu == 4) // Navigator.pop(context);
// ? Constant.textWhite // ref.read(currentPageProvider.state).update((state) => 4);
// : Constant.textBlack, // Navigator.pushNamed(context, userRoute);
// ), // },
// ), // ),
// tileColor: (currentMenu == 4) // ListTile(
// ? Constant.pcBtnBackgroundColor // title: Text(
// : Colors.transparent, // 'Change Company',
// onTap: () { // style: TextStyle(
// // Handle navigation to User screen // color: (currentMenu == 5)
// Navigator.pop(context); // ? Constant.textWhite
// ref.read(currentPageProvider.state).update((state) => 4); // : Constant.textBlack,
// Navigator.pushNamed(context, userRoute); // ),
// }, // ),
// ), // tileColor: (currentMenu == 5)
// ListTile( // ? Constant.pcBtnBackgroundColor
// title: Text( // : Colors.transparent,
// 'Change Company', // onTap: () {
// style: TextStyle( // // Handle navigation to User screen
// color: (currentMenu == 5) // Navigator.pop(context);
// ? Constant.textWhite // ref.read(currentPageProvider.state).update((state) => 5);
// : Constant.textBlack, // Navigator.pushNamed(context, changeCompanyRoute);
// ), // },
// ), // ),
// tileColor: (currentMenu == 5) ListTile(
// ? Constant.pcBtnBackgroundColor leading: Icon(
// : Colors.transparent, Icons.logout,
// onTap: () { color: Constant.textGreyv2,
// // Handle navigation to User screen ),
// Navigator.pop(context); title: Text(
// ref.read(currentPageProvider.state).update((state) => 5); 'Logout',
// Navigator.pushNamed(context, changeCompanyRoute); style: TextStyle(color: Constant.textGreyv2),
// }, ),
// ), onTap: () {
ListTile( // di set ke 0 lagi
leading: Icon( ref.read(currentPageProvider.state).update((state) => 0);
Icons.logout, ref.read(logoutProvider.notifier).logout(
color: Constant.textGreyv2, M_UserID: selectedUser?.model.M_UserID ?? "",
M_UserUsername: selectedUser?.model.M_UserUsername ?? "",
);
},
), ),
title: Text( ],
'Logout', ),
style: TextStyle(color: Constant.textGreyv2),
),
onTap: () {
// di set ke 0 lagi
ref.read(currentPageProvider.state).update((state) => 0);
ref.read(logoutProvider.notifier).logout(
M_UserID: selectedUser?.model.M_UserID ?? "",
M_UserUsername: selectedUser?.model.M_UserUsername ?? "",
);
},
),
],
), ),
); );
} }