diff --git a/app_petty_cash/lib/repository/transaksi_repository.dart b/app_petty_cash/lib/repository/transaksi_repository.dart index 2a35fe5..fbba02d 100644 --- a/app_petty_cash/lib/repository/transaksi_repository.dart +++ b/app_petty_cash/lib/repository/transaksi_repository.dart @@ -186,4 +186,33 @@ class TransaksiRepository extends BaseRepository { return resp['status']; } + + // confirm transaksi + Future confirmTransaksi( + String id, + String userid, + ) async { + final service = + "${Constant.baseUrlDevone}transaction/confirmtransaction/?id=$id&userid=$userid"; + final resp = await get( + // param: { + // "": "", + // }, + service: service, + ); + + print("url confirm transaksi : $service"); + + // final result = List.empty(growable: true); + // resp['data'].forEach((e) { + // final model = ListCategory.fromJson(e); + // result.add(model); + // }); + + if (resp['status'] != "OK") { + return resp['message']; + } + + return resp['status']; + } } diff --git a/app_petty_cash/lib/screen/report/report_screen.dart b/app_petty_cash/lib/screen/report/report_screen.dart index 963540b..227b2df 100644 --- a/app_petty_cash/lib/screen/report/report_screen.dart +++ b/app_petty_cash/lib/screen/report/report_screen.dart @@ -82,226 +82,207 @@ class ReportScreen extends HookConsumerWidget { ), drawer: CustomDrawer(), body: SafeArea( - child: SingleChildScrollView( - child: Padding( - padding: EdgeInsets.all(20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Tanggal Awal', - style: Constant.body1(context: context).copyWith( - fontWeight: FontWeight.w600, color: Constant.textBlack), - ), - SizedBox( - height: Constant.getActualYPhone(context: context, y: 10), - ), - // Tanggal Awal - Row( - children: [ - Expanded( - child: TextField( - controller: ctrlTglAwal, - decoration: InputDecoration( - hintStyle: - Constant.body2_400(context: context).copyWith( - color: Colors.orange, - ), - labelStyle: - Constant.body2_400(context: context).copyWith( - color: Colors.orange, - ), - border: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.orange, - width: 1, - ), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.orange, - width: 1, - ), - ), - // labelText: "Tanggal Awal", - hintText: 'Tanggal Awal', - // suffixIcon: isLoadingFilterScope.value - // ? SizedBox( - // width: Constant.getActualXPhone( - // context: context, - // x: 4, - // ), - // height: Constant.getActualYPhone( - // context: context, - // y: 4, - // ), - // child: CircularProgressIndicator( - // color: Constant.textRed, - // ), - // ) - // : Icon( - // Icons.calendar_month_sharp, - // color: Constant.colorIconDate, - // ), + child: Padding( + padding: EdgeInsets.all(20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Tanggal Awal', + style: Constant.body1(context: context).copyWith( + fontWeight: FontWeight.w600, color: Constant.textBlack), + ), + SizedBox( + height: Constant.getActualYPhone(context: context, y: 10), + ), + // Tanggal Awal + Row( + children: [ + Expanded( + child: TextField( + controller: ctrlTglAwal, + decoration: InputDecoration( + hintStyle: + Constant.body2_400(context: context).copyWith( + color: Colors.orange, ), - onTap: () async { - final selectedDateAwal = await showDatePicker( - // locale: const Locale("en-CA"), - // locale: , - context: context, - initialEntryMode: - DatePickerEntryMode.calendarOnly, - firstDate: DateTime(2000), - lastDate: DateTime(2100), - - initialDate: (ctrlTglAwal.text.isEmpty) - ? DateTime.now() - : tglAwal.value, - ); - - if (selectedDateAwal != null) { - String formattedDate = DateFormat('dd-MM-yyyy') - .format(selectedDateAwal); - // ctrlTglAwal.text = - // selectedDateAwal.toString().split(' ')[0]; - ctrlTglAwal.text = formattedDate; - tglAwal.value = selectedDateAwal; - tglAwalTmp.value = selectedDateAwal.toString(); - } - - if (selectedDateAwal == null) { - print('cancel button'); - return; - } - }, - ), - ), - ], - ), - - SizedBox( - height: Constant.getActualYPhone(context: context, y: 20), - ), - - Text( - 'Tanggal Akhir', - style: Constant.body1(context: context).copyWith( - fontWeight: FontWeight.w600, color: Constant.textBlack), - ), - SizedBox( - height: Constant.getActualYPhone(context: context, y: 10), - ), - // Tanggal Akhir - Row( - children: [ - Expanded( - child: TextField( - controller: ctrlTglAkhir, - decoration: InputDecoration( - hintStyle: - Constant.body2_400(context: context).copyWith( - color: Colors.orange, - ), - labelStyle: - Constant.body2_400(context: context).copyWith( - color: Colors.orange, - ), - border: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.orange, - width: 1, - ), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.orange, - width: 1, - ), - ), - // labelText: "Tanggal Awal", - hintText: 'Tanggal Akhir', - // suffixIcon: isLoadingFilterScope.value - // ? SizedBox( - // width: Constant.getActualXPhone( - // context: context, - // x: 4, - // ), - // height: Constant.getActualYPhone( - // context: context, - // y: 4, - // ), - // child: CircularProgressIndicator( - // color: Constant.textRed, - // ), - // ) - // : Icon( - // Icons.calendar_month_sharp, - // color: Constant.colorIconDate, - // ), + labelStyle: + Constant.body2_400(context: context).copyWith( + color: Colors.orange, ), - onTap: () async { - final selectedDateAkhir = await showDatePicker( - // locale: const Locale("en-CA"), - // locale: , - context: context, - initialEntryMode: - DatePickerEntryMode.calendarOnly, - firstDate: DateTime(2000), - lastDate: DateTime(2100), - - initialDate: (ctrlTglAkhir.text.isEmpty) - ? DateTime.now() - : tglAkhir.value, - ); - - if (selectedDateAkhir != null) { - String formattedDate = DateFormat('dd-MM-yyyy') - .format(selectedDateAkhir); - // ctrlTglAkhir.text = - // selectedDateAkhir.toString().split(' ')[0]; - ctrlTglAkhir.text = formattedDate; - tglAkhir.value = selectedDateAkhir; - tglAkhirTmp.value = selectedDateAkhir.toString(); - } - - if (selectedDateAkhir == null) { - print('cancel button'); - return; - } - }, + border: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.orange, + width: 1, + ), + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.orange, + width: 1, + ), + ), + // labelText: "Tanggal Awal", + hintText: 'Tanggal Awal', + // suffixIcon: isLoadingFilterScope.value + // ? SizedBox( + // width: Constant.getActualXPhone( + // context: context, + // x: 4, + // ), + // height: Constant.getActualYPhone( + // context: context, + // y: 4, + // ), + // child: CircularProgressIndicator( + // color: Constant.textRed, + // ), + // ) + // : Icon( + // Icons.calendar_month_sharp, + // color: Constant.colorIconDate, + // ), ), + onTap: () async { + final selectedDateAwal = await showDatePicker( + // locale: const Locale("en-CA"), + // locale: , + context: context, + initialEntryMode: DatePickerEntryMode.calendarOnly, + firstDate: DateTime(2000), + lastDate: DateTime(2100), + + initialDate: (ctrlTglAwal.text.isEmpty) + ? DateTime.now() + : tglAwal.value, + ); + + if (selectedDateAwal != null) { + String formattedDate = DateFormat('dd-MM-yyyy') + .format(selectedDateAwal); + // ctrlTglAwal.text = + // selectedDateAwal.toString().split(' ')[0]; + ctrlTglAwal.text = formattedDate; + tglAwal.value = selectedDateAwal; + tglAwalTmp.value = selectedDateAwal.toString(); + } + + if (selectedDateAwal == null) { + print('cancel button'); + return; + } + }, ), - ], - ), - ], - ), - ), - ), - ), - bottomNavigationBar: BottomAppBar( - height: 150, - child: Container( - child: Padding( - padding: EdgeInsets.only( - // right: Constant.getActualXPhone(context: context, x: 27), - // left: Constant.getActualXPhone(context: context, x: 27), - // bottom: Constant.getActualYPhone(context: context, y: 32), - // top: Constant.getActualYPhone(context: context, y: 24), - ), - child: Column( - children: [ - // Excel - Container( - width: Constant.getActualXPhone(context: context, x: 336), - height: Constant.getActualYPhone(context: context, y: 42), - child: ElevatedButton( + ), + ], + ), + + SizedBox( + height: Constant.getActualYPhone(context: context, y: 20), + ), + + Text( + 'Tanggal Akhir', + style: Constant.body1(context: context).copyWith( + fontWeight: FontWeight.w600, color: Constant.textBlack), + ), + SizedBox( + height: Constant.getActualYPhone(context: context, y: 10), + ), + // Tanggal Akhir + Row( + children: [ + Expanded( + child: TextField( + controller: ctrlTglAkhir, + decoration: InputDecoration( + hintStyle: + Constant.body2_400(context: context).copyWith( + color: Colors.orange, + ), + labelStyle: + Constant.body2_400(context: context).copyWith( + color: Colors.orange, + ), + border: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.orange, + width: 1, + ), + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.orange, + width: 1, + ), + ), + // labelText: "Tanggal Awal", + hintText: 'Tanggal Akhir', + // suffixIcon: isLoadingFilterScope.value + // ? SizedBox( + // width: Constant.getActualXPhone( + // context: context, + // x: 4, + // ), + // height: Constant.getActualYPhone( + // context: context, + // y: 4, + // ), + // child: CircularProgressIndicator( + // color: Constant.textRed, + // ), + // ) + // : Icon( + // Icons.calendar_month_sharp, + // color: Constant.colorIconDate, + // ), + ), + onTap: () async { + final selectedDateAkhir = await showDatePicker( + // locale: const Locale("en-CA"), + // locale: , + context: context, + initialEntryMode: DatePickerEntryMode.calendarOnly, + firstDate: DateTime(2000), + lastDate: DateTime(2100), + + initialDate: (ctrlTglAkhir.text.isEmpty) + ? DateTime.now() + : tglAkhir.value, + ); + + if (selectedDateAkhir != null) { + String formattedDate = DateFormat('dd-MM-yyyy') + .format(selectedDateAkhir); + // ctrlTglAkhir.text = + // selectedDateAkhir.toString().split(' ')[0]; + ctrlTglAkhir.text = formattedDate; + tglAkhir.value = selectedDateAkhir; + tglAkhirTmp.value = selectedDateAkhir.toString(); + } + + if (selectedDateAkhir == null) { + print('cancel button'); + return; + } + }, + ), + ), + ], + ), + + Spacer(), + + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ElevatedButton( style: ButtonStyle( backgroundColor: MaterialStateColor.resolveWith( (states) => Colors.white), // side: MaterialStateBorderSide.resolveWith( // (states) => BorderSide(color: Colors.green), // ), - // backgroundColor: MaterialStateColor.resolveWith( // (st) => Constant.pcBtnBackgroundColor), shape: @@ -333,11 +314,11 @@ class ReportScreen extends HookConsumerWidget { ), ), SizedBox( - height: Constant.getActualXPhone( - context: context, x: 8), + width: Constant.getActualXPhone( + context: context, x: 10), ), Text( - 'Download Report (xls) ', + 'Excel', style: Constant.body1(context: context).copyWith( fontWeight: FontWeight.w600, color: Colors.green, @@ -345,19 +326,41 @@ class ReportScreen extends HookConsumerWidget { ), ], ), - onPressed: () {}, + onPressed: () async { + M_CompanyID = await getCompanyID(); + if(M_CompanyID == "0"){ + SanckbarWidget(context, 'Invalid Company', snackbarType.error); + return; + } + // Awal + DateTime parsedDateAwal = + DateFormat('dd-MM-yyyy').parse( + ctrlTglAwal.value.text.toString(), + ); + String formattedDateAwal = + DateFormat('yyyy-MM-dd').format(parsedDateAwal); + + // Akhir + DateTime parsedDateAkhir = + DateFormat('dd-MM-yyyy').parse( + ctrlTglAwal.value.text.toString(), + ); + String formattedDateAkhir = + DateFormat('yyyy-MM-dd').format(parsedDateAkhir); + + String url = + "https://${Constant.baseUrlDevoneReport}/birt/run?__report=report/one/pettycash/rpt_r_pt_001.rptdesign&__format=xls&PStartDate=$formattedDateAwal&PEndDate=$formattedDateAkhir&PCompanyID=$M_CompanyID&username=adminsas%20"; + if (!await launchUrl(Uri.parse(url))) { + // throw Exception('Could not launch $url'); + SanckbarWidget(context, 'Could not launch $url', + snackbarType.error); + } + // https://devone.aplikasi.web.id/birt/run?__report=report/one/pettycash/rpt_r_pt_001.rptdesign&__format=pdf&PStartDate=2023-11-01&PEndDate=2023-12-30&PCompanyID=0&username=adminsas%20&tm=1701327096267 + }, ), - ), - SizedBox( - height: Constant.getActualYPhone(context: context, y: 20), - ), - - // PDF - Container( - width: Constant.getActualXPhone(context: context, x: 336), - height: Constant.getActualYPhone(context: context, y: 42), - child: ElevatedButton( + // PDF + ElevatedButton( style: ButtonStyle( backgroundColor: MaterialStateColor.resolveWith( (st) => Constant.pcBtnBackgroundColor), @@ -390,11 +393,11 @@ class ReportScreen extends HookConsumerWidget { ), ), SizedBox( - height: Constant.getActualXPhone( + width: Constant.getActualXPhone( context: context, x: 8), ), Text( - 'Download Report (PDF)', + 'PDF', style: Constant.body1(context: context).copyWith( fontWeight: FontWeight.w600, color: Constant.white), @@ -402,7 +405,29 @@ class ReportScreen extends HookConsumerWidget { ], ), onPressed: () async { - String url = "https://pub.dev/packages?q=url+launcher"; + M_CompanyID = await getCompanyID(); + if(M_CompanyID == "0"){ + SanckbarWidget(context, 'Invalid Company', snackbarType.error); + return; + } + // Awal + DateTime parsedDateAwal = + DateFormat('dd-MM-yyyy').parse( + ctrlTglAwal.value.text.toString(), + ); + String formattedDateAwal = + DateFormat('yyyy-MM-dd').format(parsedDateAwal); + + // Akhir + DateTime parsedDateAkhir = + DateFormat('dd-MM-yyyy').parse( + ctrlTglAwal.value.text.toString(), + ); + String formattedDateAkhir = + DateFormat('yyyy-MM-dd').format(parsedDateAkhir); + + String url = + "https://${Constant.baseUrlDevoneReport}/birt/run?__report=report/one/pettycash/rpt_r_pt_001.rptdesign&__format=pdf&PStartDate=$formattedDateAwal&PEndDate=$formattedDateAkhir&PCompanyID=$M_CompanyID&username=adminsas%20"; if (!await launchUrl(Uri.parse(url))) { // throw Exception('Could not launch $url'); SanckbarWidget(context, 'Could not launch $url', @@ -410,9 +435,9 @@ class ReportScreen extends HookConsumerWidget { } }, ), - ), - ], - ), + ], + ), + ], ), ), ), diff --git a/app_petty_cash/lib/screen/transaksi/confirm_transaksi_provider.dart b/app_petty_cash/lib/screen/transaksi/confirm_transaksi_provider.dart new file mode 100644 index 0000000..2197b6b --- /dev/null +++ b/app_petty_cash/lib/screen/transaksi/confirm_transaksi_provider.dart @@ -0,0 +1,84 @@ +import 'package:equatable/equatable.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../../repository/transaksi_repository.dart'; +import '../../provider/dio_provider.dart'; +import '../../repository/base_repository.dart'; +import 'search_history_transaksi_provider.dart'; + +abstract class ConfirmTransaksiState extends Equatable { + final DateTime date; + const ConfirmTransaksiState(this.date); + @override + List get props => [date]; +} + +class ConfirmTransaksiStateInit extends ConfirmTransaksiState { + ConfirmTransaksiStateInit() : super(DateTime.now()); +} + +class ConfirmTransaksiStateLoading extends ConfirmTransaksiState { + ConfirmTransaksiStateLoading() : super(DateTime.now()); +} + +class ConfirmTransaksiStateError extends ConfirmTransaksiState { + final String message; + ConfirmTransaksiStateError({ + required this.message, + }) : super(DateTime.now()); +} + +class ConfirmTransaksiStateDone extends ConfirmTransaksiState { + // final List model; + final String resp; + ConfirmTransaksiStateDone({ + required this.resp, + }) : super(DateTime.now()); +} + +//notifier +class ConfirmTransaksiNotifier extends StateNotifier { + final Ref ref; + ConfirmTransaksiNotifier({ + required this.ref, + }) : super(ConfirmTransaksiStateInit()); + + void confirmTransaksi( + String id, + String userid, + String companyid, + String tglAwal, + String tglAkhir, + String categoryid, + ) async { + try { + state = ConfirmTransaksiStateLoading(); + final dio = ref.read(dioProvider); + final resp = await TransaksiRepository(dio: dio).confirmTransaksi( + id, + userid, + ); + state = ConfirmTransaksiStateDone(resp: resp); + + // search lagi buat get data + ref.read(searchHistoryTransaksiProvider.notifier).searchHistoryTransaksi( + companyid, + tglAwal, + tglAkhir, + categoryid, + ); + } catch (e) { + if (e is BaseRepositoryException) { + state = ConfirmTransaksiStateError(message: e.message.toString()); + } else { + state = ConfirmTransaksiStateError(message: e.toString()); + } + } + } +} + +//provider +final confirmTransaksiProvider = + StateNotifierProvider( + (ref) => ConfirmTransaksiNotifier(ref: ref), +); diff --git a/app_petty_cash/lib/screen/transaksi/history_transaksi_screen.dart b/app_petty_cash/lib/screen/transaksi/history_transaksi_screen.dart index 328181a..a5b51fb 100644 --- a/app_petty_cash/lib/screen/transaksi/history_transaksi_screen.dart +++ b/app_petty_cash/lib/screen/transaksi/history_transaksi_screen.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:app_petty_cash/screen/transaksi/confirm_transaksi_provider.dart'; import 'package:app_petty_cash/screen/transaksi/delete_transaksi_provider.dart'; import 'package:app_petty_cash/screen/transaksi/search_history_transaksi_provider.dart'; import 'package:dropdown_button2/dropdown_button2.dart'; @@ -9,6 +10,7 @@ import 'package:flutter_svg/svg.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:url_launcher/url_launcher.dart'; import '../../app/constant.dart'; import '../../app/route.dart'; @@ -161,6 +163,27 @@ class HistoryTransaksiScreen extends HookConsumerWidget { }, ); + // confirm transaksi + ref.listen( + confirmTransaksiProvider, + (previous, next) { + if (next is ConfirmTransaksiStateLoading) { + searchHistoryIsLoading.value = true; + } else if (next is ConfirmTransaksiStateError) { + // print(next.message); + searchHistoryIsLoading.value = false; + SanckbarWidget(context, next.message, snackbarType.error); + } else if (next is ConfirmTransaksiStateDone) { + // print(jsonEncode(next.model)); + // print(next.model.length); + // listSearchHistory.value = next.model; + SanckbarWidget( + context, 'Data Berhasil Diconfirm', snackbarType.success); + searchHistoryIsLoading.value = false; + } + }, + ); + Future getCompanyID() async { final shared = await SharedPreferences.getInstance(); String M_CompanyID = "0"; @@ -306,6 +329,131 @@ class HistoryTransaksiScreen extends HookConsumerWidget { ); } + // confirm dialog + Future showConfirmDialog( + BuildContext context, + String id, + String userid, + String companyid, + String tglAwal, + String tglAkhir, + String categoryid, + ) async { + return showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text('Konfirmasi Proses Confirm'), + content: Text('Apakah anda yakin mengconfirm data ini?'), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); // Tutup dialog + }, + child: Text('Batal'), + ), + ElevatedButton( + onPressed: () { + print('confirm id $id , userid $userid'); + DateTime parsedDate = DateFormat('dd-MM-yyyy').parse( + ctrlTglAwal.value.text.toString(), + ); + String formattedDateAwal = + DateFormat('yyyy-MM-dd').format(parsedDate); + + DateTime parsedDateAkhir = DateFormat('dd-MM-yyyy').parse( + ctrlTglAkhir.value.text.toString(), + ); + String formattedDateAkhir = + DateFormat('yyyy-MM-dd').format(parsedDateAkhir); + ref.read(confirmTransaksiProvider.notifier).confirmTransaksi( + id, + userid, + companyid, + formattedDateAwal, + formattedDateAkhir, + categoryid, + ); + Navigator.of(context).pop(); + }, + child: Text( + 'Confirm Data', + style: Constant.body1_600(context: context).copyWith( + fontWeight: FontWeight.w600, + color: Constant.textWhite, + ), + ), + style: ButtonStyle( + backgroundColor: MaterialStateColor.resolveWith( + (st) => Constant.textGreen), + shape: MaterialStateProperty.all( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide( + color: Constant.textGreen, + ), + ), + ), + shadowColor: MaterialStateProperty.all(Color(0xffff48423d)), + elevation: MaterialStateProperty.all(4.0), + ), + ), + ], + ); + }, + ); + } + + // dialog image + Future showImageDialog( + BuildContext context, + String url, + ) async { + return showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text('Attachment File'), + content: Column( + children: [ + Image.network( + Constant.baseUrlFile + url, + width: MediaQuery.of(context).size.width, + // height: MediaQuery.of(context).size.height * 0.5, + loadingBuilder: (BuildContext context, Widget child, + ImageChunkEvent? loadingProgress) { + if (loadingProgress == null) { + return child; + } else { + return Center( + child: SizedBox( + width: MediaQuery.of(context).size.width, + child: CircularProgressIndicator( + value: loadingProgress.expectedTotalBytes != null + ? loadingProgress.cumulativeBytesLoaded / + (loadingProgress.expectedTotalBytes ?? 1) + : null, + ), + ), + ); + } + }, + ), + ], + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); // Tutup dialog + }, + child: Text('Tutup'), + ), + ], + ); + }, + ); + } + void _closeKeyboard() { FocusManager.instance.primaryFocus?.unfocus(); } @@ -316,740 +464,924 @@ class HistoryTransaksiScreen extends HookConsumerWidget { final FocusNode focusNodetglAkhir = useFocusNode(); final tglAkhirHasFocus = useState(false); - return Padding( - padding: EdgeInsets.only( - top: Constant.getActualYPhone(context: context, y: 30), - ), - child: Scaffold( - appBar: AppBar( - title: Text( - 'History Transaksi', - style: TextStyle(color: Constant.textWhite), - ), - backgroundColor: Constant.pcBtnBackgroundColor, - iconTheme: IconThemeData( - color: Constant.textWhite, - ), + return GestureDetector( + onTap: () => FocusManager.instance.primaryFocus?.unfocus(), + child: Padding( + padding: EdgeInsets.only( + top: Constant.getActualYPhone(context: context, y: 30), ), - drawer: CustomDrawer(), - body: SafeArea( - child: Padding( - padding: EdgeInsets.only( - top: Constant.getActualYPhone(context: context, y: 15), - left: Constant.getActualXPhone(context: context, x: 10), - right: Constant.getActualXPhone(context: context, x: 10), - bottom: Constant.getActualYPhone(context: context, y: 10), + child: Scaffold( + appBar: AppBar( + title: Text( + 'History Transaksi', + style: TextStyle(color: Constant.textWhite), ), - child: Container( - // height: MediaQuery.of(context).size.height - 10, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // filter - Row( - children: [ - // Tanggal Awal - Expanded( - child: GestureDetector( - onTap: () { - focusNodetglAwal.unfocus(); - // _closeKeyboard(); - }, - child: TextField( - enableInteractiveSelection: false, - showCursor: (tglAwalHasFocus.value) ? true : false, - controller: ctrlTglAwal, - decoration: InputDecoration( - hintStyle: - Constant.body2_400(context: context).copyWith( - color: Constant.textGreyv2, - ), - labelStyle: - Constant.body2_400(context: context).copyWith( - color: Constant.textGreyv2, - ), - border: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.orange, - width: 1, - ), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Constant.textGreyv2, - width: 1, - ), - ), - labelText: "Tanggal Awal", - hintText: 'Tanggal Awal', - // suffixIcon: isLoadingFilterScope.value - // ? SizedBox( - // width: Constant.getActualXPhone( - // context: context, - // x: 4, - // ), - // height: Constant.getActualYPhone( - // context: context, - // y: 4, - // ), - // child: CircularProgressIndicator( - // color: Constant.textRed, - // ), - // ) - // : Icon( - // Icons.calendar_month_sharp, - // color: Constant.colorIconDate, - // ), - ), - onTap: () async { - final selectedDateAwal = await showDatePicker( - // locale: const Locale("en-CA"), - // locale: , - context: context, - initialEntryMode: - DatePickerEntryMode.calendarOnly, - firstDate: DateTime(2000), - lastDate: DateTime(2100), - - initialDate: (ctrlTglAwal.text.isEmpty) - ? DateTime.now() - : tglAwal.value, - ); - - if (selectedDateAwal != null) { - String formattedDate = DateFormat('dd-MM-yyyy') - .format(selectedDateAwal); - // ctrlTglAwal.text = - // selectedDateAwal.toString().split(' ')[0]; - ctrlTglAwal.text = formattedDate; - tglAwal.value = selectedDateAwal; - tglAwalTmp.value = selectedDateAwal.toString(); - } - - if (selectedDateAwal == null) { - print('cancel button'); - return; - } - - // focusNodetglAwal.unfocus(); + backgroundColor: Constant.pcBtnBackgroundColor, + iconTheme: IconThemeData( + color: Constant.textWhite, + ), + ), + drawer: CustomDrawer(), + body: SafeArea( + child: Padding( + padding: EdgeInsets.only( + top: Constant.getActualYPhone(context: context, y: 15), + left: Constant.getActualXPhone(context: context, x: 10), + right: Constant.getActualXPhone(context: context, x: 10), + bottom: Constant.getActualYPhone(context: context, y: 10), + ), + child: Container( + // height: MediaQuery.of(context).size.height - 10, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // filter + Row( + children: [ + // Tanggal Awal + Expanded( + child: GestureDetector( + onTap: () { + focusNodetglAwal.unfocus(); // _closeKeyboard(); }, - ), - ), - ), - - SizedBox( - width: - Constant.getActualXPhone(context: context, x: 10), - ), - // Tanggal Akhir - Expanded( - child: GestureDetector( - onTap: () { - focusNodetglAkhir.unfocus(); - // _closeKeyboard(); - }, - child: TextField( - enableInteractiveSelection: false, - showCursor: (tglAwalHasFocus.value) ? true : false, - controller: ctrlTglAkhir, - decoration: InputDecoration( - hintStyle: - Constant.body2_400(context: context).copyWith( - color: Constant.textGreyv2, - ), - labelStyle: - Constant.body2_400(context: context).copyWith( - color: Constant.textGreyv2, - ), - border: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.orange, - width: 1, - ), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( + child: TextField( + enableInteractiveSelection: false, + showCursor: + (tglAwalHasFocus.value) ? true : false, + controller: ctrlTglAwal, + decoration: InputDecoration( + hintStyle: Constant.body2_400(context: context) + .copyWith( color: Constant.textGreyv2, - width: 1, ), + labelStyle: Constant.body2_400(context: context) + .copyWith( + color: Constant.textGreyv2, + ), + border: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.orange, + width: 1, + ), + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Constant.textGreyv2, + width: 1, + ), + ), + labelText: "Tanggal Awal", + hintText: 'Tanggal Awal', + // suffixIcon: isLoadingFilterScope.value + // ? SizedBox( + // width: Constant.getActualXPhone( + // context: context, + // x: 4, + // ), + // height: Constant.getActualYPhone( + // context: context, + // y: 4, + // ), + // child: CircularProgressIndicator( + // color: Constant.textRed, + // ), + // ) + // : Icon( + // Icons.calendar_month_sharp, + // color: Constant.colorIconDate, + // ), ), - labelText: "Tanggal Akhir", - hintText: 'Tanggal Akhir', - // suffixIcon: isLoadingFilterScope.value - // ? SizedBox( - // width: Constant.getActualXPhone( - // context: context, - // x: 4, - // ), - // height: Constant.getActualYPhone( - // context: context, - // y: 4, - // ), - // child: CircularProgressIndicator( - // color: Constant.textRed, - // ), - // ) - // : Icon( - // Icons.calendar_month_sharp, - // color: Constant.colorIconDate, - // ), + onTap: () async { + final selectedDateAwal = await showDatePicker( + // locale: const Locale("en-CA"), + // locale: , + context: context, + initialEntryMode: + DatePickerEntryMode.calendarOnly, + firstDate: DateTime(2000), + lastDate: DateTime(2100), + + initialDate: (ctrlTglAwal.text.isEmpty) + ? DateTime.now() + : tglAwal.value, + ); + + if (selectedDateAwal != null) { + String formattedDate = + DateFormat('dd-MM-yyyy') + .format(selectedDateAwal); + // ctrlTglAwal.text = + // selectedDateAwal.toString().split(' ')[0]; + ctrlTglAwal.text = formattedDate; + tglAwal.value = selectedDateAwal; + tglAwalTmp.value = + selectedDateAwal.toString(); + } + + if (selectedDateAwal == null) { + print('cancel button'); + return; + } + + // focusNodetglAwal.unfocus(); + // _closeKeyboard(); + }, ), - onTap: () async { - final selectedDateAkhir = await showDatePicker( - // locale: const Locale("en-CA"), - // locale: , - context: context, - initialEntryMode: - DatePickerEntryMode.calendarOnly, - firstDate: DateTime(2000), - lastDate: DateTime(2100), - - initialDate: (ctrlTglAkhir.text.isEmpty) - ? DateTime.now() - : tglAkhir.value, - ); - - if (selectedDateAkhir != null) { - String formattedDate = DateFormat('dd-MM-yyyy') - .format(selectedDateAkhir); - // ctrlTglAkhir.text = - // selectedDateAkhir.toString().split(' ')[0]; - ctrlTglAkhir.text = formattedDate; - tglAkhir.value = selectedDateAkhir; - tglAkhirTmp.value = - selectedDateAkhir.toString(); - } - - if (selectedDateAkhir == null) { - print('cancel button'); - return; - } - }, ), ), - ), - ], - ), - SizedBox( - height: Constant.getActualYPhone(context: context, y: 20), - ), - Text( - 'Kategori', - style: Constant.body1(context: context).copyWith( - fontWeight: FontWeight.w600, - color: Constant.textBlack, - ), - ), - SizedBox( - height: Constant.getActualYPhone(context: context, y: 10), - ), - // Dropdown kategori - (listCategoryLoading.value) - ? SizedBox( + + SizedBox( width: - Constant.getActualXPhone(context: context, x: 24), - height: - Constant.getActualYPhone(context: context, y: 32), - child: Center( - child: CircularProgressIndicator(), - ), - ) - : SizedBox( - width: Constant.getActualXPhone( - context: context, x: 390), - child: DropdownButtonHideUnderline( - child: DropdownButton2( - isExpanded: true, - hint: Row( - children: [ - Expanded( - child: Text( - 'Select Item', - style: Constant.body1(context: context) - .copyWith( - fontWeight: FontWeight.w600, - color: Constant.textBlack), - overflow: TextOverflow.ellipsis, - ), + Constant.getActualXPhone(context: context, x: 10), + ), + // Tanggal Akhir + Expanded( + child: GestureDetector( + onTap: () { + focusNodetglAkhir.unfocus(); + // _closeKeyboard(); + }, + child: TextField( + enableInteractiveSelection: false, + showCursor: + (tglAwalHasFocus.value) ? true : false, + controller: ctrlTglAkhir, + decoration: InputDecoration( + hintStyle: Constant.body2_400(context: context) + .copyWith( + color: Constant.textGreyv2, + ), + labelStyle: Constant.body2_400(context: context) + .copyWith( + color: Constant.textGreyv2, + ), + border: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.orange, + width: 1, ), - ], + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Constant.textGreyv2, + width: 1, + ), + ), + labelText: "Tanggal Akhir", + hintText: 'Tanggal Akhir', + // suffixIcon: isLoadingFilterScope.value + // ? SizedBox( + // width: Constant.getActualXPhone( + // context: context, + // x: 4, + // ), + // height: Constant.getActualYPhone( + // context: context, + // y: 4, + // ), + // child: CircularProgressIndicator( + // color: Constant.textRed, + // ), + // ) + // : Icon( + // Icons.calendar_month_sharp, + // color: Constant.colorIconDate, + // ), ), - items: listCategoryData.value - .map((ListCategory option) { - return DropdownMenuItem( - value: option, - child: Text( - option.categoryname ?? "", - style: Constant.body1(context: context) - .copyWith( - color: Constant.textBlack, - fontWeight: FontWeight.w600), - ), + onTap: () async { + final selectedDateAkhir = await showDatePicker( + // locale: const Locale("en-CA"), + // locale: , + context: context, + initialEntryMode: + DatePickerEntryMode.calendarOnly, + firstDate: DateTime(2000), + lastDate: DateTime(2100), + + initialDate: (ctrlTglAkhir.text.isEmpty) + ? DateTime.now() + : tglAkhir.value, ); - }).toList(), - value: selectedListCategory.value, - onChanged: (ListCategory? newValue) { - // if (newValue) { - selectedListCategory.value = newValue!; - print(selectedListCategory.value.categoryid); - // } + + if (selectedDateAkhir != null) { + String formattedDate = + DateFormat('dd-MM-yyyy') + .format(selectedDateAkhir); + // ctrlTglAkhir.text = + // selectedDateAkhir.toString().split(' ')[0]; + ctrlTglAkhir.text = formattedDate; + tglAkhir.value = selectedDateAkhir; + tglAkhirTmp.value = + selectedDateAkhir.toString(); + } + + if (selectedDateAkhir == null) { + print('cancel button'); + return; + } }, - buttonStyleData: ButtonStyleData( - height: Constant.getActualY( - context: context, y: 56), - width: Constant.getActualX( - context: context, x: 320), - padding: EdgeInsets.only( - left: Constant.getActualX( - context: context, x: 10), - right: Constant.getActualX( - context: context, x: 10), - ), - decoration: BoxDecoration( - color: Constant.white, - border: Border.all( - color: Constant.textBlack, width: 1), - borderRadius: BorderRadius.circular(8), - ), - elevation: 2, - ), - iconStyleData: IconStyleData( - icon: Icon( - Icons.keyboard_arrow_down_outlined, - ), - iconSize: 24, - iconEnabledColor: Constant.textBlack, - iconDisabledColor: Colors.grey, - ), - dropdownStyleData: DropdownStyleData( - maxHeight: Constant.getActualY( - context: context, y: 200), - // width: Constant.getActualX(context: context, x: 320), - padding: EdgeInsets.only( - top: Constant.getActualY( - context: context, y: 10), - left: Constant.getActualX( - context: context, x: 10), - right: Constant.getActualX( - context: context, x: 10), - bottom: Constant.getActualY( - context: context, y: 10), - ), - decoration: BoxDecoration( - color: Constant.white, - borderRadius: BorderRadius.circular(8), - boxShadow: [ - BoxShadow( - color: Colors.grey, - blurRadius: 20.0, - spreadRadius: 2.0, - offset: Offset(0.0, 0.0), + ), + ), + ), + ], + ), + SizedBox( + height: Constant.getActualYPhone(context: context, y: 20), + ), + Text( + 'Kategori', + style: Constant.body1(context: context).copyWith( + fontWeight: FontWeight.w600, + color: Constant.textBlack, + ), + ), + SizedBox( + height: Constant.getActualYPhone(context: context, y: 10), + ), + // Dropdown kategori + (listCategoryLoading.value) + ? SizedBox( + width: Constant.getActualXPhone( + context: context, x: 24), + height: Constant.getActualYPhone( + context: context, y: 32), + child: Center( + child: CircularProgressIndicator(), + ), + ) + : SizedBox( + width: Constant.getActualXPhone( + context: context, x: 390), + child: DropdownButtonHideUnderline( + child: DropdownButton2( + isExpanded: true, + hint: Row( + children: [ + Expanded( + child: Text( + 'Select Item', + style: Constant.body1(context: context) + .copyWith( + fontWeight: FontWeight.w600, + color: Constant.textBlack), + overflow: TextOverflow.ellipsis, + ), ), ], ), - elevation: 8, - offset: const Offset(0, -10), - scrollbarTheme: ScrollbarThemeData( - radius: const Radius.circular(40), - thickness: - MaterialStateProperty.all(6), - thumbVisibility: - MaterialStateProperty.all(true), - ), - ), - menuItemStyleData: MenuItemStyleData( - height: Constant.getActualY( - context: context, y: 56), - padding: EdgeInsets.only( - top: Constant.getActualY( - context: context, y: 10), - left: Constant.getActualX( - context: context, x: 10), - right: Constant.getActualX( - context: context, x: 10), - ), - ), - ), - ), - ), - - SizedBox( - height: Constant.getActualYPhone(context: context, y: 10), - ), - Container( - width: Constant.getActualXPhone(context: context, x: 390), - child: Align( - alignment: Alignment.centerRight, - child: ElevatedButton( - style: ButtonStyle( - backgroundColor: MaterialStateColor.resolveWith( - (st) => Constant.pcBtnBackgroundColor), - shape: - MaterialStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - side: BorderSide( - color: Constant.pcBtnBackgroundColor, - ), - ), - ), - shadowColor: - MaterialStateProperty.all(Color(0xffff48423d)), - elevation: MaterialStateProperty.all(4.0), - ), - child: Stack( - children: [ - (categoryIsLoading.value) - ? SizedBox( - width: Constant.getActualXPhone( - context: context, x: 24), - height: Constant.getActualYPhone( - context: context, y: 32), - child: CircularProgressIndicator( - color: Colors.white, + items: listCategoryData.value + .map((ListCategory option) { + return DropdownMenuItem( + value: option, + child: Text( + option.categoryname ?? "", + style: Constant.body1(context: context) + .copyWith( + color: Constant.textBlack, + fontWeight: FontWeight.w600), ), - ) - : Text( - 'Search', - style: Constant.body1(context: context) - .copyWith( - fontWeight: FontWeight.w600, - color: Constant.white), + ); + }).toList(), + value: selectedListCategory.value, + onChanged: (ListCategory? newValue) { + // if (newValue) { + selectedListCategory.value = newValue!; + print(selectedListCategory.value.categoryid); + // } + }, + buttonStyleData: ButtonStyleData( + height: Constant.getActualY( + context: context, y: 56), + width: Constant.getActualX( + context: context, x: 320), + padding: EdgeInsets.only( + left: Constant.getActualX( + context: context, x: 10), + right: Constant.getActualX( + context: context, x: 10), ), - ], + decoration: BoxDecoration( + color: Constant.white, + border: Border.all( + color: Constant.textBlack, width: 1), + borderRadius: BorderRadius.circular(8), + ), + elevation: 2, + ), + iconStyleData: IconStyleData( + icon: Icon( + Icons.keyboard_arrow_down_outlined, + ), + iconSize: 24, + iconEnabledColor: Constant.textBlack, + iconDisabledColor: Colors.grey, + ), + dropdownStyleData: DropdownStyleData( + maxHeight: Constant.getActualY( + context: context, y: 200), + // width: Constant.getActualX(context: context, x: 320), + padding: EdgeInsets.only( + top: Constant.getActualY( + context: context, y: 10), + left: Constant.getActualX( + context: context, x: 10), + right: Constant.getActualX( + context: context, x: 10), + bottom: Constant.getActualY( + context: context, y: 10), + ), + decoration: BoxDecoration( + color: Constant.white, + borderRadius: BorderRadius.circular(8), + boxShadow: [ + BoxShadow( + color: Colors.grey, + blurRadius: 20.0, + spreadRadius: 2.0, + offset: Offset(0.0, 0.0), + ), + ], + ), + elevation: 8, + offset: const Offset(0, -10), + scrollbarTheme: ScrollbarThemeData( + radius: const Radius.circular(40), + thickness: + MaterialStateProperty.all(6), + thumbVisibility: + MaterialStateProperty.all(true), + ), + ), + menuItemStyleData: MenuItemStyleData( + height: Constant.getActualY( + context: context, y: 56), + padding: EdgeInsets.only( + top: Constant.getActualY( + context: context, y: 10), + left: Constant.getActualX( + context: context, x: 10), + right: Constant.getActualX( + context: context, x: 10), + ), + ), + ), + ), + ), + + SizedBox( + height: Constant.getActualYPhone(context: context, y: 10), + ), + Container( + width: Constant.getActualXPhone(context: context, x: 390), + child: Align( + alignment: Alignment.centerRight, + child: ElevatedButton( + style: ButtonStyle( + backgroundColor: MaterialStateColor.resolveWith( + (st) => Constant.pcBtnBackgroundColor), + shape: MaterialStateProperty.all< + RoundedRectangleBorder>( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide( + color: Constant.pcBtnBackgroundColor, + ), + ), + ), + shadowColor: + MaterialStateProperty.all(Color(0xffff48423d)), + elevation: MaterialStateProperty.all(4.0), + ), + child: Stack( + children: [ + (categoryIsLoading.value) + ? SizedBox( + width: Constant.getActualXPhone( + context: context, x: 24), + height: Constant.getActualYPhone( + context: context, y: 32), + child: CircularProgressIndicator( + color: Colors.white, + ), + ) + : Text( + 'Search', + style: Constant.body1(context: context) + .copyWith( + fontWeight: FontWeight.w600, + color: Constant.white), + ), + ], + ), + onPressed: () async { + M_CompanyID.value = await getCompanyID(); + ref + .read(searchHistoryTransaksiProvider.notifier) + .searchHistoryTransaksi( + M_CompanyID.value, + ctrlTglAwal.text, + ctrlTglAkhir.text, + selectedListCategory.value.categoryid ?? "0", + ); + }, ), - onPressed: () async { - M_CompanyID.value = await getCompanyID(); - ref - .read(searchHistoryTransaksiProvider.notifier) - .searchHistoryTransaksi( - M_CompanyID.value, - ctrlTglAwal.text, - ctrlTglAkhir.text, - selectedListCategory.value.categoryid ?? "0", - ); - }, ), ), - ), - SizedBox( - height: Constant.getActualYPhone(context: context, y: 20), - ), + SizedBox( + height: Constant.getActualYPhone(context: context, y: 20), + ), - // Card looping transaksi + // Card looping transaksi - // (searchHistoryIsLoading.value) - // ? Center( - // child: CircularProgressIndicator(), - // ) - // : Expanded( - // child: ListView.builder( - // itemCount: listSearchHistory.value.length, - // itemBuilder: (context, idx) { - // return Card( - // child: Padding( - // padding: EdgeInsets.all(16.0), - // child: Column( - // crossAxisAlignment: - // CrossAxisAlignment.start, - // children: [ - // FieldRowHistoryTransaksi( - // label: "Tipe", - // value: listSearchHistory - // .value[idx].tipe - // .toString(), - // ), - // SizedBox(height: 8.0), - // FieldRowHistoryTransaksi( - // label: "Tanggal", - // value: listSearchHistory - // .value[idx].tanggaltransaksi - // .toString(), - // ), - // SizedBox(height: 8.0), - // FieldRowHistoryTransaksi( - // label: "Nominal", - // value: listSearchHistory - // .value[idx].amount - // .toString(), - // // value: "nunggu api", - // ), - // SizedBox(height: 8.0), - // FieldRowHistoryTransaksi( - // label: "Kategori", - // value: listSearchHistory - // .value[idx].kategoriname - // .toString(), - // ), - // SizedBox(height: 8.0), - // if (listSearchHistory - // .value[idx].isconfirm == - // "Y") - // Row( - // mainAxisAlignment: - // MainAxisAlignment.end, - // children: [ - // Chip( - // label: Text( - // 'Confirmed', - // style: TextStyle( - // color: - // Constant.green_600), - // ), - // shape: RoundedRectangleBorder( - // side: BorderSide( - // color: - // Constant.green_600), - // borderRadius: - // BorderRadius.circular( - // 4.0), - // ), - // backgroundColor: Colors.white, - // ), - // ], - // ), - // SizedBox( - // height: Constant.getActualYPhone( - // context: context, y: 6), - // ), - // if (listSearchHistory - // .value[idx].isconfirm == - // "N") - // Row( - // mainAxisAlignment: - // MainAxisAlignment.end, - // children: [ - // ElevatedButton( - // onPressed: () { - // // Handle delete button tap - // }, - // child: Text( - // 'Delete', - // style: TextStyle( - // color: - // Constant.textWhite), - // ), - // style: ElevatedButton.styleFrom( - // backgroundColor: Colors - // .red, // Ganti dengan warna delete button yang diinginkan - // ), - // ), - // ], - // ) - // ], - // ), - // ), - // ); - // }, - // ), - // ), + // (searchHistoryIsLoading.value) + // ? Center( + // child: CircularProgressIndicator(), + // ) + // : Expanded( + // child: ListView.builder( + // itemCount: listSearchHistory.value.length, + // itemBuilder: (context, idx) { + // return Card( + // child: Padding( + // padding: EdgeInsets.all(16.0), + // child: Column( + // crossAxisAlignment: + // CrossAxisAlignment.start, + // children: [ + // FieldRowHistoryTransaksi( + // label: "Tipe", + // value: listSearchHistory + // .value[idx].tipe + // .toString(), + // ), + // SizedBox(height: 8.0), + // FieldRowHistoryTransaksi( + // label: "Tanggal", + // value: listSearchHistory + // .value[idx].tanggaltransaksi + // .toString(), + // ), + // SizedBox(height: 8.0), + // FieldRowHistoryTransaksi( + // label: "Nominal", + // value: listSearchHistory + // .value[idx].amount + // .toString(), + // // value: "nunggu api", + // ), + // SizedBox(height: 8.0), + // FieldRowHistoryTransaksi( + // label: "Kategori", + // value: listSearchHistory + // .value[idx].kategoriname + // .toString(), + // ), + // SizedBox(height: 8.0), + // if (listSearchHistory + // .value[idx].isconfirm == + // "Y") + // Row( + // mainAxisAlignment: + // MainAxisAlignment.end, + // children: [ + // Chip( + // label: Text( + // 'Confirmed', + // style: TextStyle( + // color: + // Constant.green_600), + // ), + // shape: RoundedRectangleBorder( + // side: BorderSide( + // color: + // Constant.green_600), + // borderRadius: + // BorderRadius.circular( + // 4.0), + // ), + // backgroundColor: Colors.white, + // ), + // ], + // ), + // SizedBox( + // height: Constant.getActualYPhone( + // context: context, y: 6), + // ), + // if (listSearchHistory + // .value[idx].isconfirm == + // "N") + // Row( + // mainAxisAlignment: + // MainAxisAlignment.end, + // children: [ + // ElevatedButton( + // onPressed: () { + // // Handle delete button tap + // }, + // child: Text( + // 'Delete', + // style: TextStyle( + // color: + // Constant.textWhite), + // ), + // style: ElevatedButton.styleFrom( + // backgroundColor: Colors + // .red, // Ganti dengan warna delete button yang diinginkan + // ), + // ), + // ], + // ) + // ], + // ), + // ), + // ); + // }, + // ), + // ), - (searchHistoryIsLoading.value) - ? Center( - child: CircularProgressIndicator(), - ) - : Expanded( - child: ListView.builder( - itemCount: listSearchHistory.value.length, - itemBuilder: (context, idx) { - return Padding( - padding: EdgeInsets.only( - bottom: Constant.getActualYPhone( - context: context, - y: 10, + (searchHistoryIsLoading.value) + ? Center( + child: CircularProgressIndicator(), + ) + : Expanded( + child: ListView.builder( + itemCount: listSearchHistory.value.length, + itemBuilder: (context, idx) { + String imgUrl = listSearchHistory + .value[idx].imgurl + .toString(); + return Padding( + padding: EdgeInsets.only( + bottom: Constant.getActualYPhone( + context: context, + y: 10, + ), ), - ), - child: Card( - elevation: 2.0, - child: Padding( - padding: EdgeInsets.all(10), - child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisAlignment: MainAxisAlignment.start, - children: [ - // atas - HistoryRowAtasWidget( - icon_category_id: listSearchHistory - .value[idx].kategoriid - .toString(), - icon_category_name: listSearchHistory - .value[idx].kategoriname - .toString(), - amount: listSearchHistory - .value[idx].amount - .toString(), - tglTransaksi: listSearchHistory - .value[idx].tanggaltransaksi - .toString(), - tipe: listSearchHistory - .value[idx].tipe - .toString(), - // searchHistoryIsLoading.value - ), - - // bawah - - if (listSearchHistory - .value[idx].isconfirm == - "Y") - Row( - mainAxisAlignment: - MainAxisAlignment.end, - children: [ - Chip( - label: Text( - 'Confirmed', - style: TextStyle( - color: Constant.textWhite, - ), - ), - shape: RoundedRectangleBorder( - side: BorderSide( - color: Constant - .bgTextChipConfirmed), - borderRadius: - BorderRadius.circular( - 50, - ), - ), - backgroundColor: Constant - .bgTextChipConfirmed, - ), - ], + child: Card( + elevation: 2.0, + child: Padding( + padding: EdgeInsets.all(10), + child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // mainAxisAlignment: MainAxisAlignment.start, + children: [ + // atas + HistoryRowAtasWidget( + icon_category_id: listSearchHistory + .value[idx].kategoriid + .toString(), + icon_category_name: + listSearchHistory + .value[idx].kategoriname + .toString(), + amount: listSearchHistory + .value[idx].amount + .toString(), + tglTransaksi: listSearchHistory + .value[idx].tanggaltransaksi + .toString(), + tipe: listSearchHistory + .value[idx].tipe + .toString(), + // searchHistoryIsLoading.value ), - SizedBox( - height: Constant.getActualYPhone( - context: context, y: 6), - ), - if (listSearchHistory - .value[idx].isconfirm == - "N") - Row( - mainAxisAlignment: - MainAxisAlignment.end, - children: [ - InkWell( - onTap: () async { - final userID = ref - .read( - currentUserProvider) - ?.model - .M_UserID ?? - "0"; - // print('Deleted'); - showDeleteConfirmationDialog( - context, - listSearchHistory - .value[idx].id - .toString(), - userID, - M_CompanyID.value, - ctrlTglAwal.text.toString(), - ctrlTglAkhir.text - .toString(), - selectedListCategory - .value.categoryid - .toString(), - ); - }, - child: Chip( + // bawah + + // if (listSearchHistory + // .value[idx].isconfirm == + // "Y") + // Row( + // mainAxisAlignment: + // MainAxisAlignment.end, + // children: [ + // Chip( + // label: Text( + // 'Confirmed', + // style: TextStyle( + // color: Constant.textWhite, + // ), + // ), + // shape: RoundedRectangleBorder( + // side: BorderSide( + // color: Constant + // .bgTextChipConfirmed), + // borderRadius: + // BorderRadius.circular( + // 50, + // ), + // ), + // backgroundColor: Constant + // .bgTextChipConfirmed, + // ), + // ], + // ), + SizedBox( + height: Constant.getActualYPhone( + context: context, y: 6), + ), + + if (listSearchHistory + .value[idx].isconfirm == + "N") + Row( + mainAxisAlignment: + MainAxisAlignment + .spaceBetween, + children: [ + InkWell( + onTap: () async { + final userID = ref + .read( + currentUserProvider) + ?.model + .M_UserID ?? + "0"; + // print('Deleted'); + showDeleteConfirmationDialog( + context, + listSearchHistory + .value[idx].id + .toString(), + userID, + M_CompanyID.value, + ctrlTglAwal.text + .toString(), + ctrlTglAkhir.text + .toString(), + selectedListCategory + .value.categoryid + .toString(), + ); + }, + child: Chip( + label: Text( + 'Delete', + style: TextStyle( + color: + Constant.textWhite, + ), + ), + shape: + RoundedRectangleBorder( + side: BorderSide( + color: Constant + .bgTextChipDelete), + borderRadius: + BorderRadius.circular( + 10, + ), + ), + backgroundColor: + Constant.bgTextDelete, + ), + ), + if (imgUrl != "") + InkWell( + onTap: () async { + String fileExtension = + imgUrl + .split('.') + .last + .toLowerCase(); + if (fileExtension == 'png' || + fileExtension == + 'jpg' || + fileExtension == + 'jpeg') { + showImageDialog( + context, + imgUrl, + ); + } else { + if (!await launchUrl( + Uri.parse( + Constant.baseUrlFile + + imgUrl, + ), + )) { + // throw Exception('Could not launch $url'); + SanckbarWidget( + context, + 'Could not launch ${Constant.baseUrlFile + imgUrl}', + snackbarType + .error); + } + } + }, + child: Icon( + Icons.attach_file, + color: Constant + .pcBtnBackgroundColor, + ), + ), + InkWell( + onTap: () async { + final userID = ref + .read( + currentUserProvider) + ?.model + .M_UserID ?? + "0"; + showConfirmDialog( + context, + listSearchHistory + .value[idx].id + .toString(), + userID, + M_CompanyID.value, + ctrlTglAwal.text + .toString(), + ctrlTglAkhir.text + .toString(), + selectedListCategory + .value.categoryid + .toString(), + ); + }, + child: Chip( + label: Text( + 'Confirm', + style: TextStyle( + color: + Constant.textWhite, + ), + ), + shape: + RoundedRectangleBorder( + side: BorderSide( + color: + Constant.green_600, + ), + borderRadius: + BorderRadius.circular( + 10), + ), + backgroundColor: + Constant.green_600, + ), + ), + ], + ), + + // Confirmed + if (listSearchHistory + .value[idx].isconfirm == + "Y") + Row( + mainAxisAlignment: + MainAxisAlignment + .spaceBetween, + children: [ + Chip( label: Text( - 'Deleted', + 'Confirmed', style: TextStyle( - color: Constant.textWhite, + color: Constant.green_600, ), ), shape: RoundedRectangleBorder( side: BorderSide( - color: Constant - .bgTextChipDelete), + color: Constant.green_600, + ), borderRadius: BorderRadius.circular( - 50, - ), + 50), ), backgroundColor: - Constant.bgTextDelete, + Constant.textWhite, ), - ), - ], - ), - // Row( - // children: [ - // Container( - // width: Constant.getActualXPhone( - // context: context, x: 40), - // height: Constant.getActualYPhone( - // context: context, - // y: 40, - // ), - // child: Image.asset( - // "images/icon_delete.png", - // // scale: 1, - // ), - // ), - // SizedBox( - // height: Constant.getActualYPhone( - // context: context, y: 12), - // ), - // Expanded( - // child: ElevatedButton( - // style: ButtonStyle( - // backgroundColor: MaterialStateColor - // .resolveWith((st) => Constant - // .pcBtnBackgroundColor), - // shape: - // MaterialStateProperty.all< - // RoundedRectangleBorder>( - // RoundedRectangleBorder( - // borderRadius: - // BorderRadius.circular( - // 8), - // side: BorderSide( - // color: Constant - // .pcBtnBackgroundColor, - // ), - // ), - // ), - // shadowColor: - // MaterialStateProperty.all( - // Color(0xffff48423d)), - // elevation: - // MaterialStateProperty.all( - // 4.0), - // ), - // child: Stack( - // children: [ - // Text( - // 'Confirmed', - // style: Constant.body1( - // context: context) - // .copyWith( - // fontWeight: - // FontWeight - // .w600, - // color: Constant - // .white), - // ), - // ], - // ), - // onPressed: () {}, - // ), - // ), - // ], - // ), - ], + if (imgUrl != "") + InkWell( + onTap: () async { + String fileExtension = + imgUrl + .split('.') + .last + .toLowerCase(); + if (fileExtension == 'png' || + fileExtension == + 'jpg' || + fileExtension == + 'jpeg') { + showImageDialog( + context, + imgUrl, + ); + } else { + if (!await launchUrl( + Uri.parse( + imgUrl))) { + // throw Exception('Could not launch $url'); + SanckbarWidget( + context, + 'Could not launch $imgUrl', + snackbarType.error, + ); + } + } + }, + child: Icon( + Icons.attach_file, + color: Constant + .pcBtnBackgroundColor, + ), + ), + Chip( + label: Text( + 'Confirm', + style: TextStyle( + color: Colors.white, + ), + ), + shape: RoundedRectangleBorder( + side: BorderSide( + color: Colors.white, + ), + borderRadius: + BorderRadius.circular( + 10), + ), + backgroundColor: Colors.white, + ), + ], + ), + // Row( + // children: [ + // Container( + // width: Constant.getActualXPhone( + // context: context, x: 40), + // height: Constant.getActualYPhone( + // context: context, + // y: 40, + // ), + // child: Image.asset( + // "images/icon_delete.png", + // // scale: 1, + // ), + // ), + // SizedBox( + // height: Constant.getActualYPhone( + // context: context, y: 12), + // ), + // Expanded( + // child: ElevatedButton( + // style: ButtonStyle( + // backgroundColor: MaterialStateColor + // .resolveWith((st) => Constant + // .pcBtnBackgroundColor), + // shape: + // MaterialStateProperty.all< + // RoundedRectangleBorder>( + // RoundedRectangleBorder( + // borderRadius: + // BorderRadius.circular( + // 8), + // side: BorderSide( + // color: Constant + // .pcBtnBackgroundColor, + // ), + // ), + // ), + // shadowColor: + // MaterialStateProperty.all( + // Color(0xffff48423d)), + // elevation: + // MaterialStateProperty.all( + // 4.0), + // ), + // child: Stack( + // children: [ + // Text( + // 'Confirmed', + // style: Constant.body1( + // context: context) + // .copyWith( + // fontWeight: + // FontWeight + // .w600, + // color: Constant + // .white), + // ), + // ], + // ), + // onPressed: () {}, + // ), + // ), + // ], + // ), + ], + ), ), ), - ), - ); - }, + ); + }, + ), ), - ), - ], + ], + ), ), ), ), diff --git a/app_petty_cash/lib/widget/custom_drawer.dart b/app_petty_cash/lib/widget/custom_drawer.dart index 1193299..314d450 100644 --- a/app_petty_cash/lib/widget/custom_drawer.dart +++ b/app_petty_cash/lib/widget/custom_drawer.dart @@ -91,248 +91,203 @@ class CustomDrawer extends HookConsumerWidget { final currentMenu = ref.read(currentPageProvider); - return Drawer( - elevation: 0, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(0))), - child: Container( - child: ListView( - // padding: EdgeInsets.only( - // top: Constant.getActualYPhone(context: context, y: 10), - // ), + return Container( + width: Constant.getActualXPhone(context: context, x: 300), + height: Constant.getActualYPhone(context: context, y: 844), + child: Drawer( + elevation: 0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(0))), + child: Column( children: [ - Container( - // decoration: BoxDecoration( - // border: Border(bottom: BorderSide(color: Colors.transparent)) // <--- use the global theme to change the dividerColor property - // ), - child: Image( - image: AssetImage('images/logo_sismedika_landscape.png')), - ), + Expanded( + child: ListView( + children: [ + Container( + child: Image( + image: + AssetImage('images/logo_sismedika_landscape.png')), + ), - SizedBox( - height: Constant.getActualYPhone(context: context, y: 8), - ), + SizedBox( + 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), + ), + ), + + // 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), + // ), + // ), + // ), + // ), + // ), + // ), + Chip( + backgroundColor: Constant.textGrey.withOpacity(0.16), + label: Text( + M_CompanyName.value, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Constant.textGreyv2, + ), + ), + ), + + ListTile( + leading: Icon( + Icons.home, + color: (currentMenu == 0) + ? Constant.pcBtnBackgroundColor + : Constant.textGreyv2, + ), + title: Text( + 'Home', + style: TextStyle( + color: (currentMenu == 0) + ? Constant.pcBtnBackgroundColor + : Constant.textGreyv2, + ), + ), + 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) + ? Constant.pcBtnBackgroundColor + : Constant.textGreyv2, + ), + ), + 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) + ? Constant.pcBtnBackgroundColor + : Constant.textGreyv2, + ), + ), + 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) + ? Constant.pcBtnBackgroundColor + : Constant.textGreyv2, + ), + ), + onTap: () { + // Handle navigation to Transaksi screen + Navigator.pop(context); + ref.read(currentPageProvider.state).update((state) => 3); + Navigator.pushNamed(context, reportRoute); + }, + ), + ListTile( + leading: Icon( + Icons.logout, + color: Constant.textGreyv2, + ), + 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 ?? "", + ); + }, + ), + ], + ), + ), + // Versi Aplikasi Padding( padding: EdgeInsets.only( - top: Constant.getActualYPhone(context: context, y: 10), + right: Constant.getActualXPhone(context: context, x: 20), 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), - // ), - // ), - // ), - // ), - // ), - // ), - - Chip( - backgroundColor: Constant.textGrey.withOpacity(0.16), - label: Text( - M_CompanyName.value, - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Constant.textGreyv2, + child: Align( + alignment: Alignment.bottomRight, + child: Text( + 'Versi ${Constant.version}', + style: Constant.titleH4Login(context: context) + .copyWith(color: Constant.textGrey), ), ), ), - - ListTile( - leading: Icon( - Icons.home, - color: (currentMenu == 0) - ? Constant.pcBtnBackgroundColor - : 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); - }, - ), - ListTile( - leading: Icon( - Icons.money, - color: (currentMenu == 1) - ? Constant.pcBtnBackgroundColor - : 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); - }, - ), - ListTile( - leading: Icon( - Icons.history, - color: (currentMenu == 2) - ? Constant.pcBtnBackgroundColor - : 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); - }, - ), - ListTile( - leading: Icon( - Icons.feed, - color: (currentMenu == 3) - ? Constant.pcBtnBackgroundColor - : 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); - }, - ), - // ListTile( - // title: Text( - // 'User', - // style: TextStyle( - // color: (currentMenu == 4) - // ? Constant.textWhite - // : Constant.textBlack, - // ), - // ), - // tileColor: (currentMenu == 4) - // ? Constant.pcBtnBackgroundColor - // : Colors.transparent, - // onTap: () { - // // Handle navigation to User screen - // Navigator.pop(context); - // ref.read(currentPageProvider.state).update((state) => 4); - // Navigator.pushNamed(context, userRoute); - // }, - // ), - // ListTile( - // title: Text( - // 'Change Company', - // style: TextStyle( - // color: (currentMenu == 5) - // ? Constant.textWhite - // : Constant.textBlack, - // ), - // ), - // tileColor: (currentMenu == 5) - // ? Constant.pcBtnBackgroundColor - // : Colors.transparent, - // onTap: () { - // // Handle navigation to User screen - // Navigator.pop(context); - // ref.read(currentPageProvider.state).update((state) => 5); - // Navigator.pushNamed(context, changeCompanyRoute); - // }, - // ), - ListTile( - leading: Icon( - Icons.logout, - color: Constant.textGreyv2, - ), - 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 ?? "", - ); - }, - ), - - Spacer(), - - // Versi Aplikasi - ListTile( - title: Text( - 'Versi ${Constant.version}', - style: Constant.titleH4Login(context: context) - .copyWith(color: Constant.textGrey), - ), - onTap: () {}, - ), ], ), ), diff --git a/app_petty_cash/lib/widget/custom_drawer_v2.dart b/app_petty_cash/lib/widget/custom_drawer_v2.dart new file mode 100644 index 0000000..725be47 --- /dev/null +++ b/app_petty_cash/lib/widget/custom_drawer_v2.dart @@ -0,0 +1,341 @@ +import 'dart:async'; +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../app/constant.dart'; +import '../app/route.dart'; +import '../provider/current_menu_provider.dart'; +import '../provider/current_user_provider.dart'; +import '../screen/login/logout_provider.dart'; + +class CustomDrawerV2 extends HookConsumerWidget { + // final String userCompany; + const CustomDrawerV2({ + Key? key, + // required this.userCompany, + }) : super(key: key); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final selectedUser = ref.read(currentUserProvider); + final isLoading = useState(false); + final errorMessage = useState(""); + final successMessage = useState(""); + final M_CompanyName = useState("-"); + + Future 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(() { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + final userID = ref.read(currentUserProvider)?.model.M_UserID ?? "0"; + if (userID == "0") { + //not login + Navigator.of(context) + .pushNamedAndRemoveUntil(loginRoute, (route) => true); + + // Navigator.popAndPushNamed(context, loginRoute); + return; + } + M_CompanyName.value = await getCompanyName(); + }); + return () {}; + }, []); + + ref.listen(logoutProvider, (prev, next) async { + if (next is LogoutStateLoading) { + isLoading.value = true; + } else if (next is LogoutStateError) { + isLoading.value = false; + errorMessage.value = next.message; + Timer(const Duration(seconds: 3), () { + errorMessage.value = ""; + }); + } else if (next is LogoutStateDone) { + isLoading.value = false; + final shared = await SharedPreferences.getInstance(); + final bearerString = shared.get(Constant.bearerName).toString(); + // print(bearerString); + if (bearerString.isNotEmpty) { + shared.remove(bearerString); + shared.clear(); + // Navigator.popAndPushNamed(context, loginRoute); + Navigator.of(context) + .pushNamedAndRemoveUntil(loginRoute, (route) => false); + } + Timer(const Duration(seconds: 3), () async { + successMessage.value = ""; + }); + } + }); + + final currentMenu = ref.read(currentPageProvider); + + return Drawer( + elevation: 0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(0))), + child: Container( + child: ListView( + // padding: EdgeInsets.only( + // top: Constant.getActualYPhone(context: context, y: 10), + // ), + children: [ + Container( + // decoration: BoxDecoration( + // border: Border(bottom: BorderSide(color: Colors.transparent)) // <--- use the global theme to change the dividerColor property + // ), + child: Image( + image: AssetImage('images/logo_sismedika_landscape.png')), + ), + + SizedBox( + 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), + // ), + // ), + // ), + // ), + // ), + // ), + + Chip( + backgroundColor: Constant.textGrey.withOpacity(0.16), + label: Text( + M_CompanyName.value, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Constant.textGreyv2, + ), + ), + ), + + ListTile( + leading: Icon( + Icons.home, + color: (currentMenu == 0) + ? Constant.pcBtnBackgroundColor + : 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); + }, + ), + ListTile( + leading: Icon( + Icons.money, + color: (currentMenu == 1) + ? Constant.pcBtnBackgroundColor + : 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); + }, + ), + ListTile( + leading: Icon( + Icons.history, + color: (currentMenu == 2) + ? Constant.pcBtnBackgroundColor + : 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); + }, + ), + ListTile( + leading: Icon( + Icons.feed, + color: (currentMenu == 3) + ? Constant.pcBtnBackgroundColor + : 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); + }, + ), + // ListTile( + // title: Text( + // 'User', + // style: TextStyle( + // color: (currentMenu == 4) + // ? Constant.textWhite + // : Constant.textBlack, + // ), + // ), + // tileColor: (currentMenu == 4) + // ? Constant.pcBtnBackgroundColor + // : Colors.transparent, + // onTap: () { + // // Handle navigation to User screen + // Navigator.pop(context); + // ref.read(currentPageProvider.state).update((state) => 4); + // Navigator.pushNamed(context, userRoute); + // }, + // ), + // ListTile( + // title: Text( + // 'Change Company', + // style: TextStyle( + // color: (currentMenu == 5) + // ? Constant.textWhite + // : Constant.textBlack, + // ), + // ), + // tileColor: (currentMenu == 5) + // ? Constant.pcBtnBackgroundColor + // : Colors.transparent, + // onTap: () { + // // Handle navigation to User screen + // Navigator.pop(context); + // ref.read(currentPageProvider.state).update((state) => 5); + // Navigator.pushNamed(context, changeCompanyRoute); + // }, + // ), + ListTile( + leading: Icon( + Icons.logout, + color: Constant.textGreyv2, + ), + 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 ?? "", + ); + }, + ), + + Spacer(), + + // Versi Aplikasi + ListTile( + title: Text( + 'Versi ${Constant.version}', + style: Constant.titleH4Login(context: context) + .copyWith(color: Constant.textGrey), + ), + onTap: () {}, + ), + ], + ), + ), + ); + } +}