slight change on add tim survei to add relation with caleg

This commit is contained in:
kicap
2023-11-04 03:53:41 +08:00
parent 85be29e7ce
commit 283f793d29
15 changed files with 262 additions and 78 deletions

View File

@ -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,
),
),
),
],
)
],
)
),
],
),
),

View File

@ -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);

View File

@ -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,