Initial commit
This commit is contained in:
@ -0,0 +1,111 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rfid_app/app/themes/app_colors.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../../../../app/themes/app_text.dart';
|
||||
import '../../../../../model/penyewa_model.dart';
|
||||
import './detail_log_history_view_model.dart';
|
||||
|
||||
class DetailLogHistoryView extends StatelessWidget {
|
||||
final SheetRequest<PenyewaModel> request;
|
||||
final Function(SheetResponse) completer;
|
||||
|
||||
const DetailLogHistoryView({
|
||||
super.key,
|
||||
required SheetRequest request,
|
||||
required this.completer,
|
||||
}) : request = request as SheetRequest<PenyewaModel>;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<DetailLogHistoryViewModel>.reactive(
|
||||
viewModelBuilder: () => DetailLogHistoryViewModel(),
|
||||
onViewModelReady: (DetailLogHistoryViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
DetailLogHistoryViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return SafeArea(
|
||||
child: Container(
|
||||
// alignment: Alignment.topCenter,
|
||||
width: double.infinity,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
margin: const EdgeInsets.all(5),
|
||||
padding: const EdgeInsets.all(25),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Center(child: Text(request.data!.jenis!, style: boldTextStyle)),
|
||||
const Divider(
|
||||
color: mainGrey,
|
||||
thickness: 1,
|
||||
),
|
||||
_RowDetail(
|
||||
title: 'Nama',
|
||||
value: request.data!.nama!,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_RowDetail(
|
||||
title: 'Waktu',
|
||||
value: model.otherFunction
|
||||
.formatDateString2(request.data!.date!),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_RowDetail(
|
||||
title: 'Keterangan',
|
||||
value: request.data!.ket!,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RowDetail extends StatelessWidget {
|
||||
const _RowDetail({
|
||||
required this.title,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
title,
|
||||
style: boldTextStyle,
|
||||
),
|
||||
),
|
||||
const Expanded(
|
||||
flex: 1,
|
||||
child: Text(':'),
|
||||
),
|
||||
Expanded(
|
||||
flex: 7,
|
||||
child: Text(
|
||||
value,
|
||||
style: italicTextStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
import 'package:rfid_app/app/core/custom_base_view_model.dart';
|
||||
|
||||
class DetailLogHistoryViewModel extends CustomBaseViewModel {
|
||||
Future<void> init() async {}
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
import '../../../../app/themes/app_text.dart';
|
||||
import './log_history_sewaan_view_model.dart';
|
||||
|
||||
class LogHistorySewaanView extends StatelessWidget {
|
||||
const LogHistorySewaanView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<LogHistorySewaanViewModel>.reactive(
|
||||
viewModelBuilder: () => LogHistorySewaanViewModel(),
|
||||
onViewModelReady: (LogHistorySewaanViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
LogHistorySewaanViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: mainGrey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset:
|
||||
const Offset(0, 3), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: model.logHistorySewaanList == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15, vertical: 10),
|
||||
itemCount: model.logHistorySewaanList!.length,
|
||||
itemBuilder: (context, index) {
|
||||
// model.log
|
||||
// .i(model.logHistorySewaanList![index].date);
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
// model.log.i('clicked on index $index');
|
||||
model.checkKet(
|
||||
model.logHistorySewaanList![index],
|
||||
);
|
||||
},
|
||||
child: Card(
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
model.logHistorySewaanList![index].jenis!,
|
||||
style:
|
||||
boldTextStyle.copyWith(fontSize: 15),
|
||||
),
|
||||
subtitle: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Penyewa : ${model.logHistorySewaanList![index].nama}',
|
||||
style: regularTextStyle,
|
||||
),
|
||||
// Text(
|
||||
// model.logHistorySewaanList![index]
|
||||
// .jenis!,
|
||||
// style: italicTextStyle,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
// dummy date and time
|
||||
trailing: Text(
|
||||
model.otherFunction.formatDateString(model
|
||||
.logHistorySewaanList![index].date!),
|
||||
style: boldTextStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
import '../../../../app/app.bottomsheets.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../model/my_response_model.dart';
|
||||
import '../../../../model/penyewa_model.dart';
|
||||
|
||||
class LogHistorySewaanViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('LogHistorySewaanViewModel');
|
||||
List<PenyewaModel>? logHistorySewaanList;
|
||||
|
||||
Future<void> init() async {
|
||||
log.d('init log history sewaan');
|
||||
await getData();
|
||||
}
|
||||
|
||||
getData() async {
|
||||
try {
|
||||
var response = await httpService.get('scan/log');
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
logHistorySewaanList = [];
|
||||
myResponseModel.data.forEach((item) {
|
||||
PenyewaModel penyewa = PenyewaModel.fromJson(item);
|
||||
logHistorySewaanList!.add(penyewa);
|
||||
log.d(penyewa);
|
||||
});
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
// snackbarService.showSnackbar(message: 'Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
checkKet(PenyewaModel penyewaModel) async {
|
||||
await bottomSheetService.showCustomSheet(
|
||||
variant: BottomSheetType.detailLogHistoryView,
|
||||
data: penyewaModel,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
import 'package:validatorless/validatorless.dart';
|
||||
|
||||
import '../../../../../app/themes/app_colors.dart';
|
||||
import '../../../../../model/penyewa_model.dart';
|
||||
import '../../../../widgets/my_button.dart';
|
||||
import '../../../../widgets/my_textformfield.dart';
|
||||
import './edit_penyewa_dialog_view_model.dart';
|
||||
|
||||
class EditPenyewaDialogView extends StatelessWidget {
|
||||
final DialogRequest<DetailPenyewaModel> request;
|
||||
final Function(DialogResponse) completer;
|
||||
const EditPenyewaDialogView({
|
||||
super.key,
|
||||
required DialogRequest request,
|
||||
required this.completer,
|
||||
}) : request = request as DialogRequest<DetailPenyewaModel>;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<EditPenyewaDialogViewModel>.reactive(
|
||||
viewModelBuilder: () => EditPenyewaDialogViewModel(),
|
||||
onViewModelReady: (EditPenyewaDialogViewModel model) async {
|
||||
await model.init(request.data);
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
EditPenyewaDialogViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Dialog(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: backgroundColor,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Text("NIK"),
|
||||
MyTextFormField(
|
||||
controller: model.nikController,
|
||||
hintText: 'Masukkan NIK Penyewa',
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 16,
|
||||
validator: Validatorless.multiple(
|
||||
[
|
||||
Validatorless.required('NIK harus diisi'),
|
||||
Validatorless.min(16, 'NIK harus 16 digit'),
|
||||
Validatorless.max(16, 'NIK harus 16 digit'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Text("Nama"),
|
||||
MyTextFormField(
|
||||
controller: model.nameController,
|
||||
hintText: 'Masukkan Nama Penyewa',
|
||||
validator: Validatorless.required('Nama harus diisi'),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
MyButton(
|
||||
text: 'Update Data',
|
||||
onPressed: () {
|
||||
if (request.data!.nik == model.nikController.text &&
|
||||
request.data!.nama == model.nameController.text) {
|
||||
model.snackbarService.showSnackbar(
|
||||
message: 'Tidak ada perubahan',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
model.dialogService
|
||||
.showDialog(
|
||||
title: 'Konfirmasi',
|
||||
description: 'Apakah anda yakin ingin mengupdate data?',
|
||||
cancelTitle: 'Batal',
|
||||
buttonTitle: 'Update',
|
||||
// confirmationTitle: 'Update',
|
||||
)
|
||||
.then((value) async {
|
||||
if (value!.confirmed) {
|
||||
bool res = await model.updateData(request.data!.nik);
|
||||
// model.log.i("ini res: $res");
|
||||
if (res) {
|
||||
completer(DialogResponse(confirmed: true));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../app/app.logger.dart';
|
||||
import '../../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../../model/penyewa_model.dart';
|
||||
|
||||
class EditPenyewaDialogViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('EditPenyewaDialogViewModel');
|
||||
|
||||
TextEditingController nikController = TextEditingController();
|
||||
TextEditingController nameController = TextEditingController();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
Future<void> init(DetailPenyewaModel? data) async {
|
||||
log.d('init edit penyewa dialog');
|
||||
nikController.text = data!.nik!;
|
||||
nameController.text = data.nama!;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> updateData(String? nik) async {
|
||||
try {
|
||||
easyLoading.customLoading('Updating Data...');
|
||||
// delay 2 seconds
|
||||
// await Future.delayed(const Duration(seconds: 2));
|
||||
var formData = FormData.fromMap({
|
||||
'nik_baru': nikController.text,
|
||||
'nama': nameController.text,
|
||||
});
|
||||
await httpService.putWithFormData('scan/penyewa/$nik', formData);
|
||||
return true;
|
||||
} catch (e) {
|
||||
log.d(e);
|
||||
return false;
|
||||
} finally {
|
||||
easyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,189 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
import '../../../../app/themes/app_text.dart';
|
||||
import './penyewa_list_view_model.dart';
|
||||
|
||||
class PenyewaListView extends StatelessWidget {
|
||||
const PenyewaListView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<PenyewaListViewModel>.reactive(
|
||||
viewModelBuilder: () => PenyewaListViewModel(),
|
||||
onViewModelReady: (PenyewaListViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
PenyewaListViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: mainGrey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset:
|
||||
const Offset(0, 3), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Total',
|
||||
style: regularTextStyle.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'2 orang',
|
||||
style: regularTextStyle.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: mainGrey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset:
|
||||
const Offset(0, 3), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: model.penyewaList == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15, vertical: 10),
|
||||
itemCount: model.penyewaList!.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text(model.penyewaList![index].nama!,
|
||||
style: boldTextStyle.copyWith(
|
||||
fontSize: 13)),
|
||||
subtitle: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Card ID: ${model.penyewaList![index].rfid!}',
|
||||
style: regularTextStyle.copyWith(
|
||||
fontSize: 12)),
|
||||
Text(
|
||||
'Saldo: Rp. ${model.otherFunction.commaFormat(model.penyewaList![index].saldo!)}',
|
||||
style: regularTextStyle.copyWith(
|
||||
fontSize: 12)),
|
||||
],
|
||||
),
|
||||
// circle avatar
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await model.topUp(
|
||||
model.penyewaList![index]);
|
||||
},
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius:
|
||||
BorderRadius.circular(30),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.add_card_outlined,
|
||||
color: Colors.white,
|
||||
size: 15,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
GestureDetector(
|
||||
onTap: () => model.snackbarService
|
||||
.showSnackbar(
|
||||
message:
|
||||
'Fitur sedang dalam tahap pengembangan'),
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius:
|
||||
BorderRadius.circular(30),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.list_alt,
|
||||
color: Colors.white,
|
||||
size: 15,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
GestureDetector(
|
||||
onTap: () async =>
|
||||
model.editPenyewaDialog(
|
||||
model.penyewaList![index]),
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius:
|
||||
BorderRadius.circular(30),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.edit_document,
|
||||
color: Colors.white,
|
||||
size: 15,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
)),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
import '../../../../app/app.dialogs.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../model/my_response_model.dart';
|
||||
import '../../../../model/penyewa_model.dart';
|
||||
|
||||
class PenyewaListViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('PenyewaListViewModel');
|
||||
List<DetailPenyewaModel>? penyewaList;
|
||||
Future<void> init() async {
|
||||
log.d('init');
|
||||
await getData();
|
||||
}
|
||||
|
||||
getData() async {
|
||||
try {
|
||||
var response = await httpService.get('scan/penyewa');
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
penyewaList = [];
|
||||
myResponseModel.data.forEach((item) {
|
||||
DetailPenyewaModel detailPenyewa = DetailPenyewaModel.fromJson(item);
|
||||
penyewaList!.add(detailPenyewa);
|
||||
log.d(detailPenyewa);
|
||||
});
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
log.d(e);
|
||||
// snackbarService.showSnackbar(message: 'Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
topUp(DetailPenyewaModel detailPenyewaModel) async {
|
||||
var res = await dialogService.showCustomDialog(
|
||||
variant: DialogType.topUpSaldoView,
|
||||
data: detailPenyewaModel,
|
||||
title: 'Top Up Kartu Retributor',
|
||||
);
|
||||
|
||||
if (res != null && res.confirmed) {
|
||||
snackbarService.showSnackbar(message: res.data);
|
||||
await getData();
|
||||
}
|
||||
}
|
||||
|
||||
editPenyewaDialog(DetailPenyewaModel detailPenyewaModel) async {
|
||||
var res = await dialogService.showCustomDialog(
|
||||
variant: DialogType.editPenyewaDialogView,
|
||||
data: detailPenyewaModel,
|
||||
// title: 'Edit Penyewa',
|
||||
);
|
||||
|
||||
if (res!.confirmed) {
|
||||
snackbarService.showSnackbar(message: 'Berhasil mengupdate data');
|
||||
await getData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../../../../app/themes/app_colors.dart';
|
||||
import '../../../../../app/themes/app_text.dart';
|
||||
import '../../../../../model/penyewa_model.dart';
|
||||
import '../../scan_rfid_dialog/scan_rfid_dialog_view.dart';
|
||||
import './top_up_saldo_view_model.dart';
|
||||
|
||||
class TopUpSaldoView extends StatelessWidget {
|
||||
final DialogRequest<DetailPenyewaModel> request;
|
||||
final Function(DialogResponse) completer;
|
||||
const TopUpSaldoView({
|
||||
super.key,
|
||||
required DialogRequest request,
|
||||
required this.completer,
|
||||
}) : request = request as DialogRequest<DetailPenyewaModel>;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<TopUpSaldoViewModel>.reactive(
|
||||
viewModelBuilder: () => TopUpSaldoViewModel(),
|
||||
onViewModelReady: (TopUpSaldoViewModel model) async {
|
||||
await model.init(request.data);
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
TopUpSaldoViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Dialog(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: backgroundColor,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
request.title!,
|
||||
style: boldTextStyle.copyWith(
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
color: greyBlueColor,
|
||||
thickness: 1,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
DetailRow(
|
||||
title: 'Nama',
|
||||
value: request.data!.nama ?? '...',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
DetailRow(
|
||||
title: 'Card ID',
|
||||
value: request.data!.rfid ?? '...',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
DetailRow(
|
||||
title: 'Saldo',
|
||||
value:
|
||||
'Rp. ${model.otherFunction.commaFormat(request.data!.saldo ?? 0)}',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
border: Border.all(
|
||||
color: mainColor,
|
||||
),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<int>(
|
||||
value: model.topUpValue,
|
||||
onChanged: (int? newValue) {
|
||||
// model.log.d('newValue: $newValue');
|
||||
model.topUpValue = newValue!;
|
||||
model.notifyListeners();
|
||||
},
|
||||
items: model.topUpList.map((Map<String, dynamic> value) {
|
||||
// model.log.d('value: $value');
|
||||
return DropdownMenuItem<int>(
|
||||
value: value['value'],
|
||||
child: Text(
|
||||
value['title'].toString(),
|
||||
style: regularTextStyle.copyWith(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 200,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
String? message = await model.topUpSaldo();
|
||||
|
||||
if (message != null) {
|
||||
completer(DialogResponse(
|
||||
confirmed: true,
|
||||
data: message,
|
||||
));
|
||||
}
|
||||
},
|
||||
child: const Text('TopUp Saldo'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:rfid_app/model/my_response_model.dart';
|
||||
|
||||
import '../../../../../app/app.logger.dart';
|
||||
import '../../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../../model/penyewa_model.dart';
|
||||
|
||||
class TopUpSaldoViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('TopUpSaldoViewModel');
|
||||
|
||||
DetailPenyewaModel? detailPenyewaModel;
|
||||
|
||||
List<Map<String, dynamic>> topUpList = [
|
||||
{'title': 'Rp. 50.000', 'value': 50000},
|
||||
{'title': 'Rp. 75.000', 'value': 75000},
|
||||
{'title': 'Rp. 100.000', 'value': 100000},
|
||||
{'title': 'Rp. 200.000', 'value': 200000},
|
||||
];
|
||||
|
||||
int topUpValue = 50000;
|
||||
|
||||
Future<void> init(DetailPenyewaModel? data) async {
|
||||
log.d(data);
|
||||
|
||||
detailPenyewaModel = data;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<String?> topUpSaldo() async {
|
||||
log.i('ini topUpValue: $topUpValue');
|
||||
try {
|
||||
var formData = FormData.fromMap({
|
||||
'topup': topUpValue,
|
||||
});
|
||||
|
||||
var response = await httpService.postWithFormData(
|
||||
'scan/penyewa/${detailPenyewaModel!.nik}', formData);
|
||||
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
|
||||
return myResponseModel.message;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
// snackbarService.showSnackbar(message: 'Error: $e');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
100
lib/ui/views/retributor_index/retributor_index_view.dart
Normal file
100
lib/ui/views/retributor_index/retributor_index_view.dart
Normal file
@ -0,0 +1,100 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
import 'package:stylish_bottom_bar/model/bar_items.dart';
|
||||
import 'package:stylish_bottom_bar/stylish_bottom_bar.dart';
|
||||
|
||||
import '../../../app/app.router.dart';
|
||||
import '../../../app/themes/app_colors.dart';
|
||||
import '../../../app/themes/app_text.dart';
|
||||
import './retributor_index_view_model.dart';
|
||||
|
||||
class RetributorIndexView extends StatelessWidget {
|
||||
const RetributorIndexView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<RetributorIndexViewModel>.reactive(
|
||||
viewModelBuilder: () => RetributorIndexViewModel(),
|
||||
onViewModelReady: (RetributorIndexViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
RetributorIndexViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
return false;
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
model.header,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
backgroundColor: mainColor,
|
||||
elevation: 0,
|
||||
automaticallyImplyLeading: false,
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
model.logout();
|
||||
},
|
||||
icon: const Icon(Icons.logout, color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
|
||||
child: ExtendedNavigator(
|
||||
navigatorKey: StackedService.nestedNavigationKey(3),
|
||||
router: RetributorIndexViewRouter(),
|
||||
initialRoute: RetributorIndexViewRoutes.tempatSewaListView,
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: StylishBottomBar(
|
||||
items: [
|
||||
for (var item in model.bottomNavBarList)
|
||||
BottomBarItem(
|
||||
icon: Icon(item['icon'],
|
||||
color: model.currentIndex ==
|
||||
model.bottomNavBarList.indexOf(item)
|
||||
? sixthGrey
|
||||
: backgroundColor),
|
||||
title: Text(
|
||||
item['name'],
|
||||
style: regularTextStyle.copyWith(
|
||||
color: model.currentIndex ==
|
||||
model.bottomNavBarList.indexOf(item)
|
||||
? sixthGrey
|
||||
: mainGrey,
|
||||
),
|
||||
),
|
||||
backgroundColor: model.currentIndex ==
|
||||
model.bottomNavBarList.indexOf(item)
|
||||
? fontColor
|
||||
: mainGrey,
|
||||
),
|
||||
],
|
||||
currentIndex: model.currentIndex,
|
||||
hasNotch: true,
|
||||
backgroundColor: mainColor,
|
||||
onTap: (value) {
|
||||
model.handleNavigation(value);
|
||||
},
|
||||
option: BubbleBarOptions(
|
||||
barStyle: BubbleBarStyle.horizotnal,
|
||||
bubbleFillStyle: BubbleFillStyle.fill,
|
||||
opacity: 0.3),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
105
lib/ui/views/retributor_index/retributor_index_view_model.dart
Normal file
105
lib/ui/views/retributor_index/retributor_index_view_model.dart
Normal file
@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../../app/app.dialogs.dart';
|
||||
import '../../../app/app.locator.dart';
|
||||
import '../../../app/app.logger.dart';
|
||||
import '../../../app/app.router.dart';
|
||||
import '../../../services/my_socket_io_client.dart';
|
||||
import '../../../services/shared_prefs.dart';
|
||||
|
||||
class RetributorIndexViewModel extends IndexTrackingViewModel {
|
||||
final log = getLogger('RetributorIndexViewModel');
|
||||
final _navigationService = locator<NavigationService>();
|
||||
final socketIoClient = locator<MySocketIoClient>();
|
||||
final dialogService = locator<DialogService>();
|
||||
final snackbarService = locator<SnackbarService>();
|
||||
final mySharedPrefs = locator<MySharedPrefs>();
|
||||
|
||||
final _bottomNavBarList = [
|
||||
{
|
||||
'name': 'Tempat Sewa',
|
||||
'icon': Icons.home_outlined,
|
||||
'header': 'List Tempat Sewa',
|
||||
},
|
||||
{
|
||||
'name': 'History Sewaan',
|
||||
'icon': Icons.work_history_outlined,
|
||||
'header': 'Log History Sewaan',
|
||||
},
|
||||
{
|
||||
'name': 'List Penyewa',
|
||||
'icon': Icons.people_outlined,
|
||||
'header': 'List Penyewa',
|
||||
},
|
||||
];
|
||||
|
||||
List<Map<String, dynamic>> get bottomNavBarList => _bottomNavBarList;
|
||||
|
||||
final List<String> _views = [
|
||||
RetributorIndexViewRoutes.tempatSewaListView,
|
||||
RetributorIndexViewRoutes.logHistorySewaanView,
|
||||
RetributorIndexViewRoutes.penyewaListView,
|
||||
];
|
||||
|
||||
String header = 'List Tempat Sewa';
|
||||
|
||||
String? level;
|
||||
|
||||
Future<void> init() async {
|
||||
// socketIoClient.on('connect', (data) => log.i('connected'));
|
||||
level = await mySharedPrefs.getString('level');
|
||||
if (level != 'retributor') {
|
||||
snackbarService.showSnackbar(
|
||||
message: 'Hanya Retributor yang dapat mengakses halaman ini',
|
||||
);
|
||||
_navigationService.navigateTo(Routes.loginScreenView);
|
||||
return;
|
||||
}
|
||||
|
||||
socketIoClient.on('scan', (data) async {
|
||||
var res = await dialogService.showCustomDialog(
|
||||
variant: DialogType.scanRfidDialogView,
|
||||
title: 'Pembayaran Retribusi',
|
||||
data: data,
|
||||
);
|
||||
|
||||
if (res!.confirmed) {
|
||||
snackbarService.showSnackbar(
|
||||
message: res.data,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void handleNavigation(int index) {
|
||||
log.d("handleNavigation: $index");
|
||||
log.d("currentIndex: $currentIndex");
|
||||
|
||||
if (currentIndex == index) return;
|
||||
|
||||
setIndex(index);
|
||||
header = _bottomNavBarList[index]['header'] as String;
|
||||
_navigationService.navigateTo(
|
||||
_views[index],
|
||||
id: 3,
|
||||
);
|
||||
}
|
||||
|
||||
logout() async {
|
||||
dialogService
|
||||
.showConfirmationDialog(
|
||||
title: 'Konfirmasi',
|
||||
description: 'Apakah anda yakin ingin keluar?',
|
||||
cancelTitle: 'Batal',
|
||||
confirmationTitle: 'Keluar',
|
||||
)
|
||||
.then((value) async {
|
||||
if (value!.confirmed) {
|
||||
await mySharedPrefs.clear();
|
||||
_navigationService.clearStackAndShow(Routes.loginScreenView);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,184 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rfid_app/model/penyewa_model.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
import '../../../../app/themes/app_text.dart';
|
||||
import './scan_rfid_dialog_view_model.dart';
|
||||
|
||||
class ScanRfidDialogView extends StatelessWidget {
|
||||
final DialogRequest request;
|
||||
final Function(DialogResponse) completer;
|
||||
|
||||
const ScanRfidDialogView({
|
||||
super.key,
|
||||
required this.request,
|
||||
required this.completer,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<ScanRfidDialogViewModel>.reactive(
|
||||
viewModelBuilder: () => ScanRfidDialogViewModel(),
|
||||
onViewModelReady: (ScanRfidDialogViewModel model) async {
|
||||
await model.init(request.data);
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
ScanRfidDialogViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Dialog(
|
||||
child: Container(
|
||||
// alignment: Alignment.center,
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: backgroundColor,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: Text(
|
||||
request.title!,
|
||||
style: regularTextStyle.copyWith(
|
||||
fontSize: 20,
|
||||
// color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
// const SizedBox(height: 10),
|
||||
// create line
|
||||
const Divider(
|
||||
color: greyBlueColor,
|
||||
thickness: 1,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
DetailRow(title: 'nama', value: model.nama ?? '...'),
|
||||
const SizedBox(height: 5),
|
||||
DetailRow(title: 'Card id', value: model.cardId ?? '...'),
|
||||
const SizedBox(height: 5),
|
||||
DetailRow(title: 'Saldo', value: model.saldo ?? '...'),
|
||||
const SizedBox(height: 10),
|
||||
const Text(' Pilih tempat retribusi', style: regularTextStyle),
|
||||
model.penyewaList.isEmpty
|
||||
? Container()
|
||||
: Container(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
border: Border.all(
|
||||
color: mainColor,
|
||||
),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: model.idTempatSerwa.toString(),
|
||||
onChanged: (String? newValue) {
|
||||
model.log.d('newValue: $newValue');
|
||||
model.idTempatSerwa = int.parse(newValue!);
|
||||
model.notifyListeners();
|
||||
},
|
||||
items: model.penyewaList.map((PenyewaModel value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value.idTempatSerwa.toString(),
|
||||
child: Text(
|
||||
value.namaTempatSewa.toString(),
|
||||
style: regularTextStyle.copyWith(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 200,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
// String? message = await model.bayar();
|
||||
|
||||
// if (message != null) {
|
||||
// completer(DialogResponse(
|
||||
// confirmed: true,
|
||||
// data: message,
|
||||
// ));
|
||||
// }
|
||||
PenyewaModel penyewa = model.penyewaList.firstWhere(
|
||||
(element) =>
|
||||
element.idTempatSerwa == model.idTempatSerwa);
|
||||
|
||||
model.dialogService
|
||||
.showDialog(
|
||||
title: 'Bayar?',
|
||||
description:
|
||||
'${model.nama} dengan Card ID ${model.cardId} akan membayar retribusi ${penyewa.namaTempatSewa} sebanyak Rp. ${model.otherFunction.commaFormat(penyewa.hargaSewa!)} per bulan sekarang?',
|
||||
cancelTitle: 'Batal',
|
||||
)
|
||||
.then((res) async {
|
||||
if (res!.confirmed) {
|
||||
String? message = await model.bayar(penyewa);
|
||||
if (message != null) {
|
||||
completer(DialogResponse(
|
||||
confirmed: true,
|
||||
data: message,
|
||||
));
|
||||
}
|
||||
// completer(DialogResponse(
|
||||
// confirmed: true,
|
||||
// ));
|
||||
}
|
||||
});
|
||||
},
|
||||
child: const Text('Bayar'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DetailRow extends StatelessWidget {
|
||||
const DetailRow({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(title),
|
||||
),
|
||||
const Expanded(
|
||||
flex: 1,
|
||||
child: Text(':'),
|
||||
),
|
||||
Expanded(
|
||||
flex: 8,
|
||||
child: Text(value),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:rfid_app/app/core/custom_base_view_model.dart';
|
||||
import 'package:rfid_app/model/my_response_model.dart';
|
||||
import 'package:rfid_app/model/penyewa_model.dart';
|
||||
|
||||
import '../../../../app/app.logger.dart';
|
||||
|
||||
class ScanRfidDialogViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('ScanRfidDialogViewModel');
|
||||
String? nama;
|
||||
String? cardId;
|
||||
String? saldo;
|
||||
List<PenyewaModel> penyewaList = [];
|
||||
|
||||
int? idTempatSerwa;
|
||||
|
||||
Future<void> init(data) async {
|
||||
log.d('init');
|
||||
|
||||
getData(data);
|
||||
}
|
||||
|
||||
getData(String data) async {
|
||||
try {
|
||||
var respose = await httpService.get('scan/id/$data');
|
||||
// log.d(respose.data);
|
||||
MyResponseModel response = MyResponseModel.fromJson(respose.data);
|
||||
|
||||
response.data.forEach((item) {
|
||||
PenyewaModel penyewa = PenyewaModel.fromJson(item);
|
||||
// log.d(penyewa);
|
||||
penyewaList.add(penyewa);
|
||||
});
|
||||
log.d(penyewaList);
|
||||
nama = penyewaList[0].nama;
|
||||
cardId = penyewaList[0].rfid;
|
||||
saldo = 'Rp. ${otherFunction.commaFormat(penyewaList[0].saldo ?? 0)}';
|
||||
idTempatSerwa = penyewaList[0].idTempatSerwa;
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
// snackbarService.showSnackbar(message: 'Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> bayar(PenyewaModel penyewa) async {
|
||||
try {
|
||||
var formData = FormData.fromMap({
|
||||
'nik': penyewa.nik,
|
||||
'rfid': cardId,
|
||||
'id_tempat_sewa': idTempatSerwa,
|
||||
});
|
||||
var respose = await httpService.postWithFormData('scan/bayar', formData);
|
||||
MyResponseModel response = MyResponseModel.fromJson(respose.data);
|
||||
return response.message;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
return null;
|
||||
} finally {
|
||||
easyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
import 'package:validatorless/validatorless.dart';
|
||||
|
||||
import '../../../../../app/themes/app_colors.dart';
|
||||
import '../../../../../model/penyewa_model.dart';
|
||||
import '../../../../widgets/my_button.dart';
|
||||
import '../../../../widgets/my_textformfield.dart';
|
||||
import './edit_tempat_sewa_dialog_view_model.dart';
|
||||
|
||||
class EditTempatSewaDialogView extends StatelessWidget {
|
||||
final DialogRequest<PenyewaModel> request;
|
||||
final Function(DialogResponse) completer;
|
||||
|
||||
const EditTempatSewaDialogView(
|
||||
{super.key, required DialogRequest request, required this.completer})
|
||||
: request = request as DialogRequest<PenyewaModel>;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<EditTempatSewaDialogViewModel>.reactive(
|
||||
viewModelBuilder: () => EditTempatSewaDialogViewModel(),
|
||||
onViewModelReady: (EditTempatSewaDialogViewModel model) async {
|
||||
await model.init(request.data);
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
EditTempatSewaDialogViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Dialog(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: backgroundColor,
|
||||
),
|
||||
child: Form(
|
||||
key: model.formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Text("Tempat Sewa"),
|
||||
MyTextFormField(
|
||||
controller: model.tempatSewaController,
|
||||
hintText: 'Masukkan Tempat Sewa',
|
||||
validator:
|
||||
Validatorless.required('Tempat Sewa harus diisi'),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Text("Sewa / Bulan (Rp.)"),
|
||||
MyTextFormField(
|
||||
controller: model.sewaBulanController,
|
||||
hintText: 'Masukkan Jumlah Sewa / Bulan',
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 5,
|
||||
validator: Validatorless.required(
|
||||
'Jumlah Sewa / Bulan harus diisi',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
MyButton(
|
||||
text: 'Update Detail',
|
||||
onPressed: () async {
|
||||
if (model.tempatSewaController.text ==
|
||||
request.data!.namaTempatSewa &&
|
||||
model.sewaBulanController.text ==
|
||||
request.data!.hargaSewa.toString()) {
|
||||
model.snackbarService.showSnackbar(
|
||||
message: 'Tidak ada perubahan yang dilakukan',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
model.dialogService
|
||||
.showDialog(
|
||||
title: 'Edit Tempat Sewa',
|
||||
description:
|
||||
'Apakah anda yakin ingin mengedit detail tempat sewa?',
|
||||
buttonTitle: 'Edit',
|
||||
cancelTitle: 'Batal',
|
||||
)
|
||||
.then((value) async {
|
||||
bool result = await model
|
||||
.updateTempatSewa(request.data!.idTempatSerwa);
|
||||
// model.log.i("ini result: $result");
|
||||
if (result) {
|
||||
completer(DialogResponse(confirmed: true));
|
||||
}
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rfid_app/model/penyewa_model.dart';
|
||||
|
||||
import '../../../../../app/app.logger.dart';
|
||||
import '../../../../../app/core/custom_base_view_model.dart';
|
||||
|
||||
class EditTempatSewaDialogViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('EditTempatSewaDialogViewModel');
|
||||
TextEditingController tempatSewaController = TextEditingController();
|
||||
TextEditingController sewaBulanController = TextEditingController();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
Future<void> init(PenyewaModel? data) async {
|
||||
log.d('init edit tempat sewa dialog');
|
||||
tempatSewaController.text = data!.namaTempatSewa!;
|
||||
sewaBulanController.text = data.hargaSewa!.toString();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> updateTempatSewa(int? idTempatSerwa) async {
|
||||
String tempatSewa = tempatSewaController.text;
|
||||
String sewaBulan = sewaBulanController.text;
|
||||
|
||||
try {
|
||||
var formData = FormData.fromMap({
|
||||
'nama_tempat_sewa': tempatSewa,
|
||||
'harga_sewa': int.parse(sewaBulan),
|
||||
});
|
||||
easyLoading.customLoading('Updating...');
|
||||
await httpService.putWithFormData(
|
||||
'scan/tempat_sewa/$idTempatSerwa', formData);
|
||||
return true;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
return false;
|
||||
} finally {
|
||||
easyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,170 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
import '../../../../app/themes/app_text.dart';
|
||||
import './tempat_sewa_list_view_model.dart';
|
||||
|
||||
class TempatSewaListView extends StatelessWidget {
|
||||
const TempatSewaListView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<TempatSewaListViewModel>.reactive(
|
||||
viewModelBuilder: () => TempatSewaListViewModel(),
|
||||
onViewModelReady: (TempatSewaListViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
TempatSewaListViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: mainGrey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset:
|
||||
const Offset(0, 3), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Total Tempat Retribusi',
|
||||
style: regularTextStyle.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
model.tempatSewaList?.length.toString() ?? '...',
|
||||
style: regularTextStyle.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: mainGrey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset:
|
||||
const Offset(0, 3), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: model.tempatSewaList == null
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15, vertical: 10),
|
||||
itemCount: model.tempatSewaList!.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
model
|
||||
.tempatSewaList![index].namaTempatSewa!,
|
||||
style: boldTextStyle.copyWith(
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
subtitle: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Penyewa : ${model.tempatSewaList![index].nama}',
|
||||
),
|
||||
Text(
|
||||
'Harga : Rp. ${model.otherFunction.commaFormat(model.tempatSewaList![index].hargaSewa!)}',
|
||||
),
|
||||
],
|
||||
),
|
||||
// circle avatar
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => model.snackbarService
|
||||
.showSnackbar(
|
||||
message:
|
||||
'Fitur sedang dalam tahap pengembangan'),
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius:
|
||||
BorderRadius.circular(50),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.list_alt_outlined,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
GestureDetector(
|
||||
onTap: () async =>
|
||||
await model.editTempatSewa(
|
||||
model.tempatSewaList![index],
|
||||
),
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius:
|
||||
BorderRadius.circular(50),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.edit_square,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
import '../../../../app/app.dialogs.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../model/my_response_model.dart';
|
||||
import '../../../../model/penyewa_model.dart';
|
||||
|
||||
class TempatSewaListViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('TempatSewaListViewModel');
|
||||
List<PenyewaModel>? tempatSewaList;
|
||||
|
||||
Future<void> init() async {
|
||||
log.d('init tempat sewa list');
|
||||
await getData();
|
||||
}
|
||||
|
||||
getData() async {
|
||||
try {
|
||||
var response = await httpService.get('scan/tempat_sewa');
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
tempatSewaList = [];
|
||||
myResponseModel.data.forEach((item) {
|
||||
PenyewaModel penyewa = PenyewaModel.fromJson(item);
|
||||
tempatSewaList!.add(penyewa);
|
||||
log.d(penyewa);
|
||||
});
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
// snackbarService.showSnackbar(message: 'Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
editTempatSewa(PenyewaModel penyewaModel) async {
|
||||
var res = await dialogService.showCustomDialog(
|
||||
variant: DialogType.editTempatSewaDialogView,
|
||||
data: penyewaModel,
|
||||
);
|
||||
log.i("ini res: ${res!.confirmed}");
|
||||
if (res.confirmed) {
|
||||
snackbarService.showSnackbar(message: 'Berhasil Update Data');
|
||||
getData();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user