changes the area to kecamatan , kelurahan and tps
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
import 'package:cek_suara_app/ui/widgets/my_textformfield.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import '../../../../widgets/my_textformfield.dart';
|
||||
import './bottom_sheet_cari_area_view_model.dart';
|
||||
|
||||
class BottomSheetCariAreaView extends StatelessWidget {
|
||||
|
@ -120,11 +120,11 @@ class HalamanSurveiView extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Text(
|
||||
' Pilih Area',
|
||||
' Pilih Kecamatan',
|
||||
),
|
||||
if (model.isBusy)
|
||||
const Center(child: CircularProgressIndicator()),
|
||||
if (!model.isBusy && model.selectedArea != null)
|
||||
if (!model.isBusy && model.selectedKecamatan != null)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
@ -135,49 +135,100 @@ class HalamanSurveiView extends StatelessWidget {
|
||||
color: sixthGrey,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// icon search
|
||||
IconButton(
|
||||
onPressed: () async =>
|
||||
await model.searchArea(),
|
||||
icon: const Icon(
|
||||
Icons.search,
|
||||
color: sixthGrey,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isExpanded: true,
|
||||
value: model.selectedArea!,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
iconSize: 24,
|
||||
elevation: 16,
|
||||
style: const TextStyle(
|
||||
color: Colors.black),
|
||||
onChanged: (String? newValue) {
|
||||
model.log.i(newValue);
|
||||
model.selectedArea = newValue!;
|
||||
// model.changeArea(newValue);
|
||||
model.notifyListeners();
|
||||
},
|
||||
items: model.listAreaString
|
||||
.map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value,
|
||||
overflow:
|
||||
TextOverflow.ellipsis),
|
||||
);
|
||||
}).toList()),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isExpanded: true,
|
||||
value: model.selectedKecamatan!,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
iconSize: 24,
|
||||
elevation: 16,
|
||||
style: const TextStyle(color: Colors.black),
|
||||
onChanged: (String? newValue) {
|
||||
model.log.i(newValue);
|
||||
model.selectedKecamatan = newValue!;
|
||||
String kecamatanId = model
|
||||
.listKecamatanModel[model
|
||||
.listKecamatanString
|
||||
.indexOf(newValue)]
|
||||
.kecamatanId!;
|
||||
model.getKelurahan(kecamatanId);
|
||||
// model.changeArea(newValue);
|
||||
model.notifyListeners();
|
||||
},
|
||||
items: model.listKecamatanString
|
||||
.map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
);
|
||||
}).toList()),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
const Text(
|
||||
' Pilih Kelurahan / Desa',
|
||||
),
|
||||
if (model.isBusy)
|
||||
const Center(child: CircularProgressIndicator()),
|
||||
if (!model.isBusy && model.selectedKelurahan != null)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
border: Border.all(
|
||||
color: sixthGrey,
|
||||
),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isExpanded: true,
|
||||
value: model.selectedKelurahan!,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
iconSize: 24,
|
||||
elevation: 16,
|
||||
style: const TextStyle(color: Colors.black),
|
||||
onChanged: (String? newValue) {
|
||||
model.log.i(newValue);
|
||||
model.selectedKelurahan = newValue!;
|
||||
// model.changeArea(newValue);
|
||||
model.notifyListeners();
|
||||
},
|
||||
items: model.listKelurahanString
|
||||
.map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
);
|
||||
}).toList()),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
MyTextFormField(
|
||||
hintText: 'Masukkan No TPS',
|
||||
labelText: 'Nomor TPS',
|
||||
maxLength: 2,
|
||||
suffixIcon: const Icon(Icons.account_balance),
|
||||
controller: model.noTPScontroller,
|
||||
keyboardType: TextInputType.number,
|
||||
validator: Validatorless.multiple(
|
||||
[
|
||||
Validatorless.required(
|
||||
'Nomor TPS tidak boleh kosong'),
|
||||
Validatorless.number('Nomor TPS harus angka'),
|
||||
Validatorless.min(1, 'Nomor TPS minimal 1 digit'),
|
||||
Validatorless.max(
|
||||
2, 'Nomor TPS maksimal 2 digit'),
|
||||
],
|
||||
),
|
||||
),
|
||||
// const SizedBox(height: 20),
|
||||
// const Text(
|
||||
// ' Pilih Caleg',
|
||||
|
@ -4,7 +4,6 @@ import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import '../../../../app/app.bottomsheets.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../model/area_model.dart';
|
||||
@ -17,6 +16,7 @@ class HalamanSurveiViewModel extends CustomBaseViewModel {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
TextEditingController ktpController = TextEditingController();
|
||||
TextEditingController namaController = TextEditingController();
|
||||
TextEditingController noTPScontroller = TextEditingController();
|
||||
|
||||
// image picker
|
||||
String? _imagePath;
|
||||
@ -25,11 +25,14 @@ class HalamanSurveiViewModel extends CustomBaseViewModel {
|
||||
Uint8List? imageBytes;
|
||||
|
||||
// area
|
||||
List<AreaModel> listAreaModel = [];
|
||||
List<String> listAreaString = [];
|
||||
List<AreaModel> allListAreaModel = [];
|
||||
String? selectedArea;
|
||||
int areaIndex = 0;
|
||||
List<KecamatanModel> listKecamatanModel = [];
|
||||
List<String> listKecamatanString = [];
|
||||
List<KelurahanModel> listKelurahanModel = [];
|
||||
List<String> listKelurahanString = [];
|
||||
// List<AreaModel> allListKecamatanModel = [];
|
||||
String? selectedKecamatan;
|
||||
String? selectedKelurahan;
|
||||
// int areaIndex = 0;
|
||||
|
||||
// // caleg
|
||||
// List<CalegModel> listCalegModel = [];
|
||||
@ -59,17 +62,31 @@ class HalamanSurveiViewModel extends CustomBaseViewModel {
|
||||
|
||||
// String? nik = await mySharedPrefs.getString('nik');
|
||||
var response = await httpService.get('area/cek_area/$nik');
|
||||
log.i(response.data);
|
||||
// log.i(response.data);
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
AreaListModel areaListModel =
|
||||
AreaListModel.fromJson(myResponseModel.data);
|
||||
listAreaModel = areaListModel.area!;
|
||||
allListAreaModel = areaListModel.area!;
|
||||
for (var element in listAreaModel) {
|
||||
listAreaString.add(element.namaArea!);
|
||||
KecamatanDetail kecamatanDetail =
|
||||
KecamatanDetail.fromJson(myResponseModel.data);
|
||||
|
||||
listKecamatanModel = kecamatanDetail.kecamatan!;
|
||||
selectedKecamatan = listKecamatanModel[0].name!;
|
||||
for (var element in listKecamatanModel) {
|
||||
listKecamatanString.add(element.name!);
|
||||
}
|
||||
selectedArea = listAreaString[0];
|
||||
// int idArea = listAreaModel[0].idArea!;
|
||||
|
||||
// log.i('kecamatanDetail: ${kecamatanDetail.kecamatan}');
|
||||
|
||||
String idKecamatan = listKecamatanModel[0].kecamatanId!;
|
||||
await getKelurahan(idKecamatan);
|
||||
|
||||
// AreaListModel areaListModel =
|
||||
// AreaListModel.fromJson(myResponseModel.data);
|
||||
// listKecamatanModel = areaListModel.area!;
|
||||
// allListKecamatanModel = areaListModel.area!;
|
||||
// for (var element in listKecamatanModel) {
|
||||
// listKecamatanString.add(element.namaArea!);
|
||||
// }
|
||||
// selectedKecamatan = listKecamatanString[0];
|
||||
// // int idArea = listKecamatanModel[0].idArea!;
|
||||
// await getCaleg(idArea);
|
||||
|
||||
// getCaleg()
|
||||
@ -81,40 +98,30 @@ class HalamanSurveiViewModel extends CustomBaseViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
// getCaleg(int idArea) async {
|
||||
// log.i('getCaleg');
|
||||
// log.i('idArea: $idArea');
|
||||
// selectedCaleg = null;
|
||||
// listCalegModel = [];
|
||||
// listCalegString = [];
|
||||
// setBusy(true);
|
||||
// try {
|
||||
// var response = await httpService.get('caleg/area/$idArea');
|
||||
// log.i(response.data);
|
||||
// MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
// // log.i(myResponseModel.data);
|
||||
// CalegListModel calegListModel =
|
||||
// CalegListModel.fromJson(myResponseModel.data);
|
||||
// listCalegModel = calegListModel.caleg!;
|
||||
// for (var element in listCalegModel) {
|
||||
// listCalegString.add(element.namaCaleg!);
|
||||
// }
|
||||
// selectedCaleg = listCalegString[0];
|
||||
// // log.i('listCalegModel: $listCalegModel');
|
||||
// // log.i('listCalegString: $listCalegString');
|
||||
// // log.i('selectedCaleg: $selectedCaleg');
|
||||
// } catch (e) {
|
||||
// log.e(e);
|
||||
// } finally {
|
||||
// setBusy(false);
|
||||
// }
|
||||
// }
|
||||
|
||||
// changeArea(String? value) async {
|
||||
// int idArea = listAreaModel[listAreaString.indexOf(value!)].idArea!;
|
||||
// // log.i('idArea: $idArea');
|
||||
// await getCaleg(idArea);
|
||||
// }
|
||||
getKelurahan(String idKecamatan) async {
|
||||
log.i('getKelurahan');
|
||||
listKelurahanModel = [];
|
||||
listKelurahanString = [];
|
||||
selectedKelurahan = null;
|
||||
setBusy(true);
|
||||
try {
|
||||
var response = await httpService.get('area/kelurahan/$idKecamatan');
|
||||
// log.i(response.data);
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
KelurahanDetail kelurahanDetail =
|
||||
KelurahanDetail.fromJson(myResponseModel.data);
|
||||
// log.i('kelurahanDetail: ${kelurahanDetail.kelurahan}');
|
||||
listKelurahanModel = kelurahanDetail.kelurahan!;
|
||||
for (var element in listKelurahanModel) {
|
||||
listKelurahanString.add(element.name!);
|
||||
}
|
||||
selectedKelurahan = listKelurahanString[0];
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
void addImage() async {
|
||||
try {
|
||||
@ -132,48 +139,20 @@ class HalamanSurveiViewModel extends CustomBaseViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
searchArea() async {
|
||||
var res = await bottomSheetService.showCustomSheet(
|
||||
variant: BottomSheetType.bottomSheetCariAreaView,
|
||||
ignoreSafeArea: false,
|
||||
isScrollControlled: true,
|
||||
);
|
||||
|
||||
if (res!.confirmed) {
|
||||
log.i('res.data: ${res.data}');
|
||||
|
||||
String area = res.data;
|
||||
if (area == '') {
|
||||
listAreaModel = allListAreaModel;
|
||||
} else {
|
||||
listAreaModel = [];
|
||||
for (var element in allListAreaModel) {
|
||||
if (element.namaArea!.toLowerCase().contains(area.toLowerCase())) {
|
||||
listAreaModel.add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listAreaString = [];
|
||||
for (var element in listAreaModel) {
|
||||
listAreaString.add(element.namaArea!);
|
||||
}
|
||||
selectedArea = listAreaString[0];
|
||||
// int idArea = listAreaModel[0].idArea!;
|
||||
// await getCaleg(idArea);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
uploadData() async {
|
||||
log.i('uploadData');
|
||||
setBusy(true);
|
||||
easyLoading.customLoading('Uploading data...');
|
||||
globalVar.backPressed = 'cantBack';
|
||||
try {
|
||||
String idArea = listAreaModel[listAreaString.indexOf(selectedArea!)]
|
||||
.idArea
|
||||
.toString();
|
||||
String idKecamatan =
|
||||
listKecamatanModel[listKecamatanString.indexOf(selectedKecamatan!)]
|
||||
.kecamatanId
|
||||
.toString();
|
||||
String idKelurahan =
|
||||
listKelurahanModel[listKelurahanString.indexOf(selectedKelurahan!)]
|
||||
.kelurahanId
|
||||
.toString();
|
||||
var fomData = FormData.fromMap(
|
||||
{
|
||||
'ktp': ktpController.text,
|
||||
@ -184,8 +163,10 @@ class HalamanSurveiViewModel extends CustomBaseViewModel {
|
||||
filename: imageFile!.name,
|
||||
contentType: MediaType('image', 'jpg'),
|
||||
),
|
||||
'idArea': idArea,
|
||||
'idKecamatan': idKecamatan,
|
||||
'idKelurahan': idKelurahan,
|
||||
'nik': nik,
|
||||
'noTPS': noTPScontroller.text,
|
||||
},
|
||||
);
|
||||
await httpService.postWithFormData('tim_survei', fomData);
|
||||
@ -200,6 +181,7 @@ class HalamanSurveiViewModel extends CustomBaseViewModel {
|
||||
_imagePath = null;
|
||||
imageFile = null;
|
||||
imageBytes = null;
|
||||
noTPScontroller.clear();
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
|
Reference in New Issue
Block a user