slight change on add tim survei to add relation with caleg
This commit is contained in:
@ -63,6 +63,8 @@ class HalamanAreaViewModel extends CustomBaseViewModel {
|
||||
var response = await httpService.postWithFormData('area', formData);
|
||||
log.i(response.data);
|
||||
await getData();
|
||||
// reset form
|
||||
namaAreaController.clear();
|
||||
return true;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
|
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
import './coba_bottom_sheet_view_model.dart';
|
||||
|
||||
class CobaBottomSheetView extends StatelessWidget {
|
||||
final SheetRequest? request;
|
||||
final Function(SheetResponse)? completer;
|
||||
|
||||
const CobaBottomSheetView({
|
||||
Key? key,
|
||||
this.request,
|
||||
this.completer,
|
||||
}) : super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<CobaBottomSheetViewModel>.reactive(
|
||||
viewModelBuilder: () => CobaBottomSheetViewModel(),
|
||||
onViewModelReady: (CobaBottomSheetViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
CobaBottomSheetViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return SafeArea(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: const Text('Coba Bottom Sheet'),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
import 'package:cek_suara/app/core/custom_base_view_model.dart';
|
||||
|
||||
class CobaBottomSheetViewModel extends CustomBaseViewModel {
|
||||
Future<void> init() async {}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
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';
|
||||
@ -46,6 +47,10 @@ class HalamanCalegViewModel extends CustomBaseViewModel {
|
||||
|
||||
addCaleg() async {
|
||||
// log.i('addCaleg');
|
||||
// await bottomSheetService.showCustomSheet(
|
||||
// variant: BottomSheetType.cobaBottomSheetView,
|
||||
// title: 'Tambah Caleg',
|
||||
// );
|
||||
var res = await dialogService.showCustomDialog(
|
||||
variant: DialogType.tambahEditCalegView,
|
||||
title: 'Tambah Caleg',
|
||||
|
@ -75,6 +75,71 @@ class TambahDetailTimSurveiView extends StatelessWidget {
|
||||
'Nama Tim Survei tidak boleh kosong'),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (model.timSurveiModel == null)
|
||||
Column(
|
||||
children: [
|
||||
const Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
' Pilih Caleg',
|
||||
),
|
||||
),
|
||||
if (model.isBusy)
|
||||
const LinearProgressIndicator(
|
||||
minHeight: 5,
|
||||
color: mainColor,
|
||||
),
|
||||
if (!model.isBusy && model.listCalegModel.isNotEmpty)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
border: Border.all(
|
||||
color: sixthGrey,
|
||||
),
|
||||
),
|
||||
child: Expanded(
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isExpanded: true,
|
||||
value: model.selectedCaleg!,
|
||||
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.selectedCaleg = newValue!;
|
||||
model.selectedCalegId = model
|
||||
.listCalegModel
|
||||
.firstWhere((element) =>
|
||||
element.namaCaleg ==
|
||||
model.selectedCaleg)
|
||||
.idCaleg;
|
||||
|
||||
model.log.i(model.selectedCalegId);
|
||||
|
||||
model.notifyListeners();
|
||||
},
|
||||
items: model.listCalegString
|
||||
.map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
);
|
||||
}).toList()),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
if (model.timSurveiModel == null)
|
||||
SizedBox(
|
||||
width: 200,
|
||||
@ -103,45 +168,56 @@ class TambahDetailTimSurveiView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
if (model.timSurveiModel != null)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
Column(
|
||||
children: [
|
||||
// create rounde icon with one is delete and one is info
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(
|
||||
Icons.list_alt_outlined,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
MyTextFormField(
|
||||
labelText: 'Caleg',
|
||||
hintText: 'Caleg',
|
||||
readOnly: true,
|
||||
controller: model.namaCalegController,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: dangerColor,
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: IconButton(
|
||||
onPressed: () async {
|
||||
completer(DialogResponse(confirmed: true));
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// create rounde icon with one is delete and one is info
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(
|
||||
Icons.list_alt_outlined,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: dangerColor,
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: IconButton(
|
||||
onPressed: () async {
|
||||
completer(DialogResponse(confirmed: true));
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -1,9 +1,10 @@
|
||||
import 'package:cek_suara/model/tim_survei_model.dart';
|
||||
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/caleg_model.dart';
|
||||
import '../../../../../model/tim_survei_model.dart';
|
||||
|
||||
class TambahDetailTimSurveiViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('TambahDetailTimSurveiViewModel');
|
||||
@ -12,15 +13,45 @@ class TambahDetailTimSurveiViewModel extends CustomBaseViewModel {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
TextEditingController nikController = TextEditingController();
|
||||
TextEditingController namaController = TextEditingController();
|
||||
TextEditingController namaCalegController = TextEditingController();
|
||||
|
||||
TimSurveiModel? timSurveiModel;
|
||||
|
||||
// list caleg
|
||||
List<CalegModel> listCalegModel = [];
|
||||
List<String> listCalegString = [];
|
||||
String? selectedCaleg;
|
||||
int? selectedCalegId;
|
||||
|
||||
Future<void> init(data) async {
|
||||
globalVar.backPressed = 'exitApp';
|
||||
timSurveiModel = data;
|
||||
if (timSurveiModel != null) {
|
||||
nikController.text = timSurveiModel!.nik!;
|
||||
namaController.text = timSurveiModel!.nama!;
|
||||
namaCalegController.text = timSurveiModel!.namaCaleg!;
|
||||
} else {
|
||||
await getData();
|
||||
}
|
||||
}
|
||||
|
||||
getData() async {
|
||||
setBusy(true);
|
||||
try {
|
||||
var response = await httpService.get('caleg');
|
||||
// log.i(response.data);
|
||||
CalegListModel calegListModel =
|
||||
CalegListModel.fromJson(response.data['data']);
|
||||
listCalegModel = calegListModel.caleg!;
|
||||
for (var element in listCalegModel) {
|
||||
listCalegString.add(element.namaCaleg!);
|
||||
}
|
||||
selectedCaleg = listCalegString[0];
|
||||
selectedCalegId = listCalegModel[0].idCaleg;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +64,7 @@ class TambahDetailTimSurveiViewModel extends CustomBaseViewModel {
|
||||
var formData = FormData.fromMap({
|
||||
'nik': nikController.text,
|
||||
'nama': namaController.text,
|
||||
'id_caleg': selectedCalegId,
|
||||
});
|
||||
var response = await httpService.postWithFormData('survei', formData);
|
||||
log.i(response.data);
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:cek_suara/app/themes/app_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
@ -84,8 +85,21 @@ class TimSurveiView extends StatelessWidget {
|
||||
title: Text(
|
||||
model.listTimSurveiModel[i].nama!,
|
||||
),
|
||||
subtitle: Text(
|
||||
model.listTimSurveiModel[i].nik!,
|
||||
subtitle: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
model.listTimSurveiModel[i]
|
||||
.nik!,
|
||||
style: italicTextStyle,
|
||||
),
|
||||
Text(
|
||||
model.listTimSurveiModel[i]
|
||||
.namaCaleg!,
|
||||
style: boldTextStyle,
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
Reference in New Issue
Block a user