From 6c5bfde8280c08100d7239a82e85d3abfa9f9279 Mon Sep 17 00:00:00 2001 From: kicap Date: Thu, 10 Aug 2023 01:21:43 +0800 Subject: [PATCH] repair back button --- lib/app/app.dart | 8 +- lib/app/app.locator.dart | 4 + lib/app/core/custom_base_view_model.dart | 4 + lib/main.dart | 2 +- lib/services/global_var.dart | 3 + lib/services/my_easyloading.dart | 2 - .../input_informasi_diri_view.dart | 2 +- .../input_informasi_diri_view_model.dart | 4 +- .../masukan_no_hp/masukan_no_hp_view.dart | 2 +- .../masukan_no_hp_view_model.dart | 4 +- .../verifikasi_no_hp_view.dart | 2 +- .../verifikasi_no_hp_view_model.dart | 4 +- lib/ui/views/login_user/login_user_view.dart | 2 +- .../login_user/login_user_view_model.dart | 4 +- .../views/meja_detail/meja_detail_view.dart | 218 ++++---- .../meja_detail/meja_detail_view_model.dart | 2 +- .../user_ui/akun_user/akun_user_view.dart | 211 +++---- .../akun_user/akun_user_view_model.dart | 2 +- .../detail_makanan/detail_makanan_view.dart | 17 +- .../detail_makanan_view_model.dart | 2 +- .../makanan_list/makanan_list_view.dart | 25 +- .../makanan_list/makanan_list_view_model.dart | 2 +- .../keranjang_saya/keranjang_saya_view.dart | 281 +++++----- .../keranjang_saya_view_model.dart | 2 +- .../pesanan_list/pesanan_list_view.dart | 518 +++++++++--------- .../pesanan_list/pesanan_list_view_model.dart | 2 +- .../reservasi_meja/reservasi_meja_view.dart | 351 ++++++------ .../reservasi_meja_view_model.dart | 2 +- .../user_index_tracking_view_model.dart | 119 ++-- 29 files changed, 956 insertions(+), 845 deletions(-) create mode 100644 lib/services/global_var.dart diff --git a/lib/app/app.dart b/lib/app/app.dart index a6e3698..34b4d36 100644 --- a/lib/app/app.dart +++ b/lib/app/app.dart @@ -1,5 +1,5 @@ -import 'package:reza_app/ui/views/meja_detail/meja_detail_view.dart'; -import 'package:reza_app/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view.dart'; +import 'package:reza_app/services/global_var.dart'; +import 'package:reza_app/services/other_function.dart'; import 'package:stacked_services/stacked_services.dart'; import 'package:stacked/stacked_annotations.dart'; @@ -9,10 +9,12 @@ import '../ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_vie import '../ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view.dart'; import '../ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view.dart'; import '../ui/views/login_user/login_user_view.dart'; +import '../ui/views/meja_detail/meja_detail_view.dart'; import '../ui/views/splash_screen/splash_screen_view.dart'; import '../ui/views/user_ui/akun_user/akun_user_view.dart'; import '../ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view.dart'; import '../ui/views/user_ui/makanan_list/makanan_list_view.dart'; +import '../ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view.dart'; import '../ui/views/user_ui/pesanan_list/pesanan_list_view.dart'; import '../ui/views/user_ui/reservasi_meja/reservasi_meja_view.dart'; import '../ui/views/user_ui/user_index_tracking/user_index_tracking_view.dart'; @@ -50,6 +52,8 @@ import '../ui/views/user_ui/user_index_tracking/user_index_tracking_view.dart'; LazySingleton(classType: MyEasyLoading), LazySingleton(classType: MyHttpServices), + LazySingleton(classType: OtherFunction), + LazySingleton(classType: GlobalVar), ], logger: StackedLogger(), ) diff --git a/lib/app/app.locator.dart b/lib/app/app.locator.dart index 57e7a42..97e55c5 100644 --- a/lib/app/app.locator.dart +++ b/lib/app/app.locator.dart @@ -12,8 +12,10 @@ import 'package:stacked_services/src/navigation/navigation_service.dart'; import 'package:stacked_services/src/snackbar/snackbar_service.dart'; import 'package:stacked_shared/stacked_shared.dart'; +import '../services/global_var.dart'; import '../services/http_services.dart'; import '../services/my_easyloading.dart'; +import '../services/other_function.dart'; final locator = StackedLocator.instance; @@ -32,4 +34,6 @@ Future setupLocator({ locator.registerLazySingleton(() => BottomSheetService()); locator.registerLazySingleton(() => MyEasyLoading()); locator.registerLazySingleton(() => MyHttpServices()); + locator.registerLazySingleton(() => OtherFunction()); + locator.registerLazySingleton(() => GlobalVar()); } diff --git a/lib/app/core/custom_base_view_model.dart b/lib/app/core/custom_base_view_model.dart index 16e7b40..4b401ab 100755 --- a/lib/app/core/custom_base_view_model.dart +++ b/lib/app/core/custom_base_view_model.dart @@ -3,8 +3,10 @@ import 'package:flutter/services.dart'; import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; +import '../../services/global_var.dart'; import '../../services/http_services.dart'; import '../../services/my_easyloading.dart'; +import '../../services/other_function.dart'; import '../app.locator.dart'; import '../themes/app_colors.dart'; @@ -15,6 +17,8 @@ class CustomBaseViewModel extends BaseViewModel { final snackbarService = locator(); final easyLoading = locator(); final httpService = locator(); + final otherFunction = locator(); + final globalVar = locator(); // late bool backPressed; diff --git a/lib/main.dart b/lib/main.dart index 3c48071..1c17cd2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -21,7 +21,7 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Panti Asuhan Aisyiyah Abadi', + title: 'Reza Restaurant App', theme: appTheme, debugShowCheckedModeBanner: false, navigatorKey: StackedService.navigatorKey, diff --git a/lib/services/global_var.dart b/lib/services/global_var.dart new file mode 100644 index 0000000..483a46f --- /dev/null +++ b/lib/services/global_var.dart @@ -0,0 +1,3 @@ +class GlobalVar { + String backPressed = 'backNormal'; +} diff --git a/lib/services/my_easyloading.dart b/lib/services/my_easyloading.dart index c1eb253..46cb062 100644 --- a/lib/services/my_easyloading.dart +++ b/lib/services/my_easyloading.dart @@ -1,8 +1,6 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; class MyEasyLoading { - int backPressed = 1; - showLoading() { EasyLoading.show( status: 'loading...', diff --git a/lib/ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_view.dart b/lib/ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_view.dart index a7335ae..4fc8366 100644 --- a/lib/ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_view.dart +++ b/lib/ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_view.dart @@ -40,7 +40,7 @@ class InputInformasiDiriView extends StatelessWidget { ), body: WillPopScope( onWillPop: () async { - if (model.easyLoading.backPressed == 1) { + if (model.globalVar.backPressed == 'backNormal') { model.navigationService.navigateToMasukanNoHpView(); } return false; diff --git a/lib/ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_view_model.dart b/lib/ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_view_model.dart index d567933..3935a18 100644 --- a/lib/ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_view_model.dart +++ b/lib/ui/views/daftar_user_ui/input_informasi_diri/input_informasi_diri_view_model.dart @@ -33,13 +33,13 @@ class InputInformasiDiriViewModel extends CustomBaseViewModel { } goToLogin() async { - easyLoading.backPressed = 0; + globalVar.backPressed = 'cantBack'; easyLoading.customLoading("Mendaftarkan Akun Anda"); await Future.delayed(const Duration(seconds: 2)); easyLoading.customLoading("Ke Halaman Login"); await Future.delayed(const Duration(seconds: 2)); easyLoading.dismissLoading(); - easyLoading.backPressed = 1; + globalVar.backPressed = 'backNormal'; notifyListeners(); await navigationService.navigateToLoginUserView(); } diff --git a/lib/ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view.dart b/lib/ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view.dart index 09b0c57..1939839 100644 --- a/lib/ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view.dart +++ b/lib/ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view.dart @@ -36,7 +36,7 @@ class MasukanNoHpView extends StatelessWidget { ), body: WillPopScope( onWillPop: () async { - if (model.easyLoading.backPressed == 1) { + if (model.globalVar.backPressed == 'backNormal') { model.navigationService.navigateToLoginUserView(); } return false; diff --git a/lib/ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view_model.dart b/lib/ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view_model.dart index 663397b..d63d23d 100644 --- a/lib/ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view_model.dart +++ b/lib/ui/views/daftar_user_ui/masukan_no_hp/masukan_no_hp_view_model.dart @@ -16,9 +16,9 @@ class MasukanNoHpViewModel extends CustomBaseViewModel { selanjutnya() async { _easyloading.customLoading("Menghantar Kode OTP \nke WhatsApp Anda"); - easyLoading.backPressed = 0; + globalVar.backPressed = 'cantBack'; await Future.delayed(const Duration(seconds: 3)); - easyLoading.backPressed = 1; + globalVar.backPressed = 'backNormal'; notifyListeners(); _easyloading.dismissLoading(); await navigationService.navigateToVerifikasiNoHpView(); diff --git a/lib/ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view.dart b/lib/ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view.dart index b313885..f1f6eb8 100644 --- a/lib/ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view.dart +++ b/lib/ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view.dart @@ -36,7 +36,7 @@ class VerifikasiNoHpView extends StatelessWidget { ), body: WillPopScope( onWillPop: () async { - if (model.easyLoading.backPressed == 1) { + if (model.globalVar.backPressed == 'backNormal') { model.back(); } return false; diff --git a/lib/ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view_model.dart b/lib/ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view_model.dart index 37f598c..42ac107 100644 --- a/lib/ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view_model.dart +++ b/lib/ui/views/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view_model.dart @@ -9,11 +9,11 @@ class VerifikasiNoHpViewModel extends CustomBaseViewModel { Future init() async {} goToInputInformasiDiri() async { - easyLoading.backPressed = 0; + globalVar.backPressed = 'cantBack'; easyLoading.customLoading("Ke Halaman Input Informasi Diri"); await Future.delayed(const Duration(seconds: 3)); easyLoading.dismissLoading(); - easyLoading.backPressed = 1; + globalVar.backPressed = 'backNormal'; notifyListeners(); await navigationService.navigateToInputInformasiDiriView( noHp: "082293246583", diff --git a/lib/ui/views/login_user/login_user_view.dart b/lib/ui/views/login_user/login_user_view.dart index aaa3c96..aa1f16e 100644 --- a/lib/ui/views/login_user/login_user_view.dart +++ b/lib/ui/views/login_user/login_user_view.dart @@ -23,7 +23,7 @@ class LoginUserView extends StatelessWidget { return Scaffold( body: WillPopScope( onWillPop: () async { - if (model.easyLoading.backPressed == 1) { + if (model.globalVar.backPressed == 'backNormal') { // model.back(); model.quitApp(context); } diff --git a/lib/ui/views/login_user/login_user_view_model.dart b/lib/ui/views/login_user/login_user_view_model.dart index 91a9c16..6f61941 100644 --- a/lib/ui/views/login_user/login_user_view_model.dart +++ b/lib/ui/views/login_user/login_user_view_model.dart @@ -17,12 +17,12 @@ class LoginUserViewModel extends CustomBaseViewModel { login() async { setBusy(true); - easyLoading.backPressed = 0; + globalVar.backPressed = 'cantBack'; easyLoading.showLoading(); await Future.delayed(const Duration(seconds: 5)); easyLoading.dismissLoading(); setBusy(false); - easyLoading.backPressed = 1; + globalVar.backPressed = 'backNormal'; notifyListeners(); await navigationService.navigateToUserIndexTrackingView(); } diff --git a/lib/ui/views/meja_detail/meja_detail_view.dart b/lib/ui/views/meja_detail/meja_detail_view.dart index 28ad637..c5efc0a 100644 --- a/lib/ui/views/meja_detail/meja_detail_view.dart +++ b/lib/ui/views/meja_detail/meja_detail_view.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:reza_app/app/app.router.dart'; import 'package:reza_app/app/themes/app_colors.dart'; import 'package:reza_app/app/themes/app_text.dart'; import 'package:stacked/stacked.dart'; @@ -26,119 +25,136 @@ class MejaDetailView extends StatelessWidget { MejaDetailViewModel model, Widget? child, ) { - return Scaffold( - appBar: AppBar( - title: const Text('MejaDetailView', - style: TextStyle(color: Colors.white)), - backgroundColor: mainColor, - leading: IconButton( - onPressed: () => model.navigationService.popUntil((route) => - route.settings.name == Routes.userIndexTrackingView), - icon: const Icon(Icons.arrow_back, color: Colors.white), + return WillPopScope( + onWillPop: () async { + if (model.globalVar.backPressed == 'backNormal') { + model.globalVar.backPressed = 'exitApp'; + return true; + } + // model.quitApp(context); + + return false; + }, + child: Scaffold( + appBar: AppBar( + title: const Text('MejaDetailView', + style: TextStyle(color: Colors.white)), + backgroundColor: mainColor, + leading: IconButton( + onPressed: () { + if (model.globalVar.backPressed == 'backNormal') { + model.globalVar.backPressed = 'exitApp'; + model.navigationService.back(); + // return true; + } + }, + icon: const Icon(Icons.arrow_back, color: Colors.white), + ), ), - ), - body: Padding( - padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - height: 250, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20), + body: Padding( + padding: + const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + height: 250, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(20), + child: model.imgAsset == null + ? const Center(child: CircularProgressIndicator()) + : Image.asset(model.imgAsset!, fit: BoxFit.cover), + ), ), - child: ClipRRect( - borderRadius: BorderRadius.circular(20), - child: model.imgAsset == null - ? const Center(child: CircularProgressIndicator()) - : Image.asset(model.imgAsset!, fit: BoxFit.cover), + const SizedBox(height: 5), + Text( + model.namaMeja, + style: const TextStyle( + fontSize: 20, + // fontWeight: FontWeight.bold, + ), ), - ), - const SizedBox(height: 5), - Text( - model.namaMeja, - style: const TextStyle( - fontSize: 20, - // fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 10), - RichText( - text: TextSpan( - text: 'Status : ', - style: regularTextStyle, - children: [ - TextSpan( - text: 'Tersedia', - style: regularTextStyle.copyWith( - color: Colors.green, - fontWeight: FontWeight.bold, + const SizedBox(height: 10), + RichText( + text: TextSpan( + text: 'Status : ', + style: regularTextStyle, + children: [ + TextSpan( + text: 'Tersedia', + style: regularTextStyle.copyWith( + color: Colors.green, + fontWeight: FontWeight.bold, + ), ), - ), - ], + ], + ), ), - ), - const SizedBox(height: 10), - RichText( - text: TextSpan( - text: 'Kapasitas : ', - style: regularTextStyle, - children: [ - TextSpan( - text: 'Maksimal 8 Orang', - style: regularTextStyle.copyWith( - color: Colors.green, - fontWeight: FontWeight.bold, + const SizedBox(height: 10), + RichText( + text: TextSpan( + text: 'Kapasitas : ', + style: regularTextStyle, + children: [ + TextSpan( + text: 'Maksimal 8 Orang', + style: regularTextStyle.copyWith( + color: Colors.green, + fontWeight: FontWeight.bold, + ), ), - ), - ], + ], + ), ), - ), - const SizedBox(height: 10), - RichText( - text: TextSpan( - text: 'Lokasi : ', - style: regularTextStyle, - children: [ - TextSpan( - text: 'Luar Ruangan', - style: regularTextStyle.copyWith( - color: Colors.green, - fontWeight: FontWeight.bold, + const SizedBox(height: 10), + RichText( + text: TextSpan( + text: 'Lokasi : ', + style: regularTextStyle, + children: [ + TextSpan( + text: 'Luar Ruangan', + style: regularTextStyle.copyWith( + color: Colors.green, + fontWeight: FontWeight.bold, + ), ), - ), - ], + ], + ), ), - ), - const SizedBox(height: 10), - RichText( - text: TextSpan( - text: 'Harga : ', - style: regularTextStyle, - children: [ - TextSpan( - text: 'Rp. 20.000', - style: regularTextStyle.copyWith( - color: Colors.orange, - fontWeight: FontWeight.bold, + const SizedBox(height: 10), + RichText( + text: TextSpan( + text: 'Harga : ', + style: regularTextStyle, + children: [ + TextSpan( + text: 'Rp. 20.000', + style: regularTextStyle.copyWith( + color: Colors.orange, + fontWeight: FontWeight.bold, + ), ), - ), - ], + ], + ), ), - ), - ], + ], + ), ), + floatingActionButton: FloatingActionButton.extended( + onPressed: () {}, + label: const Text('Pesan'), + icon: const Icon(Icons.add_shopping_cart), + backgroundColor: mainColor, + ), + floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling, + floatingActionButtonLocation: + FloatingActionButtonLocation.centerFloat, ), - floatingActionButton: FloatingActionButton.extended( - onPressed: () {}, - label: const Text('Pesan'), - icon: const Icon(Icons.add_shopping_cart), - backgroundColor: mainColor, - ), - floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling, - floatingActionButtonLocation: - FloatingActionButtonLocation.centerFloat, ); }, ); diff --git a/lib/ui/views/meja_detail/meja_detail_view_model.dart b/lib/ui/views/meja_detail/meja_detail_view_model.dart index bce3c3b..6c87c92 100644 --- a/lib/ui/views/meja_detail/meja_detail_view_model.dart +++ b/lib/ui/views/meja_detail/meja_detail_view_model.dart @@ -13,7 +13,7 @@ class MejaDetailViewModel extends CustomBaseViewModel { log.i('MejaDetailViewModel init'); log.i('mejaId : $mejaId'); this.mejaId = mejaId; - easyLoading.backPressed = 3; + globalVar.backPressed = 'backNormal'; // seperate the number from the string var number = int.parse(mejaId.replaceAll(RegExp(r'[^0-9]'), '')); // log.i('number : $number'); diff --git a/lib/ui/views/user_ui/akun_user/akun_user_view.dart b/lib/ui/views/user_ui/akun_user/akun_user_view.dart index d21e99f..742da50 100644 --- a/lib/ui/views/user_ui/akun_user/akun_user_view.dart +++ b/lib/ui/views/user_ui/akun_user/akun_user_view.dart @@ -20,111 +20,122 @@ class AkunUserView extends StatelessWidget { AkunUserViewModel model, Widget? child, ) { - return Scaffold( - appBar: AppBar( - title: Text( - 'Akun Saya', - style: boldTextStyle.copyWith(color: fontGrey, fontSize: 16), - ), - // transparent - backgroundColor: Colors.transparent, - automaticallyImplyLeading: false, - actions: [ - IconButton( - onPressed: () {}, - icon: const Icon( - Icons.logout_outlined, - color: fontGrey, - ), + return WillPopScope( + onWillPop: () async { + // model.log.i('onWillPop di akun_user_view.dart'); + if (model.globalVar.backPressed == 'exitApp') { + model.quitApp(context); + model.globalVar.backPressed = 'exitApp'; + return false; + } + return false; + }, + child: Scaffold( + appBar: AppBar( + title: Text( + 'Akun Saya', + style: boldTextStyle.copyWith(color: fontGrey, fontSize: 16), ), - ], - ), - backgroundColor: backgroundColor, - body: Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox(height: 20), - // create a circle avatar 150x150 that contain the image - Center( - child: ClipRRect( - borderRadius: BorderRadius.circular(150), - child: Image.network( - 'https://a.cdn-hotels.com/gdcs/production0/d1513/35c1c89e-408c-4449-9abe-f109068f40c0.jpg?impolicy=fcrop&w=800&h=533&q=medium', - height: 150, - width: 150, - fit: BoxFit.fill, - errorBuilder: (context, error, stackTrace) { - return const Icon(Icons.error); - }, - ), + // transparent + backgroundColor: Colors.transparent, + automaticallyImplyLeading: false, + actions: [ + IconButton( + onPressed: () {}, + icon: const Icon( + Icons.logout_outlined, + color: fontGrey, ), ), - const SizedBox(height: 10), - Row( - children: [ - const Text('Nama'), - const Expanded(child: SizedBox(width: 10)), - Text( - 'Reza', - style: regularTextStyle.copyWith( - color: fontGrey, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(width: 10), - const Icon( - Icons.arrow_forward_ios, - color: fontGrey, - size: 15, - ), - ], - ), - const SizedBox(height: 20), - Row( - children: [ - const Text('Jenis Kelamin'), - const Expanded(child: SizedBox(width: 10)), - Text( - 'Laki-laki', - style: regularTextStyle.copyWith( - color: fontGrey, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(width: 10), - const Icon( - Icons.arrow_forward_ios, - color: fontGrey, - size: 15, - ), - ], - ), - const SizedBox(height: 20), - Row( - children: [ - const Text('Tanggal Lahir'), - const Expanded(child: SizedBox(width: 10)), - Text( - '12-12-1999', - style: regularTextStyle.copyWith( - color: fontGrey, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(width: 10), - const Icon( - Icons.arrow_forward_ios, - color: fontGrey, - size: 15, - ), - ], - ), ], ), + backgroundColor: backgroundColor, + body: Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 20), + // create a circle avatar 150x150 that contain the image + Center( + child: ClipRRect( + borderRadius: BorderRadius.circular(150), + child: Image.network( + 'https://a.cdn-hotels.com/gdcs/production0/d1513/35c1c89e-408c-4449-9abe-f109068f40c0.jpg?impolicy=fcrop&w=800&h=533&q=medium', + height: 150, + width: 150, + fit: BoxFit.fill, + errorBuilder: (context, error, stackTrace) { + return const Icon(Icons.error); + }, + ), + ), + ), + const SizedBox(height: 10), + Row( + children: [ + const Text('Nama'), + const Expanded(child: SizedBox(width: 10)), + Text( + 'Reza', + style: regularTextStyle.copyWith( + color: fontGrey, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(width: 10), + const Icon( + Icons.arrow_forward_ios, + color: fontGrey, + size: 15, + ), + ], + ), + const SizedBox(height: 20), + Row( + children: [ + const Text('Jenis Kelamin'), + const Expanded(child: SizedBox(width: 10)), + Text( + 'Laki-laki', + style: regularTextStyle.copyWith( + color: fontGrey, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(width: 10), + const Icon( + Icons.arrow_forward_ios, + color: fontGrey, + size: 15, + ), + ], + ), + const SizedBox(height: 20), + Row( + children: [ + const Text('Tanggal Lahir'), + const Expanded(child: SizedBox(width: 10)), + Text( + '12-12-1999', + style: regularTextStyle.copyWith( + color: fontGrey, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(width: 10), + const Icon( + Icons.arrow_forward_ios, + color: fontGrey, + size: 15, + ), + ], + ), + ], + ), + ), ), ); }, diff --git a/lib/ui/views/user_ui/akun_user/akun_user_view_model.dart b/lib/ui/views/user_ui/akun_user/akun_user_view_model.dart index 3005729..e106ce8 100644 --- a/lib/ui/views/user_ui/akun_user/akun_user_view_model.dart +++ b/lib/ui/views/user_ui/akun_user/akun_user_view_model.dart @@ -2,6 +2,6 @@ import 'package:reza_app/app/core/custom_base_view_model.dart'; class AkunUserViewModel extends CustomBaseViewModel { Future init() async { - easyLoading.backPressed = 2; + globalVar.backPressed = 'exitApp'; } } diff --git a/lib/ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view.dart b/lib/ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view.dart index ef28730..86bae22 100644 --- a/lib/ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view.dart +++ b/lib/ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view.dart @@ -28,7 +28,17 @@ class DetailMakananView extends HookWidget { DetailMakananViewModel model, Widget? child, ) { - return Scaffold( + return WillPopScope( + onWillPop: () async { + // model.log.i('onWillPop di reservasi_meja_view.dart'); + // if (model.globalVar.backPressed == 'exitApp') { + model.globalVar.backPressed = 'exitApp'; + model.back(); + return false; + // } + // return false; + }, + child: Scaffold( backgroundColor: backgroundColor, body: SizedBox( width: MediaQuery.of(context).size.width, @@ -203,7 +213,9 @@ class DetailMakananView extends HookWidget { ), ], ), - )); + ), + ), + ); }, ); } @@ -257,6 +269,7 @@ class TopBarWidget extends ViewModelWidget { ), child: IconButton( onPressed: () { + viewModel.globalVar.backPressed = 'exitApp'; viewModel.back(); }, icon: const Icon( diff --git a/lib/ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view_model.dart b/lib/ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view_model.dart index 51f212d..d49cd4b 100644 --- a/lib/ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view_model.dart +++ b/lib/ui/views/user_ui/makanan_list/detail_makanan/detail_makanan_view_model.dart @@ -5,6 +5,6 @@ class DetailMakananViewModel extends CustomBaseViewModel { final log = getLogger('DetailMakananViewModel'); Future init() async { - easyLoading.backPressed = 3; + globalVar.backPressed = 'backNormal'; } } diff --git a/lib/ui/views/user_ui/makanan_list/makanan_list_view.dart b/lib/ui/views/user_ui/makanan_list/makanan_list_view.dart index 2661c4b..e3d4f7f 100644 --- a/lib/ui/views/user_ui/makanan_list/makanan_list_view.dart +++ b/lib/ui/views/user_ui/makanan_list/makanan_list_view.dart @@ -21,7 +21,17 @@ class MakananListView extends StatelessWidget { MakananListViewModel model, Widget? child, ) { - return Scaffold( + return WillPopScope( + onWillPop: () async { + // model.log.i('onWillPop di reservasi_meja_view.dart'); + if (model.globalVar.backPressed == 'exitApp') { + model.quitApp(context); + model.globalVar.backPressed = 'exitApp'; + return false; + } + return false; + }, + child: Scaffold( backgroundColor: backgroundColor, body: Column( mainAxisAlignment: MainAxisAlignment.start, @@ -38,7 +48,14 @@ class MakananListView extends StatelessWidget { Expanded( flex: 2, child: IconButton( - onPressed: () => model.back(), + onPressed: () { + if (model.globalVar.backPressed == 'exitApp') { + model.quitApp(context); + model.globalVar.backPressed = 'exitApp'; + } else { + model.navigationService.back(); + } + }, icon: const Icon(Icons.arrow_back), ), ), @@ -230,7 +247,9 @@ class MakananListView extends StatelessWidget { ], ), ), - )); + ), + ), + ); }, ); } diff --git a/lib/ui/views/user_ui/makanan_list/makanan_list_view_model.dart b/lib/ui/views/user_ui/makanan_list/makanan_list_view_model.dart index 0cd330d..7c11af3 100644 --- a/lib/ui/views/user_ui/makanan_list/makanan_list_view_model.dart +++ b/lib/ui/views/user_ui/makanan_list/makanan_list_view_model.dart @@ -5,7 +5,7 @@ import '../../../../app/core/custom_base_view_model.dart'; class MakananListViewModel extends CustomBaseViewModel { final log = getLogger('MakananListViewModel'); Future init() async { - easyLoading.backPressed = 2; + globalVar.backPressed = 'exitApp'; } goToDetailMakanan() { diff --git a/lib/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view.dart b/lib/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view.dart index 3338823..ee32c5d 100644 --- a/lib/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view.dart +++ b/lib/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view.dart @@ -21,151 +21,164 @@ class KeranjangSayaView extends StatelessWidget { KeranjangSayaViewModel model, Widget? child, ) { - return Scaffold( - appBar: AppBar( - title: const Text('Keranjang Saya', - style: TextStyle(color: Colors.white)), - backgroundColor: mainColor, - iconTheme: const IconThemeData(color: Colors.white), - ), - body: Column( - children: [ - const SizedBox(height: 15), - Expanded( - child: ListView.builder( - itemCount: 10, - shrinkWrap: true, - itemBuilder: (context, index) { - return Padding( - padding: const EdgeInsets.only(bottom: 10), - child: MyWhiteContainer( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - // create a checkbox - Checkbox( - // check if the value is true or false - value: false, - // if true change the value to false - onChanged: (bool? value) { - // model.changeIsCheck(value!); - }, - ), - const SizedBox(width: 10), - // create a container 100x100 that contain the image - Container( - width: 100, - height: 100, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), + return WillPopScope( + onWillPop: () async { + // model.log.i('onWillPop di reservasi_meja_view.dart'); + if (model.globalVar.backPressed == 'backNormal') { + // model.quitApp(context); + model.globalVar.backPressed = 'exitApp'; + return true; + } + return false; + }, + child: Scaffold( + appBar: AppBar( + title: const Text('Keranjang Saya', + style: TextStyle(color: Colors.white)), + backgroundColor: mainColor, + iconTheme: const IconThemeData(color: Colors.white), + ), + body: Column( + children: [ + const SizedBox(height: 15), + Expanded( + child: ListView.builder( + itemCount: 10, + shrinkWrap: true, + itemBuilder: (context, index) { + return Padding( + padding: const EdgeInsets.only(bottom: 10), + child: MyWhiteContainer( + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + // create a checkbox + Checkbox( + // check if the value is true or false + value: false, + // if true change the value to false + onChanged: (bool? value) { + // model.changeIsCheck(value!); + }, ), - child: ClipRRect( - borderRadius: BorderRadius.circular(10), - child: Image.network( - 'https://a.cdn-hotels.com/gdcs/production0/d1513/35c1c89e-408c-4449-9abe-f109068f40c0.jpg?impolicy=fcrop&w=800&h=533&q=medium', - height: 150, - width: double.infinity, - fit: BoxFit.fill, - errorBuilder: (context, error, stackTrace) { - return const Icon(Icons.error); - }, + const SizedBox(width: 10), + // create a container 100x100 that contain the image + Container( + width: 100, + height: 100, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(10), + child: Image.network( + 'https://a.cdn-hotels.com/gdcs/production0/d1513/35c1c89e-408c-4449-9abe-f109068f40c0.jpg?impolicy=fcrop&w=800&h=533&q=medium', + height: 150, + width: double.infinity, + fit: BoxFit.fill, + errorBuilder: + (context, error, stackTrace) { + return const Icon(Icons.error); + }, + ), ), ), - ), - const SizedBox(width: 10), - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text( - 'Product Name ', - style: regularTextStyle.copyWith( - fontSize: 16), - overflow: TextOverflow.ellipsis, - ), - const SizedBox(height: 5), - Text( - 'Rp. 100.000', - style: boldTextStyle.copyWith( - color: redColor), - ), - const SizedBox(height: 5), - // create a row that contain minus button, value, and plus button - Row( - mainAxisAlignment: - MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - // create a button minus - GestureDetector( - onTap: () {}, - child: Container( - width: 25, - height: 25, - decoration: BoxDecoration( - borderRadius: - BorderRadius.circular(5), - color: stockColor, - ), - child: const Icon( - Icons.remove, - color: mainGrey, + const SizedBox(width: 10), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Product Name ', + style: regularTextStyle.copyWith( + fontSize: 16), + overflow: TextOverflow.ellipsis, + ), + const SizedBox(height: 5), + Text( + 'Rp. 100.000', + style: boldTextStyle.copyWith( + color: redColor), + ), + const SizedBox(height: 5), + // create a row that contain minus button, value, and plus button + Row( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + // create a button minus + GestureDetector( + onTap: () {}, + child: Container( + width: 25, + height: 25, + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(5), + color: stockColor, + ), + child: const Icon( + Icons.remove, + color: mainGrey, + ), ), ), - ), - const SizedBox(width: 10), - // create a text that contain value - Text( - '1', - style: regularTextStyle.copyWith( - fontSize: 16, - ), - ), - const SizedBox(width: 10), - // create a button plus - GestureDetector( - onTap: () {}, - child: Container( - width: 25, - height: 25, - decoration: BoxDecoration( - borderRadius: - BorderRadius.circular(5), - color: stockColor, - ), - child: const Icon( - Icons.add, - color: mainGrey, + const SizedBox(width: 10), + // create a text that contain value + Text( + '1', + style: regularTextStyle.copyWith( + fontSize: 16, ), ), - ), - ], - ), - ], + const SizedBox(width: 10), + // create a button plus + GestureDetector( + onTap: () {}, + child: Container( + width: 25, + height: 25, + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(5), + color: stockColor, + ), + child: const Icon( + Icons.add, + color: mainGrey, + ), + ), + ), + ], + ), + ], + ), ), - ), - ], + ], + ), ), - ), - ); - }, + ); + }, + ), ), - ), - const SizedBox(height: 15), - ], - ), - floatingActionButton: FloatingActionButton( - onPressed: () {}, - // create a shopping cart icon with a badge containing the number of items - child: const Icon( - Icons.shopping_cart_outlined, - color: Colors.white, + const SizedBox(height: 15), + ], ), - )); + floatingActionButton: FloatingActionButton( + onPressed: () {}, + // create a shopping cart icon with a badge containing the number of items + child: const Icon( + Icons.shopping_cart_outlined, + color: Colors.white, + ), + )), + ); }, ); } diff --git a/lib/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view_model.dart b/lib/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view_model.dart index 9150cef..7034283 100644 --- a/lib/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view_model.dart +++ b/lib/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view_model.dart @@ -5,6 +5,6 @@ import '../../../../../app/app.logger.dart'; class KeranjangSayaViewModel extends CustomBaseViewModel { final log = getLogger('KeranjangSayaViewModel'); Future init() async { - easyLoading.backPressed = 3; + globalVar.backPressed = 'backNormal'; } } diff --git a/lib/ui/views/user_ui/pesanan_list/pesanan_list_view.dart b/lib/ui/views/user_ui/pesanan_list/pesanan_list_view.dart index 15abd6e..78f2ef3 100644 --- a/lib/ui/views/user_ui/pesanan_list/pesanan_list_view.dart +++ b/lib/ui/views/user_ui/pesanan_list/pesanan_list_view.dart @@ -22,93 +22,54 @@ class PesananListView extends StatelessWidget { PesananListViewModel model, Widget? child, ) { - return Scaffold( - appBar: AppBar( - title: Text( - 'List Pesanan', - style: boldTextStyle.copyWith(color: Colors.white), - ), - backgroundColor: mainColor, - automaticallyImplyLeading: false, - actions: [ - // create a shopping cart icon with a badge containing the number of items - Container( - margin: const EdgeInsets.only(right: 10), - child: Stack( - children: [ - IconButton( - onPressed: () { - model.navigationService.navigateToKeranjangSayaView(); - }, - icon: const Icon(Icons.shopping_cart_outlined, - color: Colors.white), - ), - Positioned( - top: 5, - right: 5, - child: Container( - width: 20, - height: 20, - decoration: const BoxDecoration( - color: Colors.red, - shape: BoxShape.circle, - ), - child: const Center( - child: Text( - '9', - style: TextStyle( - color: Colors.white, - fontSize: 12, - ), - ), - ), - ), - ), - ], - ), + return WillPopScope( + onWillPop: () async { + // model.log.i('onWillPop di reservasi_meja_view.dart'); + if (model.globalVar.backPressed == 'exitApp') { + model.quitApp(context); + model.globalVar.backPressed = 'exitApp'; + return false; + } + return false; + }, + child: Scaffold( + appBar: AppBar( + title: Text( + 'List Pesanan', + style: boldTextStyle.copyWith(color: Colors.white), ), - ], - ), - backgroundColor: backgroundColor, - body: Column( - children: [ - MyWhiteContainer( - child: IntrinsicHeight( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, + backgroundColor: mainColor, + automaticallyImplyLeading: false, + actions: [ + // create a shopping cart icon with a badge containing the number of items + Container( + margin: const EdgeInsets.only(right: 10), + child: Stack( children: [ - Expanded( - child: TextButton( - onPressed: () {}, - child: const Text('Dikemas'), - ), + IconButton( + onPressed: () { + model.navigationService.navigateToKeranjangSayaView(); + }, + icon: const Icon(Icons.shopping_cart_outlined, + color: Colors.white), ), - const VerticalDivider( - color: mainGrey, - thickness: 1, - ), - Expanded( - child: TextButton( - onPressed: () {}, - child: const Text( - 'Dikirim', - style: TextStyle( - color: mainGrey, - ), + Positioned( + top: 5, + right: 5, + child: Container( + width: 20, + height: 20, + decoration: const BoxDecoration( + color: Colors.red, + shape: BoxShape.circle, ), - ), - ), - const VerticalDivider( - color: Colors.grey, - thickness: 1, - ), - Expanded( - child: TextButton( - onPressed: () {}, - child: const Text( - 'Selesai', - style: TextStyle( - color: mainGrey, + child: const Center( + child: Text( + '9', + style: TextStyle( + color: Colors.white, + fontSize: 12, + ), ), ), ), @@ -116,193 +77,246 @@ class PesananListView extends StatelessWidget { ], ), ), - ), - const SizedBox( - height: 15, - ), - Expanded( - child: ListView.builder( - shrinkWrap: true, - itemCount: 10, - itemBuilder: (context, index) { - return Padding( - padding: const EdgeInsets.only(bottom: 10), - child: MyWhiteContainer( - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 20, + ], + ), + backgroundColor: backgroundColor, + body: Column( + children: [ + MyWhiteContainer( + child: IntrinsicHeight( + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + child: TextButton( + onPressed: () {}, + child: const Text('Dikemas'), ), - child: Column( - children: [ - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - width: 100, - height: 100, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - ), - child: ClipRRect( - borderRadius: BorderRadius.circular(10), - child: Image.network( - 'https://a.cdn-hotels.com/gdcs/production0/d1513/35c1c89e-408c-4449-9abe-f109068f40c0.jpg?impolicy=fcrop&w=800&h=533&q=medium', - height: 100, - width: double.infinity, - fit: BoxFit.fill, - errorBuilder: - (context, error, stackTrace) { - return const Icon(Icons.error); - }, + ), + const VerticalDivider( + color: mainGrey, + thickness: 1, + ), + Expanded( + child: TextButton( + onPressed: () {}, + child: const Text( + 'Dikirim', + style: TextStyle( + color: mainGrey, + ), + ), + ), + ), + const VerticalDivider( + color: Colors.grey, + thickness: 1, + ), + Expanded( + child: TextButton( + onPressed: () {}, + child: const Text( + 'Selesai', + style: TextStyle( + color: mainGrey, + ), + ), + ), + ), + ], + ), + ), + ), + const SizedBox( + height: 15, + ), + Expanded( + child: ListView.builder( + shrinkWrap: true, + itemCount: 10, + itemBuilder: (context, index) { + return Padding( + padding: const EdgeInsets.only(bottom: 10), + child: MyWhiteContainer( + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 20, + ), + child: Column( + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 100, + height: 100, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(10), + child: Image.network( + 'https://a.cdn-hotels.com/gdcs/production0/d1513/35c1c89e-408c-4449-9abe-f109068f40c0.jpg?impolicy=fcrop&w=800&h=533&q=medium', + height: 100, + width: double.infinity, + fit: BoxFit.fill, + errorBuilder: + (context, error, stackTrace) { + return const Icon(Icons.error); + }, + ), ), ), + const SizedBox( + width: 20, + ), + Expanded( + child: IntrinsicHeight( + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + child: Text( + 'Nama Makanan', + style: + regularTextStyle.copyWith( + fontSize: 17, + ), + overflow: TextOverflow.ellipsis, + ), + ), + const SizedBox( + height: 5, + ), + Align( + alignment: Alignment.centerRight, + child: Text( + 'x 1', + style: + regularTextStyle.copyWith( + color: mainGrey, + fontSize: 17, + ), + ), + ), + const SizedBox( + height: 5, + ), + Align( + alignment: Alignment.centerRight, + child: Text( + 'Rp. 100.000', + style: + regularTextStyle.copyWith( + color: redColor, + fontSize: 17, + ), + ), + ), + ], + ), + ), + ) + ], + ), + const SizedBox( + height: 10, + ), + Center( + child: Text( + 'Tampilkan Produk Lain', + style: regularTextStyle.copyWith( + color: mainGrey, + ), ), - const SizedBox( - width: 20, - ), - Expanded( - child: IntrinsicHeight( - child: Column( - mainAxisAlignment: - MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.start, + ), + const SizedBox( + height: 10, + ), + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + const Text( + '3 Item', + style: regularTextStyle, + ), + const Expanded(child: SizedBox()), + RichText( + text: TextSpan( + text: 'Total Pesanan: ', + style: regularTextStyle, children: [ - Expanded( - child: Text( - 'Nama Makanan', - style: regularTextStyle.copyWith( - fontSize: 17, - ), - overflow: TextOverflow.ellipsis, - ), - ), - const SizedBox( - height: 5, - ), - Align( - alignment: Alignment.centerRight, - child: Text( - 'x 1', - style: regularTextStyle.copyWith( - color: mainGrey, - fontSize: 17, - ), - ), - ), - const SizedBox( - height: 5, - ), - Align( - alignment: Alignment.centerRight, - child: Text( - 'Rp. 100.000', - style: regularTextStyle.copyWith( - color: redColor, - fontSize: 17, - ), + TextSpan( + text: 'Rp. 300.000', + style: regularTextStyle.copyWith( + color: redColor, + fontWeight: FontWeight.bold, ), ), ], ), ), - ) - ], - ), - const SizedBox( - height: 10, - ), - Center( - child: Text( - 'Tampilkan Produk Lain', - style: regularTextStyle.copyWith( - color: mainGrey, - ), + ], ), - ), - const SizedBox( - height: 10, - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - const Text( - '3 Item', - style: regularTextStyle, - ), - const Expanded(child: SizedBox()), - RichText( - text: TextSpan( - text: 'Total Pesanan: ', - style: regularTextStyle, - children: [ - TextSpan( - text: 'Rp. 300.000', - style: regularTextStyle.copyWith( - color: redColor, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - ], - ), - const SizedBox( - height: 15, - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - // lorry icon - const Icon( - Icons.local_shipping_outlined, - color: mainColor, - ), - const SizedBox( - width: 5, - ), - Text( - 'Pesanan telah sampai', - style: regularTextStyle.copyWith( + const SizedBox( + height: 15, + ), + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + // lorry icon + const Icon( + Icons.local_shipping_outlined, color: mainColor, ), - ), + const SizedBox( + width: 5, + ), + Text( + 'Pesanan telah sampai', + style: regularTextStyle.copyWith( + color: mainColor, + ), + ), - const Expanded(child: SizedBox()), - const Icon( - Icons.arrow_forward_ios, - color: mainGrey, - size: 15, - ), - ], - ), - ], + const Expanded(child: SizedBox()), + const Icon( + Icons.arrow_forward_ios, + color: mainGrey, + size: 15, + ), + ], + ), + ], + ), ), ), - ), - ); - }, + ); + }, + ), ), - ), - ], + ], + ), + // floatingActionButton: FloatingActionButton.extended( + // onPressed: () {}, + // label: Text( + // 'Pesan', + // style: boldTextStyle.copyWith(color: Colors.white), + // ), + // icon: const Icon( + // Icons.shopping_cart, + // color: Colors.white, + // ), + // backgroundColor: mainColor, + // ), ), - // floatingActionButton: FloatingActionButton.extended( - // onPressed: () {}, - // label: Text( - // 'Pesan', - // style: boldTextStyle.copyWith(color: Colors.white), - // ), - // icon: const Icon( - // Icons.shopping_cart, - // color: Colors.white, - // ), - // backgroundColor: mainColor, - // ), ); }, ); diff --git a/lib/ui/views/user_ui/pesanan_list/pesanan_list_view_model.dart b/lib/ui/views/user_ui/pesanan_list/pesanan_list_view_model.dart index 5d9df0f..458803d 100644 --- a/lib/ui/views/user_ui/pesanan_list/pesanan_list_view_model.dart +++ b/lib/ui/views/user_ui/pesanan_list/pesanan_list_view_model.dart @@ -2,6 +2,6 @@ import 'package:reza_app/app/core/custom_base_view_model.dart'; class PesananListViewModel extends CustomBaseViewModel { Future init() async { - easyLoading.backPressed = 2; + globalVar.backPressed = 'exitApp'; } } diff --git a/lib/ui/views/user_ui/reservasi_meja/reservasi_meja_view.dart b/lib/ui/views/user_ui/reservasi_meja/reservasi_meja_view.dart index 80506c5..f8fb427 100644 --- a/lib/ui/views/user_ui/reservasi_meja/reservasi_meja_view.dart +++ b/lib/ui/views/user_ui/reservasi_meja/reservasi_meja_view.dart @@ -23,183 +23,198 @@ class ReservasiMejaView extends StatelessWidget { ReservasiMejaViewModel model, Widget? child, ) { - return Scaffold( - appBar: AppBar( - title: const Text('RESERVASI MEJA', - style: TextStyle(color: Colors.white)), - backgroundColor: mainColor, - automaticallyImplyLeading: false, - actions: [ - // create a shopping cart icon with a badge containing the number of items - Container( - margin: const EdgeInsets.only(right: 10), - child: Stack( - children: [ - IconButton( - onPressed: () {}, - icon: const Icon(Icons.shopping_cart_outlined, - color: Colors.white), - ), - Positioned( - top: 5, - right: 5, - child: Container( + return WillPopScope( + onWillPop: () async { + // model.log.i('onWillPop di reservasi_meja_view.dart'); + if (model.globalVar.backPressed == 'exitApp') { + model.quitApp(context); + model.globalVar.backPressed = 'exitApp'; + return false; + } + return false; + }, + child: Scaffold( + appBar: AppBar( + title: const Text('RESERVASI MEJA', + style: TextStyle(color: Colors.white)), + backgroundColor: mainColor, + automaticallyImplyLeading: false, + actions: [ + // create a shopping cart icon with a badge containing the number of items + Container( + margin: const EdgeInsets.only(right: 10), + child: Stack( + children: [ + IconButton( + onPressed: () {}, + icon: const Icon(Icons.shopping_cart_outlined, + color: Colors.white), + ), + Positioned( + top: 5, + right: 5, + child: Container( + width: 20, + height: 20, + decoration: const BoxDecoration( + color: Colors.red, + shape: BoxShape.circle, + ), + child: const Center( + child: Text( + '9', + style: TextStyle( + color: Colors.white, + fontSize: 12, + ), + ), + ), + ), + ), + ], + ), + ), + ], + ), + body: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + height: 20, + ), + CarouselSlider.builder( + itemCount: model.imagePaths.length, + itemBuilder: + (BuildContext context, int index, int realIndex) { + return SizedBox( + width: MediaQuery.of(context) + .size + .width, // Set the width to full width + child: Image.asset( + model.imagePaths[index], + fit: BoxFit.cover, + ), + ); + }, + options: CarouselOptions( + autoPlay: true, + aspectRatio: 2.0, + enlargeCenterPage: true, + ), + ), + Expanded( + child: WebView( + initialUrl: dotenv.env['table_url'], + // initialUrl: 'http://172.29.85.181/parkir/user', + // initialUrl: 'https://rekam-medis.airlangga-it.com/', + javascriptMode: JavascriptMode.unrestricted, + onWebViewCreated: (WebViewController webViewController) { + // _controller.complete(webViewController); + // model.controllerCompleter.future + // .then((value) => model.webViewController = value); + // model.controllerCompleter.complete(webViewController); + }, + onProgress: (int progress) { + // model.log.i('WebView is loading (progress : $progress%)'); + // show a loading indicator when the WebView is loading using circular progress indicator + model.easyLoading.customLoading('Loading Data Meja'); + }, + // javascriptChannels: { + // _toasterJavascriptChannel(context), + // }, + javascriptChannels: { + JavascriptChannel( + name: 'messageHandler', + onMessageReceived: (JavascriptMessage message) async { + // model.log.i('messageHandler : ${message.message}'); + // model.easyLoading.backPressed = 1; + model.notifyListeners(); + // model.log.i( + // 'backPressed : ${model.easyLoading.backPressed}'); + String mejaId = message.message; + model.navigationService.navigateToView( + MejaDetailView( + mejaId: mejaId, + ), + ); + }, + ), + JavascriptChannel( + name: 'messageHandler1', + onMessageReceived: (JavascriptMessage message) async { + // String no_telpon = message.message; + // dev.i('no_telpon : $no_telpon'); + // await launchUrl(Uri.parse('tel:$no_telpon')); + }, + ), + }, + navigationDelegate: (NavigationRequest request) async { + // if (request.url.startsWith('https://www.youtube.com/')) { + // dev.log('blocking navigation to $request}'); + // return NavigationDecision.prevent; + // } + // check if request.url has 'nrm' + + return NavigationDecision.navigate; + }, + onPageStarted: (String url) { + model.log.i('Page started loading: $url'); + }, + onPageFinished: (String url) { + model.log.i('Page finished loading: $url'); + model.easyLoading.dismissLoading(); + }, + gestureNavigationEnabled: true, + backgroundColor: const Color(0x00000000), + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(20, 0, 20, 20), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + // create 3 circle color + Container( + width: 20, + height: 20, + decoration: const BoxDecoration( + color: Color.fromRGBO(223, 216, 214, 1), + shape: BoxShape.circle, + ), + ), + const SizedBox(width: 5), + const Text('Tersedia'), + const SizedBox(width: 10), + + Container( width: 20, height: 20, decoration: const BoxDecoration( color: Colors.red, shape: BoxShape.circle, ), - child: const Center( - child: Text( - '9', - style: TextStyle( - color: Colors.white, - fontSize: 12, - ), - ), + ), + const SizedBox(width: 5), + const Text('Tidak Tersedia'), + + const SizedBox(width: 10), + Container( + width: 20, + height: 20, + decoration: const BoxDecoration( + color: Colors.blue, + shape: BoxShape.circle, ), ), - ), - ], + const SizedBox(width: 5), + const Text('Dipesan'), + const SizedBox(width: 10), + ], + ), ), - ), - ], - ), - body: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 20, - ), - CarouselSlider.builder( - itemCount: model.imagePaths.length, - itemBuilder: (BuildContext context, int index, int realIndex) { - return SizedBox( - width: MediaQuery.of(context) - .size - .width, // Set the width to full width - child: Image.asset( - model.imagePaths[index], - fit: BoxFit.cover, - ), - ); - }, - options: CarouselOptions( - autoPlay: true, - aspectRatio: 2.0, - enlargeCenterPage: true, - ), - ), - Expanded( - child: WebView( - initialUrl: dotenv.env['table_url'], - // initialUrl: 'http://172.29.85.181/parkir/user', - // initialUrl: 'https://rekam-medis.airlangga-it.com/', - javascriptMode: JavascriptMode.unrestricted, - onWebViewCreated: (WebViewController webViewController) { - // _controller.complete(webViewController); - // model.controllerCompleter.future - // .then((value) => model.webViewController = value); - // model.controllerCompleter.complete(webViewController); - }, - onProgress: (int progress) { - model.log.i('WebView is loading (progress : $progress%)'); - }, - // javascriptChannels: { - // _toasterJavascriptChannel(context), - // }, - javascriptChannels: { - JavascriptChannel( - name: 'messageHandler', - onMessageReceived: (JavascriptMessage message) async { - // model.log.i('messageHandler : ${message.message}'); - model.easyLoading.backPressed = 1; - model.notifyListeners(); - model.log.i( - 'backPressed : ${model.easyLoading.backPressed}'); - String mejaId = message.message; - model.navigationService.navigateToView( - MejaDetailView( - mejaId: mejaId, - ), - ); - }, - ), - JavascriptChannel( - name: 'messageHandler1', - onMessageReceived: (JavascriptMessage message) async { - // String no_telpon = message.message; - // dev.i('no_telpon : $no_telpon'); - // await launchUrl(Uri.parse('tel:$no_telpon')); - }, - ), - }, - navigationDelegate: (NavigationRequest request) async { - // if (request.url.startsWith('https://www.youtube.com/')) { - // dev.log('blocking navigation to $request}'); - // return NavigationDecision.prevent; - // } - // check if request.url has 'nrm' - - return NavigationDecision.navigate; - }, - onPageStarted: (String url) { - model.log.i('Page started loading: $url'); - }, - onPageFinished: (String url) { - model.log.i('Page finished loading: $url'); - }, - gestureNavigationEnabled: true, - backgroundColor: const Color(0x00000000), - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(20, 0, 20, 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - // create 3 circle color - Container( - width: 20, - height: 20, - decoration: const BoxDecoration( - color: Color.fromRGBO(223, 216, 214, 1), - shape: BoxShape.circle, - ), - ), - const SizedBox(width: 5), - const Text('Tersedia'), - const SizedBox(width: 10), - - Container( - width: 20, - height: 20, - decoration: const BoxDecoration( - color: Colors.red, - shape: BoxShape.circle, - ), - ), - const SizedBox(width: 5), - const Text('Tidak Tersedia'), - - const SizedBox(width: 10), - Container( - width: 20, - height: 20, - decoration: const BoxDecoration( - color: Colors.blue, - shape: BoxShape.circle, - ), - ), - const SizedBox(width: 5), - const Text('Dipesan'), - const SizedBox(width: 10), - ], - ), - ), - ], + ], + ), ), ); }, diff --git a/lib/ui/views/user_ui/reservasi_meja/reservasi_meja_view_model.dart b/lib/ui/views/user_ui/reservasi_meja/reservasi_meja_view_model.dart index 97161d9..e69669e 100644 --- a/lib/ui/views/user_ui/reservasi_meja/reservasi_meja_view_model.dart +++ b/lib/ui/views/user_ui/reservasi_meja/reservasi_meja_view_model.dart @@ -13,6 +13,6 @@ class ReservasiMejaViewModel extends CustomBaseViewModel { ]; Future init() async { - easyLoading.backPressed = 2; + globalVar.backPressed = 'exitApp'; } } diff --git a/lib/ui/views/user_ui/user_index_tracking/user_index_tracking_view_model.dart b/lib/ui/views/user_ui/user_index_tracking/user_index_tracking_view_model.dart index c31e14f..1b714d6 100644 --- a/lib/ui/views/user_ui/user_index_tracking/user_index_tracking_view_model.dart +++ b/lib/ui/views/user_ui/user_index_tracking/user_index_tracking_view_model.dart @@ -1,52 +1,49 @@ -import 'package:back_button_interceptor/back_button_interceptor.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:reza_app/services/my_easyloading.dart'; import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; import '../../../../app/app.locator.dart'; import '../../../../app/app.logger.dart'; import '../../../../app/app.router.dart'; -import '../../../../app/themes/app_colors.dart'; +import '../../../../services/global_var.dart'; class UserIndexTrackingViewModel extends IndexTrackingViewModel { final log = getLogger('UserIndexTrackingViewModel'); final navigationService = locator(); - final easyLoading = locator(); + final globalVar = locator(); // late bool backPressed; Future init() async { - BackButtonInterceptor.add(myInterceptor); + // BackButtonInterceptor.add(myInterceptor); // backPressed = easyLoading.backPressed; - easyLoading.backPressed = 2; + globalVar.backPressed = 'exitApp'; } - bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { - // print("BACK BUTTON!"); // Do some stuff. + // bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { + // // print("BACK BUTTON!"); // Do some stuff. - log.i('myInterceptor : ${easyLoading.backPressed}'); + // log.i('myInterceptor : ${easyLoading.backPressed}'); - if (easyLoading.backPressed == 2) { - quitApp(null); - } + // if (easyLoading.backPressed == 2) { + // quitApp(null); + // } - if (easyLoading.backPressed == 3) { - // easyLoading.backPressed = 2; - // notifyListeners(); - // navigationService.back(); - easyLoading.backPressed = 2; - return false; - } + // if (easyLoading.backPressed == 3) { + // // easyLoading.backPressed = 2; + // // notifyListeners(); + // // navigationService.back(); + // easyLoading.backPressed = 2; + // return false; + // } - if (easyLoading.backPressed == 1) { - // easyLoading.backPressed = 2; - // notifyListeners(); - // navigationService.back(); - return false; - } + // if (easyLoading.backPressed == 1) { + // // easyLoading.backPressed = 2; + // // notifyListeners(); + // // navigationService.back(); + // return false; + // } - return true; - } + // return true; + // } final _bottomNavBarList = [ { @@ -95,37 +92,37 @@ class UserIndexTrackingViewModel extends IndexTrackingViewModel { ); } - quitApp(BuildContext? context) { - easyLoading.backPressed = 0; - showDialog( - context: context ?? StackedService.navigatorKey!.currentContext!, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Keluar'), - content: const Text('Apakah Anda yakin ingin keluar?'), - actions: [ - TextButton( - onPressed: () { - easyLoading.backPressed = 2; - Navigator.of(context).pop(false); - }, - child: const Text('Batal'), - ), - TextButton( - onPressed: () => Navigator.of(context).pop(true), - child: const Text( - 'Keluar', - style: TextStyle(color: dangerColor), - ), - ), - ], - ); - }, - ).then((value) { - if (value == true) { - SystemNavigator.pop(); - } - }); - notifyListeners(); - } +// quitApp(BuildContext? context) { +// easyLoading.backPressed = 0; +// showDialog( +// context: context ?? StackedService.navigatorKey!.currentContext!, +// builder: (BuildContext context) { +// return AlertDialog( +// title: const Text('Keluar'), +// content: const Text('Apakah Anda yakin ingin keluar?'), +// actions: [ +// TextButton( +// onPressed: () { +// easyLoading.backPressed = 2; +// Navigator.of(context).pop(false); +// }, +// child: const Text('Batal'), +// ), +// TextButton( +// onPressed: () => Navigator.of(context).pop(true), +// child: const Text( +// 'Keluar', +// style: TextStyle(color: dangerColor), +// ), +// ), +// ], +// ); +// }, +// ).then((value) { +// if (value == true) { +// SystemNavigator.pop(); +// } +// }); +// notifyListeners(); +// } }