first commit
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../pengembang_home_view.dart';
|
||||
import './pengembang_home2_view_model.dart';
|
||||
|
||||
class PengembangHome2View extends StatelessWidget {
|
||||
const PengembangHome2View({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<PengembangHome2ViewModel>.reactive(
|
||||
viewModelBuilder: () => PengembangHome2ViewModel(),
|
||||
onViewModelReady: (PengembangHome2ViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
PengembangHome2ViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return const PengembangHomeView();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
import '../../../../../app/core/custom_base_view_model.dart';
|
||||
|
||||
class PengembangHome2ViewModel extends CustomBaseViewModel {
|
||||
Future<void> init() async {}
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
import './pengembang_home_view_model.dart';
|
||||
|
||||
class PengembangHomeView extends StatelessWidget {
|
||||
const PengembangHomeView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<PengembangHomeViewModel>.reactive(
|
||||
viewModelBuilder: () => PengembangHomeViewModel(),
|
||||
onViewModelReady: (PengembangHomeViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
disposeViewModel: false,
|
||||
fireOnViewModelReadyOnce: true,
|
||||
builder: (
|
||||
BuildContext context,
|
||||
PengembangHomeViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Scaffold(
|
||||
body: WillPopScope(
|
||||
onWillPop: () async {
|
||||
// model.log.i('backPressed: ${model.globalVar.backPressed}');
|
||||
if (model.globalVar.backPressed == 'exitApp') {
|
||||
// model.back();
|
||||
model.quitApp(context);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: WebView(
|
||||
// initialUrl: 'http://192.168.43.125/rekam-medis',
|
||||
initialUrl: model.url,
|
||||
javascriptMode: JavascriptMode.unrestricted,
|
||||
onWebViewCreated: (WebViewController webViewController) {
|
||||
// _controller.complete(webViewController);
|
||||
model.webViewControllerCompleter.future
|
||||
.then((value) => model.webVIewcontroller = value);
|
||||
model.webViewControllerCompleter.complete(webViewController);
|
||||
},
|
||||
onProgress: (int progress) {
|
||||
double progressDouble = progress / 100;
|
||||
LinearProgressIndicator(
|
||||
value: progressDouble,
|
||||
);
|
||||
// model.myEasyLoading.showProgress(progressDouble, "Loading Denah");
|
||||
},
|
||||
// javascriptChannels: <JavascriptChannel>{
|
||||
// _toasterJavascriptChannel(context),
|
||||
// },
|
||||
javascriptChannels: <JavascriptChannel>{
|
||||
JavascriptChannel(
|
||||
name: 'messageHandler',
|
||||
onMessageReceived: (JavascriptMessage message) {
|
||||
model.log.d(message.message);
|
||||
// var data = JsonDecoder().convert(message.message);
|
||||
// model.log.d(data['status']);
|
||||
model.goToDetail(message.message);
|
||||
|
||||
// dev.i("message from the web view=\"${message.message}\"");
|
||||
// if (message.message == "coba") {
|
||||
// dev.i("sini untuk coba");
|
||||
// controller.runJavascript("coba22('heheheh')");
|
||||
// }
|
||||
},
|
||||
),
|
||||
},
|
||||
// navigationDelegate: (NavigationRequest request) async {},
|
||||
onPageStarted: (String url) {},
|
||||
onPageFinished: (String url) {
|
||||
// dev.i('Page finished loading: $url');
|
||||
model.easyLoading.dismiss();
|
||||
},
|
||||
|
||||
gestureNavigationEnabled: true,
|
||||
backgroundColor: const Color(0x00000000),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
import '../../../../app/app.bottomsheets.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/app.router.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../model/my_response_model.dart';
|
||||
|
||||
class PengembangHomeViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('PengembangHomeViewModel');
|
||||
|
||||
late String url;
|
||||
late String level;
|
||||
|
||||
late WebViewController webVIewcontroller;
|
||||
final Completer<WebViewController> webViewControllerCompleter =
|
||||
Completer<WebViewController>();
|
||||
|
||||
Future<void> init() async {
|
||||
globalVar.backPressed = "exitApp";
|
||||
url = dotenv.env['url']!;
|
||||
log.d(url);
|
||||
if (Platform.isAndroid) {
|
||||
WebView.platform = SurfaceAndroidWebView();
|
||||
}
|
||||
level = await mySharedPrefs.getString('level') ?? '';
|
||||
log.d('level: $level');
|
||||
if (level == '') {
|
||||
navigationService.clearTillFirstAndShow(Routes.loginScreenView);
|
||||
}
|
||||
}
|
||||
|
||||
goToDetail(String message) async {
|
||||
setBusy(true);
|
||||
easyLoading.customLoading('Loading...');
|
||||
try {
|
||||
var response = await httpService.get('cek_rumah?id=$message');
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
log.i('myResponseModel: ${myResponseModel.res}');
|
||||
if (myResponseModel.res == true) {
|
||||
navigationService.navigateTo(
|
||||
'/perumahan-detail-view',
|
||||
arguments: PerumahanDetailViewArguments(idPerumahan: message),
|
||||
);
|
||||
} else {
|
||||
// easyLoading.showError('Data tidak ditemukan');
|
||||
easyLoading.dismiss();
|
||||
if (level == 'Mandor') {
|
||||
snackbarService.showSnackbar(
|
||||
message: 'Data Rumah Belum Ada',
|
||||
title: 'Gagal',
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
return;
|
||||
}
|
||||
var res = await bottomSheetService.showCustomSheet(
|
||||
variant: BottomSheetType.tambahRumahBottomSheetView,
|
||||
title: 'Form Tambah Pemilik Rumah',
|
||||
data: message,
|
||||
);
|
||||
// res;
|
||||
|
||||
if (res!.confirmed) {
|
||||
webVIewcontroller.reload();
|
||||
snackbarService.showSnackbar(
|
||||
message:
|
||||
'Pemilik Rumah ${res.data.toString().toUpperCase()} berhasil ditambahkan',
|
||||
title: 'Berhasil',
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log.e(e.toString());
|
||||
} finally {
|
||||
setBusy(false);
|
||||
easyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,242 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:omni_datetime_picker/omni_datetime_picker.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 '../../../../../app/themes/app_text.dart';
|
||||
import '../../../../widgets/my_button.dart';
|
||||
import '../../../../widgets/my_textformfield.dart';
|
||||
import './tambah_rumah_bottom_sheet_view_model.dart';
|
||||
|
||||
class TambahRumahBottomSheetView extends StatelessWidget {
|
||||
final SheetRequest? request;
|
||||
final Function(SheetResponse)? completer;
|
||||
|
||||
const TambahRumahBottomSheetView({Key? key, this.request, this.completer})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<TambahRumahBottomSheetViewModel>.reactive(
|
||||
viewModelBuilder: () => TambahRumahBottomSheetViewModel(),
|
||||
onViewModelReady: (TambahRumahBottomSheetViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
TambahRumahBottomSheetViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return SafeArea(
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: const BoxDecoration(
|
||||
color: backgroundColor,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(
|
||||
20,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Form(
|
||||
key: model.globalKey,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Center(
|
||||
child: Text(
|
||||
'${request!.title!} ${request!.data.toString().toUpperCase()}',
|
||||
style: regularTextStyle,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
MyTextFormField(
|
||||
labelText: 'Nama Pemilik Rumah',
|
||||
hintText: 'Masukkan Nama Pemilik Rumah',
|
||||
suffixIcon: const Icon(
|
||||
Icons.person,
|
||||
color: mainColor,
|
||||
),
|
||||
validator: Validatorless.required(
|
||||
'Nama Pemilik Rumah Tidak Boleh Kosong'),
|
||||
controller: model.namaPemilikRumahController,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
MyTextFormField(
|
||||
labelText: 'No. Telp',
|
||||
hintText: 'Masukkan No. Telp',
|
||||
suffixIcon: const Icon(
|
||||
Icons.phone,
|
||||
color: mainColor,
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
validator: Validatorless.multiple(
|
||||
[
|
||||
Validatorless.required('No. Telp Tidak Boleh Kosong'),
|
||||
Validatorless.number('No. Telp Harus Angka'),
|
||||
Validatorless.min(9, 'No. Telp Minimal 10 Angka'),
|
||||
Validatorless.max(13, 'No. Telp Maksimal 13 Angka'),
|
||||
],
|
||||
),
|
||||
controller: model.noHpPemilikRumahController,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
MyTextFormField(
|
||||
labelText: 'Harga Rumah',
|
||||
hintText: 'Masukkan Harga Rumah',
|
||||
keyboardType: TextInputType.number,
|
||||
suffixIcon: const Icon(
|
||||
Icons.attach_money,
|
||||
color: mainColor,
|
||||
),
|
||||
validator: Validatorless.multiple(
|
||||
[
|
||||
Validatorless.required(
|
||||
'Harga Rumah Tidak Boleh Kosong'),
|
||||
Validatorless.number('Harga Rumah Harus Angka'),
|
||||
],
|
||||
),
|
||||
controller: model.hargaRumahController,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
MyTextFormField(
|
||||
labelText: 'Cicilan / Bulan',
|
||||
hintText: 'Masukkan Cicilan / Bulan',
|
||||
keyboardType: TextInputType.number,
|
||||
suffixIcon: const Icon(
|
||||
Icons.attach_money,
|
||||
color: mainColor,
|
||||
),
|
||||
validator: Validatorless.multiple(
|
||||
[
|
||||
Validatorless.required(
|
||||
'Cicilan / Bulan Tidak Boleh Kosong'),
|
||||
Validatorless.number('Cicilan / Bulan Harus Angka'),
|
||||
],
|
||||
),
|
||||
controller: model.bayarPerbulanController,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
MyTextFormField(
|
||||
hintText: "Tanggal Pembelian",
|
||||
labelText: "Tanggal Pembelian",
|
||||
suffixIcon: const Icon(
|
||||
Icons.date_range,
|
||||
color: mainColor,
|
||||
),
|
||||
readOnly: true,
|
||||
controller: model.tglBeliController,
|
||||
onTap: () async {
|
||||
DateTime? dateTime = await showOmniDateTimePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime(1600)
|
||||
.subtract(const Duration(days: 3652)),
|
||||
lastDate: DateTime.now().add(
|
||||
const Duration(days: 3652),
|
||||
),
|
||||
is24HourMode: false,
|
||||
isShowSeconds: false,
|
||||
minutesInterval: 1,
|
||||
secondsInterval: 1,
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(16)),
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: 350,
|
||||
maxHeight: 650,
|
||||
),
|
||||
transitionBuilder: (context, anim1, anim2, child) {
|
||||
return FadeTransition(
|
||||
opacity: anim1.drive(
|
||||
Tween(
|
||||
begin: 0,
|
||||
end: 1,
|
||||
),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
transitionDuration: const Duration(milliseconds: 200),
|
||||
barrierDismissible: true,
|
||||
selectableDayPredicate: (dateTime) {
|
||||
// Disable 25th Feb 2023
|
||||
if (dateTime == DateTime(2023, 2, 25)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
);
|
||||
model.log.i(dateTime);
|
||||
if (dateTime != null) {
|
||||
model.tglBeliController.text = model.myFunction
|
||||
.convertDateTime(dateTime.toString());
|
||||
model.dateTime = dateTime.toString();
|
||||
}
|
||||
model.notifyListeners();
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 250,
|
||||
child: MyButton(
|
||||
text: 'Tambah',
|
||||
onPressed: () {
|
||||
if (model.globalKey.currentState!.validate()) {
|
||||
model.dialogService
|
||||
.showDialog(
|
||||
title: 'Tambah Pemilik Rumah',
|
||||
description:
|
||||
'Apakah anda yakin ingin menambahkan pemilik rumah ${request!.data.toString().toUpperCase()} ini?',
|
||||
buttonTitle: 'Ya',
|
||||
cancelTitle: 'Tidak',
|
||||
)
|
||||
.then((value) async {
|
||||
if (value!.confirmed) {
|
||||
// model.log.i(request!.data);
|
||||
bool res = await model
|
||||
.tambahRumah(request!.data.toString());
|
||||
model.log.i('res: $res');
|
||||
if (res == true) {
|
||||
completer!(SheetResponse(
|
||||
confirmed: true,
|
||||
data: request!.data,
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../app/app.logger.dart';
|
||||
import '../../../../../app/core/custom_base_view_model.dart';
|
||||
|
||||
class TambahRumahBottomSheetViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('TambahRumahBottomSheetViewModel');
|
||||
|
||||
// form variables
|
||||
final globalKey = GlobalKey<FormState>();
|
||||
TextEditingController namaPemilikRumahController = TextEditingController();
|
||||
TextEditingController noHpPemilikRumahController = TextEditingController();
|
||||
TextEditingController hargaRumahController = TextEditingController();
|
||||
TextEditingController bayarPerbulanController = TextEditingController();
|
||||
TextEditingController tglBeliController = TextEditingController();
|
||||
String? dateTime;
|
||||
|
||||
Future<void> init() async {}
|
||||
|
||||
Future<bool> tambahRumah(String idPerumahan) async {
|
||||
setBusy(true);
|
||||
easyLoading.customLoading('Tambah Pemilik Rumah...');
|
||||
try {
|
||||
String harga =
|
||||
myFunction.numberFormat(int.parse(hargaRumahController.text));
|
||||
String cicilan =
|
||||
myFunction.numberFormat(int.parse(bayarPerbulanController.text));
|
||||
// log.i(myFunction.numberFormat(int.parse(hargaRumahController.text)));
|
||||
var formData = FormData.fromMap({
|
||||
'id_rumah': idPerumahan,
|
||||
'nama': namaPemilikRumahController.text,
|
||||
'no_hp': noHpPemilikRumahController.text,
|
||||
'harga': harga,
|
||||
'cicilan': cicilan,
|
||||
'tanggal_pembelian': dateTime,
|
||||
});
|
||||
// log.i(hargaRumahController.text);
|
||||
// log.i(bayarPerbulanController.text);
|
||||
await httpService.postWithFormData(
|
||||
'rumahnya',
|
||||
formData,
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
log.e(e.toString());
|
||||
return false;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
easyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user