repair back button

This commit is contained in:
kicap
2023-08-10 01:21:43 +08:00
parent 696c52efeb
commit 6c5bfde828
29 changed files with 956 additions and 845 deletions

View File

@ -1,5 +1,5 @@
import 'package:reza_app/ui/views/meja_detail/meja_detail_view.dart'; import 'package:reza_app/services/global_var.dart';
import 'package:reza_app/ui/views/user_ui/pesanan_list/keranjang_saya/keranjang_saya_view.dart'; import 'package:reza_app/services/other_function.dart';
import 'package:stacked_services/stacked_services.dart'; import 'package:stacked_services/stacked_services.dart';
import 'package:stacked/stacked_annotations.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/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/daftar_user_ui/verifikasi_no_hp/verifikasi_no_hp_view.dart';
import '../ui/views/login_user/login_user_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/splash_screen/splash_screen_view.dart';
import '../ui/views/user_ui/akun_user/akun_user_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/detail_makanan/detail_makanan_view.dart';
import '../ui/views/user_ui/makanan_list/makanan_list_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/pesanan_list/pesanan_list_view.dart';
import '../ui/views/user_ui/reservasi_meja/reservasi_meja_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'; 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: MyEasyLoading),
LazySingleton(classType: MyHttpServices), LazySingleton(classType: MyHttpServices),
LazySingleton(classType: OtherFunction),
LazySingleton(classType: GlobalVar),
], ],
logger: StackedLogger(), logger: StackedLogger(),
) )

View File

@ -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_services/src/snackbar/snackbar_service.dart';
import 'package:stacked_shared/stacked_shared.dart'; import 'package:stacked_shared/stacked_shared.dart';
import '../services/global_var.dart';
import '../services/http_services.dart'; import '../services/http_services.dart';
import '../services/my_easyloading.dart'; import '../services/my_easyloading.dart';
import '../services/other_function.dart';
final locator = StackedLocator.instance; final locator = StackedLocator.instance;
@ -32,4 +34,6 @@ Future<void> setupLocator({
locator.registerLazySingleton(() => BottomSheetService()); locator.registerLazySingleton(() => BottomSheetService());
locator.registerLazySingleton(() => MyEasyLoading()); locator.registerLazySingleton(() => MyEasyLoading());
locator.registerLazySingleton(() => MyHttpServices()); locator.registerLazySingleton(() => MyHttpServices());
locator.registerLazySingleton(() => OtherFunction());
locator.registerLazySingleton(() => GlobalVar());
} }

View File

