modify reservation table page, add socket io client for real time data update, modify makanan list page
This commit is contained in:
@ -85,9 +85,18 @@ class MejaDetailView extends StatelessWidget {
|
||||
style: regularTextStyle,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: 'Tersedia',
|
||||
text: model.theBool
|
||||
? (model.reservasiMejaModel == null
|
||||
? 'Loading'
|
||||
: model.reservasiMejaModel!.status!
|
||||
.toUpperCase())
|
||||
: 'Tersedia',
|
||||
style: regularTextStyle.copyWith(
|
||||
color: Colors.green,
|
||||
color: model.theBool
|
||||
? (model.reservasiMejaModel == null
|
||||
? Colors.grey
|
||||
: Colors.red)
|
||||
: Colors.green,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@ -146,10 +155,14 @@ class MejaDetailView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
if (model.theBool == false) {
|
||||
model.showReservasiMeja();
|
||||
}
|
||||
},
|
||||
label: const Text('Pesan'),
|
||||
icon: const Icon(Icons.add_shopping_cart),
|
||||
backgroundColor: mainColor,
|
||||
backgroundColor: mainColor.withOpacity(model.theBool ? 0.5 : 1),
|
||||
),
|
||||
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
|
||||
floatingActionButtonLocation:
|
||||
|
||||
@ -1,17 +1,24 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:reza_app/model/reservasi_meja_model.dart';
|
||||
|
||||
import '../../../app/app.logger.dart';
|
||||
import '../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../model/my_model.dart';
|
||||
|
||||
class MejaDetailViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('MejaDetailViewModel');
|
||||
|
||||
late String mejaId;
|
||||
late String namaMeja;
|
||||
late int idMeja;
|
||||
|
||||
String? imgAsset;
|
||||
bool theBool = false;
|
||||
ReservasiMejaModel? reservasiMejaModel;
|
||||
|
||||
Future<void> init(String mejaId) async {
|
||||
log.i('MejaDetailViewModel init');
|
||||
log.i('mejaId : $mejaId');
|
||||
// log.i('MejaDetailViewModel init');
|
||||
// log.i('mejaId : $mejaId');
|
||||
this.mejaId = mejaId;
|
||||
globalVar.backPressed = 'backNormal';
|
||||
// seperate the number from the string
|
||||
@ -27,9 +34,76 @@ class MejaDetailViewModel extends CustomBaseViewModel {
|
||||
namaMeja = 'Meja';
|
||||
imgAsset = 'assets/reza_meja_2.jpeg';
|
||||
}
|
||||
idMeja = number;
|
||||
|
||||
namaMeja = '$namaMeja $number';
|
||||
|
||||
log.i('imgAsset : $imgAsset');
|
||||
// log.i('imgAsset : $imgAsset');
|
||||
getData();
|
||||
}
|
||||
|
||||
getData() async {
|
||||
easyLoading.showLoading();
|
||||
setBusy(true);
|
||||
try {
|
||||
var response = await httpService.get('table/detail/$idMeja');
|
||||
log.i('response : $response');
|
||||
MyModel myModel = MyModel.fromJson(response.data);
|
||||
theBool = myModel.theBool!;
|
||||
|
||||
reservasiMejaModel =
|
||||
theBool ? ReservasiMejaModel.fromJson(myModel.data) : null;
|
||||
|
||||
log.i('reservasiMejaModel : $reservasiMejaModel');
|
||||
} catch (e) {
|
||||
log.e('error : $e');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
easyLoading.dismissLoading();
|
||||
}
|
||||
}
|
||||
|
||||
showReservasiMeja() async {
|
||||
await dialogService
|
||||
.showDialog(
|
||||
title: 'Reservasi Meja',
|
||||
description: 'Apakah anda ingin reservasi meja ini?',
|
||||
buttonTitle: 'Ya',
|
||||
cancelTitle: 'Tidak',
|
||||
)
|
||||
.then((value) {
|
||||
log.i('value : $value');
|
||||
if (value!.confirmed) {
|
||||
reservasiMeja();
|
||||
log.i('confirmed');
|
||||
} else {
|
||||
log.i('not confirmed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reservasiMeja() async {
|
||||
easyLoading.customLoading('Melakukan reservasi meja...');
|
||||
setBusy(true);
|
||||
try {
|
||||
var formData = FormData.fromMap({'id_user': 1, 'status': 'booking'});
|
||||
|
||||
String path = 'table/reservation/$idMeja';
|
||||
|
||||
await httpService.postWithFormData(path, formData);
|
||||
// log.i('res : $res');
|
||||
getData();
|
||||
snackbarService.showSnackbar(
|
||||
message:
|
||||
'Reservasi meja berhasil\nSila Bayar Rp. 20 ribu jika tiba di cafe',
|
||||
title: 'Berhasil',
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
} catch (e) {
|
||||
log.e('error : $e');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
easyLoading.dismissLoading();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user