change area to kecamatan and some changes
This commit is contained in:
@ -47,6 +47,11 @@ class HalamanCalegView extends StatelessWidget {
|
||||
Expanded(
|
||||
// flex: 3,
|
||||
child: Container(
|
||||
alignment: model.isBusy
|
||||
? Alignment.center
|
||||
: (model.listCalegModel.isNotEmpty
|
||||
? Alignment.topCenter
|
||||
: Alignment.center),
|
||||
height: double.infinity,
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
@ -66,9 +71,11 @@ class HalamanCalegView extends StatelessWidget {
|
||||
: MainAxisAlignment.center),
|
||||
children: [
|
||||
if (model.isBusy)
|
||||
const LinearProgressIndicator(
|
||||
minHeight: 5,
|
||||
color: mainColor,
|
||||
const Center(
|
||||
child: LinearProgressIndicator(
|
||||
minHeight: 5,
|
||||
color: mainColor,
|
||||
),
|
||||
),
|
||||
if (!model.isBusy &&
|
||||
model.listCalegModel.isNotEmpty)
|
||||
|
@ -1,9 +1,7 @@
|
||||
import 'package:cek_suara/app/themes/app_colors.dart';
|
||||
|
||||
// import '../../../../app/app.bottomsheets.dart';
|
||||
import '../../../../app/app.dialogs.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
import '../../../../model/caleg_model.dart';
|
||||
import '../../../../model/my_response.model.dart';
|
||||
|
||||
@ -58,7 +56,8 @@ class HalamanCalegViewModel extends CustomBaseViewModel {
|
||||
|
||||
if (res!.confirmed) {
|
||||
snackbarService.showSnackbar(
|
||||
message: 'Caleg berhasil ditambahkan',
|
||||
message:
|
||||
'Caleg berhasil ditambahkan\nPassword default caleg : 12345678',
|
||||
title: 'Berhasil',
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
|
@ -136,27 +136,39 @@ class TambahEditCalegView extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (model.calegModel == null) const SizedBox(height: 10),
|
||||
if (model.calegModel == null)
|
||||
MyTextFormField(
|
||||
hintText: 'Area',
|
||||
labelText: 'Pencarian Area',
|
||||
controller: model.cariAreaController,
|
||||
suffixIcon: GestureDetector(
|
||||
onTap: () {
|
||||
// remove keyboard focus
|
||||
FocusScope.of(context).unfocus();
|
||||
model.cariArea();
|
||||
},
|
||||
child: const Icon(Icons.search),
|
||||
),
|
||||
// if (model.calegModel == null) const SizedBox(height: 10),
|
||||
// if (model.calegModel == null)
|
||||
// MyTextFormField(
|
||||
// hintText: 'Area',
|
||||
// labelText: 'Pencarian Area',
|
||||
// controller: model.cariAreaController,
|
||||
// // suffixIcon: GestureDetector(
|
||||
// // onTap: () {
|
||||
// // // remove keyboard focus
|
||||
// // FocusScope.of(context).unfocus();
|
||||
// // model.cariArea();
|
||||
// // },
|
||||
// // child: const Icon(Icons.search),
|
||||
// // ),
|
||||
|
||||
// controller: model.partaiController,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
// // controller: model.partaiController,
|
||||
// ),
|
||||
const SizedBox(height: 20),
|
||||
// create a horizontal divider
|
||||
|
||||
const Text("Pilih Kecamatan"),
|
||||
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height * 0.3,
|
||||
width: double.infinity,
|
||||
// create a border
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Colors.grey,
|
||||
width: 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
|
||||
// create 10 random checkbox
|
||||
child: SingleChildScrollView(
|
||||
@ -175,18 +187,19 @@ class TambahEditCalegView extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: model.listAreaId.contains(
|
||||
model.listAreaModel[index].idArea!),
|
||||
value: model.listAreaId.contains(model
|
||||
.listAreaModel[index].kecamatanId!),
|
||||
onChanged: (value) {
|
||||
if (model.calegModel != null) return;
|
||||
model.tambahHapusArea(
|
||||
model.listAreaModel[index].idArea!,
|
||||
model.listAreaModel[index]
|
||||
.kecamatanId!,
|
||||
);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
model.listAreaModel[index].namaArea!,
|
||||
model.listAreaModel[index].name!,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -19,15 +19,15 @@ class TambahEditCalegViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('TambahEditCalegViewModel');
|
||||
|
||||
// variabel list area
|
||||
List<AreaModel> listAreaModel = [];
|
||||
List<AreaModel> allListAreaModel = [];
|
||||
List<KecamatanModel> listAreaModel = [];
|
||||
List<KecamatanModel> allListAreaModel = [];
|
||||
|
||||
// form variable
|
||||
final formKey = GlobalKey<FormState>();
|
||||
TextEditingController namaController = TextEditingController();
|
||||
TextEditingController cariAreaController = TextEditingController();
|
||||
TextEditingController nomorUrutController = TextEditingController();
|
||||
List<int> listAreaId = [];
|
||||
List<String> listAreaId = [];
|
||||
|
||||
// image picker
|
||||
String? _imagePath;
|
||||
@ -58,13 +58,13 @@ class TambahEditCalegViewModel extends CustomBaseViewModel {
|
||||
var response = await httpService.get('caleg/relasi_area/$idCaleg');
|
||||
log.i(response.data);
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
var data = myResponseModel.data['area'];
|
||||
var data = myResponseModel.data['kecamatan'];
|
||||
for (var item in data) {
|
||||
listAreaId.add(item['id_area']);
|
||||
listAreaId.add(item['kecamatan_id']);
|
||||
}
|
||||
listAreaModel = [];
|
||||
for (var item in allListAreaModel) {
|
||||
if (listAreaId.contains(item.idArea)) {
|
||||
if (listAreaId.contains(item.kecamatanId)) {
|
||||
listAreaModel.add(item);
|
||||
}
|
||||
}
|
||||
@ -85,16 +85,19 @@ class TambahEditCalegViewModel extends CustomBaseViewModel {
|
||||
setBusy(true);
|
||||
globalVar.backPressed = 'cantBack';
|
||||
try {
|
||||
var response = await httpService.get('area');
|
||||
var response = await httpService.get('area/kecamatan');
|
||||
log.i(response.data);
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
AreaListModel areaListModel =
|
||||
AreaListModel.fromJson(myResponseModel.data);
|
||||
listAreaModel = areaListModel.area!;
|
||||
allListAreaModel = areaListModel.area!;
|
||||
// log.i(myResponseModel.data);
|
||||
KecamatanDetail areaListModel =
|
||||
KecamatanDetail.fromJson(myResponseModel.data);
|
||||
listAreaModel = areaListModel.kecamatan!;
|
||||
allListAreaModel = areaListModel.kecamatan!;
|
||||
// listAreaModel = areaListModel.area!;
|
||||
// allListAreaModel = areaListModel.area!;
|
||||
// jumlahArea = areaListModel.jumlah!;
|
||||
|
||||
log.i('listAreaModel: $listAreaModel');
|
||||
// log.i('listAreaModel: $listAreaModel');
|
||||
// log.i('jumlahArea: $jumlahArea');
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
@ -120,33 +123,33 @@ class TambahEditCalegViewModel extends CustomBaseViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
tambahHapusArea(int idArea) {
|
||||
tambahHapusArea(String kecamatanId) {
|
||||
log.i('tambahHapusArea');
|
||||
if (listAreaId.contains(idArea)) {
|
||||
listAreaId.remove(idArea);
|
||||
if (listAreaId.contains(kecamatanId)) {
|
||||
listAreaId.remove(kecamatanId);
|
||||
} else {
|
||||
listAreaId.add(idArea);
|
||||
listAreaId.add(kecamatanId);
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
cariArea() {
|
||||
log.i('cariArea ${cariAreaController.text}');
|
||||
// cariArea() {
|
||||
// log.i('cariArea ${cariAreaController.text}');
|
||||
|
||||
if (cariAreaController.text.isEmpty) {
|
||||
listAreaModel = allListAreaModel;
|
||||
return;
|
||||
}
|
||||
// if (cariAreaController.text.isEmpty) {
|
||||
// listAreaModel = allListAreaModel;
|
||||
// return;
|
||||
// }
|
||||
|
||||
listAreaModel = allListAreaModel
|
||||
.where((element) => element.namaArea!
|
||||
.toLowerCase()
|
||||
.contains(cariAreaController.text.toLowerCase()))
|
||||
.toList();
|
||||
// listAreaModel = allListAreaModel
|
||||
// .where((element) => element.namaArea!
|
||||
// .toLowerCase()
|
||||
// .contains(cariAreaController.text.toLowerCase()))
|
||||
// .toList();
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
// notifyListeners();
|
||||
// }
|
||||
|
||||
Future<bool> addCaleg() async {
|
||||
log.i('addCaleg');
|
||||
@ -157,7 +160,7 @@ class TambahEditCalegViewModel extends CustomBaseViewModel {
|
||||
var formData = FormData.fromMap({
|
||||
'nama': namaController.text,
|
||||
'nomor_urut': nomorUrutController.text,
|
||||
'area': const JsonEncoder().convert(listAreaId),
|
||||
'kecamatan': const JsonEncoder().convert(listAreaId),
|
||||
'foto': await MultipartFile.fromFile(
|
||||
imageFile!.path,
|
||||
filename: imageFile!.name,
|
||||
|
Reference in New Issue
Block a user