@ -3,8 +3,10 @@ import 'package:flutter/services.dart';
import 'package:stacked/stacked.dart'; import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart'; import 'package:stacked_services/stacked_services.dart';
import '../../services/global_var.dart';
import '../../services/http_services.dart'; import '../../services/http_services.dart';
import '../../services/my_easyloading.dart'; import '../../services/my_easyloading.dart';
import '../../services/other_function.dart';
import '../app.locator.dart'; import '../app.locator.dart';
import '../themes/app_colors.dart'; import '../themes/app_colors.dart';
@ -15,6 +17,8 @@ class CustomBaseViewModel extends BaseViewModel {
final snackbarService = locator<SnackbarService>(); final snackbarService = locator<SnackbarService>();
final easyLoading = locator<MyEasyLoading>(); final easyLoading = locator<MyEasyLoading>();
final httpService = locator<MyHttpServices>(); final httpService = locator<MyHttpServices>();
final otherFunction = locator<OtherFunction>();
final globalVar = locator<GlobalVar>();
// late bool backPressed; // late bool backPressed;

View File

@ -21,7 +21,7 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Panti Asuhan Aisyiyah Abadi', title: 'Reza Restaurant App',
theme: appTheme, theme: appTheme,
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
navigatorKey: StackedService.navigatorKey, navigatorKey: StackedService.navigatorKey,

View File

@ -0,0 +1,3 @@
class GlobalVar {
String backPressed = 'backNormal';
}

View File

@ -1,8 +1,6 @@
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
class MyEasyLoading { class MyEasyLoading {
int backPressed = 1;
showLoading() { showLoading() {
EasyLoading.show( EasyLoading.show(
status: 'loading...', status: 'loading...',

View File

@ -40,7 +40,7 @@ class InputInformasiDiriView extends StatelessWidget {
), ),
body: WillPopScope( body: WillPopScope(
onWillPop: () async { onWillPop: () async {
if (model.easyLoading.backPressed == 1) { if (model.globalVar.backPressed == 'backNormal') {
model.navigationService.navigateToMasukanNoHpView(); model.navigationService.navigateToMasukanNoHpView();
} }
return false; return false;

View File

@ -33,13 +33,13 @@ class InputInformasiDiriViewModel extends CustomBaseViewModel {
} }
goToLogin() async { goToLogin() async {
easyLoading.backPressed = 0; globalVar.backPressed = 'cantBack';
easyLoading.customLoading("Mendaftarkan Akun Anda"); easyLoading.customLoading("Mendaftarkan Akun Anda");
await Future.delayed(const Duration(seconds: 2)); await Future.delayed(const Duration(seconds: 2));
easyLoading.customLoading("Ke Halaman Login"); easyLoading.customLoading("Ke Halaman Login");
await Future.delayed(const Duration(seconds: 2)); await Future.delayed(const Duration(seconds: 2));
easyLoading.dismissLoading(); easyLoading.dismissLoading();
easyLoading.backPressed = 1; globalVar.backPressed = 'backNormal';
notifyListeners(); notifyListeners();
await navigationService.navigateToLoginUserView(); await navigationService.navigateToLoginUserView();
} }

View File

@ -36,7 +36,7 @@ class MasukanNoHpView extends StatelessWidget {
), ),
body: WillPopScope( body: WillPopScope(
onWillPop: () async { onWillPop: () async {
if (model.easyLoading.backPressed == 1) { if (model.globalVar.backPressed == 'backNormal') {
model.navigationService.navigateToLoginUserView(); model.navigationService.navigateToLoginUserView();
} }
return false; return false;

View File

@ -16,9 +16,9 @@ class MasukanNoHpViewModel extends CustomBaseViewModel {
selanjutnya() async { selanjutnya() async {
_easyloading.customLoading("Menghantar Kode OTP \nke WhatsApp Anda"); _easyloading.customLoading("Menghantar Kode OTP \nke WhatsApp Anda");
easyLoading.backPressed = 0; globalVar.backPressed = 'cantBack';
await Future.delayed(const Duration(seconds: 3)); await Future.delayed(const Duration(seconds: 3));
easyLoading.backPressed = 1; globalVar.backPressed = 'backNormal';
notifyListeners(); notifyListeners();
_easyloading.dismissLoading(); _easyloading.dismissLoading();
await navigationService.navigateToVerifikasiNoHpView(); await navigationService.navigateToVerifikasiNoHpView();

View File

@ -36,7 +36,7 @@ class VerifikasiNoHpView extends StatelessWidget {
), ),
body: WillPopScope( body: WillPopScope(
onWillPop: () async { onWillPop: () async {
if (model.easyLoading.backPressed == 1) { if (model.globalVar.backPressed == 'backNormal') {
model.back(); model.back();
} }
return false; return false;

View File

@ -9,11 +9,11 @@ class VerifikasiNoHpViewModel extends CustomBaseViewModel {
Future<void> init() async {} Future<void> init() async {}
goToInputInformasiDiri() async { goToInputInformasiDiri() async {
easyLoading.backPressed = 0; globalVar.backPressed = 'cantBack';
easyLoading.customLoading("Ke Halaman Input Informasi Diri"); easyLoading.customLoading("Ke Halaman Input Informasi Diri");
await Future.delayed(const Duration(seconds: 3)); await Future.delayed(const Duration(seconds: 3));
easyLoading.dismissLoading(); easyLoading.dismissLoading();
easyLoading.backPressed = 1; globalVar.backPressed = 'backNormal';
notifyListeners(); notifyListeners();
await navigationService.navigateToInputInformasiDiriView( await navigationService.navigateToInputInformasiDiriView(
noHp: "082293246583", noHp: "082293246583",

View File

@ -23,7 +23,7 @@ class LoginUserView extends StatelessWidget {
return Scaffold( return Scaffold(
body: WillPopScope( body: WillPopScope(
onWillPop: () async { onWillPop: () async {
if (model.easyLoading.backPressed == 1) { if (model.globalVar.backPressed == 'backNormal') {
// model.back(); // model.back();
model.quitApp(context); model.quitApp(context);
} }

View File

@ -17,12 +17,12 @@ class LoginUserViewModel extends CustomBaseViewModel {
login() async { login() async {
setBusy(true); setBusy(true);
easyLoading.backPressed = 0; globalVar.backPressed = 'cantBack';
easyLoading.showLoading(); easyLoading.showLoading();
await Future.delayed(const Duration(seconds: 5)); await Future.delayed(const Duration(seconds: 5));
easyLoading.dismissLoading(); easyLoading.dismissLoading();
setBusy(false); setBusy(false);
easyLoading.backPressed = 1; globalVar.backPressed = 'backNormal';
notifyListeners(); notifyListeners();
await navigationService.navigateToUserIndexTrackingView(); await navigationService.navigateToUserIndexTrackingView();
} }

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; 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_colors.dart';
import 'package:reza_app/app/themes/app_text.dart'; import 'package:reza_app/app/themes/app_text.dart';
import 'package:stacked/stacked.dart'; import 'package:stacked/stacked.dart';
@ -26,119 +25,136 @@ class MejaDetailView extends StatelessWidget {
MejaDetailViewModel model, MejaDetailViewModel model,
Widget? child, Widget? child,
) { ) {
return Scaffold( return WillPopScope(
appBar: AppBar( onWillPop: () async {
title: const Text('MejaDetailView', if (model.globalVar.backPressed == 'backNormal') {
style: TextStyle(color: Colors.white)), model.globalVar.backPressed = 'exitApp';
backgroundColor: mainColor, return true;
leading: IconButton( }
onPressed: () => model.navigationService.popUntil((route) => // model.quitApp(context);
route.settings.name == Routes.userIndexTrackingView),
icon: const Icon(Icons.arrow_back, color: Colors.white), 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(
body: Padding( padding:
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10), const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Container(
height: 250, height: 250,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20), 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( const SizedBox(height: 5),
borderRadius: BorderRadius.circular(20), Text(
child: model.imgAsset == null model.namaMeja,
? const Center(child: CircularProgressIndicator()) style: const TextStyle(
: Image.asset(model.imgAsset!, fit: BoxFit.cover), fontSize: 20,
// fontWeight: FontWeight.bold,
),
), ),
), const SizedBox(height: 10),
const SizedBox(height: 5), RichText(
Text( text: TextSpan(
model.namaMeja, text: 'Status : ',
style: const TextStyle( style: regularTextStyle,
fontSize: 20, children: [
// fontWeight: FontWeight.bold, TextSpan(
), text: 'Tersedia',
), style: regularTextStyle.copyWith(
const SizedBox(height: 10), color: Colors.green,
RichText( fontWeight: FontWeight.bold,
text: TextSpan( ),
text: 'Status : ',
style: regularTextStyle,
children: [
TextSpan(
text: 'Tersedia',
style: regularTextStyle.copyWith(
color: Colors.green,
fontWeight: FontWeight.bold,
), ),
), ],
], ),
), ),
), const SizedBox(height: 10),
const SizedBox(height: 10), RichText(
RichText( text: TextSpan(
text: TextSpan( text: 'Kapasitas : ',
text: 'Kapasitas : ', style: regularTextStyle,
style: regularTextStyle, children: [
children: [ TextSpan(
TextSpan( text: 'Maksimal 8 Orang',
text: 'Maksimal 8 Orang', style: regularTextStyle.copyWith(
style: regularTextStyle.copyWith( color: Colors.green,
color: Colors.green, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), ),
), ],
], ),
), ),
), const SizedBox(height: 10),
const SizedBox(height: 10), RichText(
RichText( text: TextSpan(
text: TextSpan( text: 'Lokasi : ',
text: 'Lokasi : ', style: regularTextStyle,
style: regularTextStyle, children: [
children: [ TextSpan(
TextSpan( text: 'Luar Ruangan',
text: 'Luar Ruangan', style: regularTextStyle.copyWith(
style: regularTextStyle.copyWith( color: Colors.green,
color: Colors.green, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), ),
), ],
], ),
), ),
), const SizedBox(height: 10),
const SizedBox(height: 10), RichText(
RichText( text: TextSpan(
text: TextSpan( text: 'Harga : ',
text: 'Harga : ', style: regularTextStyle,
style: regularTextStyle, children: [
children: [ TextSpan(
TextSpan( text: 'Rp. 20.000',
text: 'Rp. 20.000', style: regularTextStyle.copyWith(
style: regularTextStyle.copyWith( color: Colors.orange,
color: Colors.orange, fontWeight: FontWeight.bold,
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,
); );
}, },
); );

View File

@ -13,7 +13,7 @@ class MejaDetailViewModel extends CustomBaseViewModel {
log.i('MejaDetailViewModel init'); log.i('MejaDetailViewModel init');
log.i('mejaId : $mejaId'); log.i('mejaId : $mejaId');
this.mejaId = mejaId; this.mejaId = mejaId;
easyLoading.backPressed = 3; globalVar.backPressed = 'backNormal';
// seperate the number from the string // seperate the number from the string
var number = int.parse(mejaId.replaceAll(RegExp(r'[^0-9]'), '')); var number = int.parse(mejaId.replaceAll(RegExp(r'[^0-9]'), ''));
// log.i('number : $number'); // log.i('number : $number');

View File

@ -20,111 +20,122 @@ class AkunUserView extends StatelessWidget {
AkunUserViewModel model, AkunUserViewModel model,
Widget? child, Widget? child,
) { ) {
return Scaffold( return WillPopScope(
appBar: AppBar( onWillPop: () async {
title: Text( // model.log.i('onWillPop di akun_user_view.dart');
'Akun Saya', if (model.globalVar.backPressed == 'exitApp') {
style: boldTextStyle.copyWith(color: fontGrey, fontSize: 16), model.quitApp(context);
), model.globalVar.backPressed = 'exitApp';
// transparent return false;
backgroundColor: Colors.transparent, }
automaticallyImplyLeading: false, return false;
actions: [ },
IconButton( child: Scaffold(
onPressed: () {}, appBar: AppBar(
icon: const Icon( title: Text(
Icons.logout_outlined, 'Akun Saya',
color: fontGrey, style: boldTextStyle.copyWith(color: fontGrey, fontSize: 16),
),
), ),
], // transparent
), backgroundColor: Colors.transparent,
backgroundColor: backgroundColor, automaticallyImplyLeading: false,
body: Padding( actions: [
padding: const EdgeInsets.symmetric(horizontal: 20), IconButton(
child: Column( onPressed: () {},
mainAxisAlignment: MainAxisAlignment.start, icon: const Icon(
mainAxisSize: MainAxisSize.min, Icons.logout_outlined,
crossAxisAlignment: CrossAxisAlignment.start, color: fontGrey,
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,
),
],
),
], ],
), ),
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,
),
],
),
],
),
),
), ),
); );
}, },

View File

@ -2,6 +2,6 @@ import 'package:reza_app/app/core/custom_base_view_model.dart';
class AkunUserViewModel extends CustomBaseViewModel { class AkunUserViewModel extends CustomBaseViewModel {
Future<void> init() async { Future<void> init() async {
easyLoading.backPressed = 2; globalVar.backPressed = 'exitApp';
} }
} }

View File

@ -28,7 +28,17 @@ class DetailMakananView extends HookWidget {
DetailMakananViewModel model, DetailMakananViewModel model,
Widget? child, 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, backgroundColor: backgroundColor,
body: SizedBox( body: SizedBox(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
@ -203,7 +213,9 @@ class DetailMakananView extends HookWidget {
), ),
], ],
), ),
)); ),
),
);
}, },
); );
} }
@ -257,6 +269,7 @@ class TopBarWidget extends ViewModelWidget<DetailMakananViewModel> {
), ),
child: IconButton( child: IconButton(
onPressed: () { onPressed: () {
viewModel.globalVar.backPressed = 'exitApp';
viewModel.back(); viewModel.back();
}, },
icon: const Icon( icon: const Icon(

View File

@ -5,6 +5,6 @@ class DetailMakananViewModel extends CustomBaseViewModel {
final log = getLogger('DetailMakananViewModel'); final log = getLogger('DetailMakananViewModel');
Future<void> init() async { Future<void> init() async {
easyLoading.backPressed = 3; globalVar.backPressed = 'backNormal';
} }
} }

View File

@ -21,7 +21,17 @@ class MakananListView extends StatelessWidget {
MakananListViewModel model, MakananListViewModel model,
Widget? child, 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, backgroundColor: backgroundColor,
body: Column( body: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
@ -38,7 +48,14 @@ class MakananListView extends StatelessWidget {
Expanded( Expanded(
flex: 2, flex: 2,
child: IconButton( 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), icon: const Icon(Icons.arrow_back),
), ),
), ),
@ -230,7 +247,9 @@ class MakananListView extends StatelessWidget {
], ],
), ),
), ),
)); ),
),
);
}, },
); );
} }

View File

@ -5,7 +5,7 @@ import '../../../../app/core/custom_base_view_model.dart';
class MakananListViewModel extends CustomBaseViewModel { class MakananListViewModel extends CustomBaseViewModel {
final log = getLogger('MakananListViewModel'); final log = getLogger('MakananListViewModel');
Future<void> init() async { Future<void> init() async {
easyLoading.backPressed = 2; globalVar.backPressed = 'exitApp';
} }
goToDetailMakanan() { goToDetailMakanan() {

View File

@ -21,151 +21,164 @@ class KeranjangSayaView extends StatelessWidget {
KeranjangSayaViewModel model, KeranjangSayaViewModel model,
Widget? child, Widget? child,
) { ) {
return Scaffold( return WillPopScope(
appBar: AppBar( onWillPop: () async {
title: const Text('Keranjang Saya', // model.log.i('onWillPop di reservasi_meja_view.dart');
style: TextStyle(color: Colors.white)), if (model.globalVar.backPressed == 'backNormal') {
backgroundColor: mainColor, // model.quitApp(context);
iconTheme: const IconThemeData(color: Colors.white), model.globalVar.backPressed = 'exitApp';
), return true;
body: Column( }
children: [ return false;
const SizedBox(height: 15), },
Expanded( child: Scaffold(
child: ListView.builder( appBar: AppBar(
itemCount: 10, title: const Text('Keranjang Saya',
shrinkWrap: true, style: TextStyle(color: Colors.white)),
itemBuilder: (context, index) { backgroundColor: mainColor,
return Padding( iconTheme: const IconThemeData(color: Colors.white),
padding: const EdgeInsets.only(bottom: 10), ),
child: MyWhiteContainer( body: Column(
child: Row( children: [
mainAxisAlignment: MainAxisAlignment.start, const SizedBox(height: 15),
crossAxisAlignment: CrossAxisAlignment.center, Expanded(
children: [ child: ListView.builder(
// create a checkbox itemCount: 10,
Checkbox( shrinkWrap: true,
// check if the value is true or false itemBuilder: (context, index) {
value: false, return Padding(
// if true change the value to false padding: const EdgeInsets.only(bottom: 10),
onChanged: (bool? value) { child: MyWhiteContainer(
// model.changeIsCheck(value!); child: Row(
}, mainAxisAlignment: MainAxisAlignment.start,
), crossAxisAlignment: CrossAxisAlignment.center,
const SizedBox(width: 10), children: [
// create a container 100x100 that contain the image // create a checkbox
Container( Checkbox(
width: 100, // check if the value is true or false
height: 100, value: false,
decoration: BoxDecoration( // if true change the value to false
borderRadius: BorderRadius.circular(10), onChanged: (bool? value) {
// model.changeIsCheck(value!);
},
), ),
child: ClipRRect( const SizedBox(width: 10),
borderRadius: BorderRadius.circular(10), // create a container 100x100 that contain the image
child: Image.network( Container(
'https://a.cdn-hotels.com/gdcs/production0/d1513/35c1c89e-408c-4449-9abe-f109068f40c0.jpg?impolicy=fcrop&w=800&h=533&q=medium', width: 100,
height: 150, height: 100,
width: double.infinity, decoration: BoxDecoration(
fit: BoxFit.fill, borderRadius: BorderRadius.circular(10),
errorBuilder: (context, error, stackTrace) { ),
return const Icon(Icons.error); 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),
const SizedBox(width: 10), Expanded(
Expanded( child: Column(
child: Column( mainAxisAlignment: MainAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment:
crossAxisAlignment: CrossAxisAlignment.start, CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( Text(
'Product Name ', 'Product Name ',
style: regularTextStyle.copyWith( style: regularTextStyle.copyWith(
fontSize: 16), fontSize: 16),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
const SizedBox(height: 5), const SizedBox(height: 5),
Text( Text(
'Rp. 100.000', 'Rp. 100.000',
style: boldTextStyle.copyWith( style: boldTextStyle.copyWith(
color: redColor), color: redColor),
), ),
const SizedBox(height: 5), const SizedBox(height: 5),
// create a row that contain minus button, value, and plus button // create a row that contain minus button, value, and plus button
Row( Row(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.start, MainAxisAlignment.start,
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.center, CrossAxisAlignment.center,
children: [ children: [
// create a button minus // create a button minus
GestureDetector( GestureDetector(
onTap: () {}, onTap: () {},
child: Container( child: Container(
width: 25, width: 25,
height: 25, height: 25,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: borderRadius:
BorderRadius.circular(5), BorderRadius.circular(5),
color: stockColor, color: stockColor,
), ),
child: const Icon( child: const Icon(
Icons.remove, Icons.remove,
color: mainGrey, color: mainGrey,
),
), ),
), ),
), const SizedBox(width: 10),
const SizedBox(width: 10), // create a text that contain value
// create a text that contain value Text(
Text( '1',
'1', style: regularTextStyle.copyWith(
style: regularTextStyle.copyWith( fontSize: 16,
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 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),
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,
), ),
)); 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,
),
)),
);
}, },
); );
} }

View File

@ -5,6 +5,6 @@ import '../../../../../app/app.logger.dart';
class KeranjangSayaViewModel extends CustomBaseViewModel { class KeranjangSayaViewModel extends CustomBaseViewModel {
final log = getLogger('KeranjangSayaViewModel'); final log = getLogger('KeranjangSayaViewModel');
Future<void> init() async { Future<void> init() async {
easyLoading.backPressed = 3; globalVar.backPressed = 'backNormal';
} }
} }

View File

@ -22,93 +22,54 @@ class PesananListView extends StatelessWidget {
PesananListViewModel model, PesananListViewModel model,
Widget? child, Widget? child,
) { ) {
return Scaffold( return WillPopScope(
appBar: AppBar( onWillPop: () async {
title: Text( // model.log.i('onWillPop di reservasi_meja_view.dart');
'List Pesanan', if (model.globalVar.backPressed == 'exitApp') {
style: boldTextStyle.copyWith(color: Colors.white), model.quitApp(context);
), model.globalVar.backPressed = 'exitApp';
backgroundColor: mainColor, return false;
automaticallyImplyLeading: false, }
actions: [ return false;
// create a shopping cart icon with a badge containing the number of items },
Container( child: Scaffold(
margin: const EdgeInsets.only(right: 10), appBar: AppBar(
child: Stack( title: Text(
children: [ 'List Pesanan',
IconButton( style: boldTextStyle.copyWith(color: Colors.white),
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,
),
),
),
),
),
],
),
), ),
], backgroundColor: mainColor,
), automaticallyImplyLeading: false,
backgroundColor: backgroundColor, actions: [
body: Column( // create a shopping cart icon with a badge containing the number of items
children: [ Container(
MyWhiteContainer( margin: const EdgeInsets.only(right: 10),
child: IntrinsicHeight( child: Stack(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Expanded( IconButton(
child: TextButton( onPressed: () {
onPressed: () {}, model.navigationService.navigateToKeranjangSayaView();
child: const Text('Dikemas'), },
), icon: const Icon(Icons.shopping_cart_outlined,
color: Colors.white),
), ),
const VerticalDivider( Positioned(
color: mainGrey, top: 5,
thickness: 1, right: 5,
), child: Container(
Expanded( width: 20,
child: TextButton( height: 20,
onPressed: () {}, decoration: const BoxDecoration(
child: const Text( color: Colors.red,
'Dikirim', shape: BoxShape.circle,
style: TextStyle(
color: mainGrey,
),
), ),
), child: const Center(
), child: Text(
const VerticalDivider( '9',
color: Colors.grey, style: TextStyle(
thickness: 1, color: Colors.white,
), fontSize: 12,
Expanded( ),
child: TextButton(
onPressed: () {},
child: const Text(
'Selesai',
style: TextStyle(
color: mainGrey,
), ),
), ),
), ),
@ -116,193 +77,246 @@ class PesananListView extends StatelessWidget {
], ],
), ),
), ),
), ],
const SizedBox( ),
height: 15, backgroundColor: backgroundColor,
), body: Column(
Expanded( children: [
child: ListView.builder( MyWhiteContainer(
shrinkWrap: true, child: IntrinsicHeight(
itemCount: 10, child: Row(
itemBuilder: (context, index) { mainAxisAlignment: MainAxisAlignment.start,
return Padding( children: [
padding: const EdgeInsets.only(bottom: 10), Expanded(
child: MyWhiteContainer( child: TextButton(
child: Padding( onPressed: () {},
padding: const EdgeInsets.symmetric( child: const Text('Dikemas'),
horizontal: 20,
), ),
child: Column( ),
children: [ const VerticalDivider(
Row( color: mainGrey,
mainAxisAlignment: thickness: 1,
MainAxisAlignment.spaceBetween, ),
crossAxisAlignment: CrossAxisAlignment.start, Expanded(
children: [ child: TextButton(
Container( onPressed: () {},
width: 100, child: const Text(
height: 100, 'Dikirim',
decoration: BoxDecoration( style: TextStyle(
borderRadius: BorderRadius.circular(10), color: mainGrey,
), ),
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', const VerticalDivider(
height: 100, color: Colors.grey,
width: double.infinity, thickness: 1,
fit: BoxFit.fill, ),
errorBuilder: Expanded(
(context, error, stackTrace) { child: TextButton(
return const Icon(Icons.error); 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, const SizedBox(
), height: 10,
Expanded( ),
child: IntrinsicHeight( Row(
child: Column( mainAxisAlignment:
mainAxisAlignment: MainAxisAlignment.spaceBetween,
MainAxisAlignment.start, children: [
crossAxisAlignment: const Text(
CrossAxisAlignment.start, '3 Item',
style: regularTextStyle,
),
const Expanded(child: SizedBox()),
RichText(
text: TextSpan(
text: 'Total Pesanan: ',
style: regularTextStyle,
children: [ children: [
Expanded( TextSpan(
child: Text( text: 'Rp. 300.000',
'Nama Makanan', style: regularTextStyle.copyWith(
style: regularTextStyle.copyWith( color: redColor,
fontSize: 17, fontWeight: FontWeight.bold,
),
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(
const SizedBox( height: 15,
height: 10, ),
), Row(
Row( mainAxisAlignment:
mainAxisAlignment: MainAxisAlignment.spaceBetween,
MainAxisAlignment.spaceBetween, children: [
children: [ // lorry icon
const Text( const Icon(
'3 Item', Icons.local_shipping_outlined,
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(
color: mainColor, color: mainColor,
), ),
), const SizedBox(
width: 5,
),
Text(
'Pesanan telah sampai',
style: regularTextStyle.copyWith(
color: mainColor,
),
),
const Expanded(child: SizedBox()), const Expanded(child: SizedBox()),
const Icon( const Icon(
Icons.arrow_forward_ios, Icons.arrow_forward_ios,
color: mainGrey, color: mainGrey,
size: 15, 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,
// ),
); );
}, },
); );

View File

@ -2,6 +2,6 @@ import 'package:reza_app/app/core/custom_base_view_model.dart';
class PesananListViewModel extends CustomBaseViewModel { class PesananListViewModel extends CustomBaseViewModel {
Future<void> init() async { Future<void> init() async {
easyLoading.backPressed = 2; globalVar.backPressed = 'exitApp';
} }
} }

View File

@ -23,183 +23,198 @@ class ReservasiMejaView extends StatelessWidget {
ReservasiMejaViewModel model, ReservasiMejaViewModel model,
Widget? child, Widget? child,
) { ) {
return Scaffold( return WillPopScope(
appBar: AppBar( onWillPop: () async {
title: const Text('RESERVASI MEJA', // model.log.i('onWillPop di reservasi_meja_view.dart');
style: TextStyle(color: Colors.white)), if (model.globalVar.backPressed == 'exitApp') {
backgroundColor: mainColor, model.quitApp(context);
automaticallyImplyLeading: false, model.globalVar.backPressed = 'exitApp';
actions: [ return false;
// create a shopping cart icon with a badge containing the number of items }
Container( return false;
margin: const EdgeInsets.only(right: 10), },
child: Stack( child: Scaffold(
children: [ appBar: AppBar(
IconButton( title: const Text('RESERVASI MEJA',
onPressed: () {}, style: TextStyle(color: Colors.white)),
icon: const Icon(Icons.shopping_cart_outlined, backgroundColor: mainColor,
color: Colors.white), automaticallyImplyLeading: false,
), actions: [
Positioned( // create a shopping cart icon with a badge containing the number of items
top: 5, Container(
right: 5, margin: const EdgeInsets.only(right: 10),
child: Container( 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: <JavascriptChannel>{
// _toasterJavascriptChannel(context),
// },
javascriptChannels: <JavascriptChannel>{
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, width: 20,
height: 20, height: 20,
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: Colors.red, color: Colors.red,
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
child: const Center( ),
child: Text( const SizedBox(width: 5),
'9', const Text('Tidak Tersedia'),
style: TextStyle(
color: Colors.white, const SizedBox(width: 10),
fontSize: 12, 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: <JavascriptChannel>{
// _toasterJavascriptChannel(context),
// },
javascriptChannels: <JavascriptChannel>{
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),
],
),
),
],
), ),
); );
}, },

View File

@ -13,6 +13,6 @@ class ReservasiMejaViewModel extends CustomBaseViewModel {
]; ];
Future<void> init() async { Future<void> init() async {
easyLoading.backPressed = 2; globalVar.backPressed = 'exitApp';
} }
} }

View File

@ -1,52 +1,49 @@
import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:flutter/material.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/stacked.dart';
import 'package:stacked_services/stacked_services.dart'; import 'package:stacked_services/stacked_services.dart';
import '../../../../app/app.locator.dart'; import '../../../../app/app.locator.dart';
import '../../../../app/app.logger.dart'; import '../../../../app/app.logger.dart';
import '../../../../app/app.router.dart'; import '../../../../app/app.router.dart';
import '../../../../app/themes/app_colors.dart'; import '../../../../services/global_var.dart';
class UserIndexTrackingViewModel extends IndexTrackingViewModel { class UserIndexTrackingViewModel extends IndexTrackingViewModel {
final log = getLogger('UserIndexTrackingViewModel'); final log = getLogger('UserIndexTrackingViewModel');
final navigationService = locator<NavigationService>(); final navigationService = locator<NavigationService>();
final easyLoading = locator<MyEasyLoading>(); final globalVar = locator<GlobalVar>();
// late bool backPressed; // late bool backPressed;
Future<void> init() async { Future<void> init() async {
BackButtonInterceptor.add(myInterceptor); // BackButtonInterceptor.add(myInterceptor);
// backPressed = easyLoading.backPressed; // backPressed = easyLoading.backPressed;
easyLoading.backPressed = 2; globalVar.backPressed = 'exitApp';
} }
bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { // bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) {
// print("BACK BUTTON!"); // Do some stuff. // // print("BACK BUTTON!"); // Do some stuff.
log.i('myInterceptor : ${easyLoading.backPressed}'); // log.i('myInterceptor : ${easyLoading.backPressed}');
if (easyLoading.backPressed == 2) { // if (easyLoading.backPressed == 2) {
quitApp(null); // quitApp(null);
} // }
if (easyLoading.backPressed == 3) { // if (easyLoading.backPressed == 3) {
// easyLoading.backPressed = 2; // // easyLoading.backPressed = 2;
// notifyListeners(); // // notifyListeners();
// navigationService.back(); // // navigationService.back();
easyLoading.backPressed = 2; // easyLoading.backPressed = 2;
return false; // return false;
} // }
if (easyLoading.backPressed == 1) { // if (easyLoading.backPressed == 1) {
// easyLoading.backPressed = 2; // // easyLoading.backPressed = 2;
// notifyListeners(); // // notifyListeners();
// navigationService.back(); // // navigationService.back();
return false; // return false;
} // }
return true; // return true;
} // }
final _bottomNavBarList = [ final _bottomNavBarList = [
{ {
@ -95,37 +92,37 @@ class UserIndexTrackingViewModel extends IndexTrackingViewModel {
); );
} }
quitApp(BuildContext? context) { // quitApp(BuildContext? context) {
easyLoading.backPressed = 0; // easyLoading.backPressed = 0;
showDialog( // showDialog(
context: context ?? StackedService.navigatorKey!.currentContext!, // context: context ?? StackedService.navigatorKey!.currentContext!,
builder: (BuildContext context) { // builder: (BuildContext context) {
return AlertDialog( // return AlertDialog(
title: const Text('Keluar'), // title: const Text('Keluar'),
content: const Text('Apakah Anda yakin ingin keluar?'), // content: const Text('Apakah Anda yakin ingin keluar?'),
actions: [ // actions: [
TextButton( // TextButton(
onPressed: () { // onPressed: () {
easyLoading.backPressed = 2; // easyLoading.backPressed = 2;
Navigator.of(context).pop(false); // Navigator.of(context).pop(false);
}, // },
child: const Text('Batal'), // child: const Text('Batal'),
), // ),
TextButton( // TextButton(
onPressed: () => Navigator.of(context).pop(true), // onPressed: () => Navigator.of(context).pop(true),
child: const Text( // child: const Text(
'Keluar', // 'Keluar',
style: TextStyle(color: dangerColor), // style: TextStyle(color: dangerColor),
), // ),
), // ),
], // ],
); // );
}, // },
).then((value) { // ).then((value) {
if (value == true) { // if (value == true) {
SystemNavigator.pop(); // SystemNavigator.pop();
} // }
}); // });
notifyListeners(); // notifyListeners();
} // }
} }