add edit siswa page
This commit is contained in:
parent
b1dc1851a4
commit
667aae745b
8
.env
8
.env
|
@ -1,6 +1,6 @@
|
|||
# url = 'https://panti-asuhan.s-keytech.com/'
|
||||
# api_url = 'https://panti-asuhan.s-keytech.com/api/'
|
||||
url = 'https://panti-asuhan.s-keytech.com/'
|
||||
api_url = 'https://panti-asuhan.s-keytech.com/api/'
|
||||
# url = 'http://172.29.85.181/panti_asuhan2/'
|
||||
# api_url = 'http://172.29.85.181/panti_asuhan2/api/'
|
||||
url = 'http://20.20.20.25/panti_asuhan2/'
|
||||
api_url = 'http://20.20.20.25/panti_asuhan2/api/'
|
||||
# url = 'http://20.20.20.25/panti_asuhan2/'
|
||||
# api_url = 'http://20.20.20.25/panti_asuhan2/api/'
|
|
@ -26,10 +26,10 @@ class DanaSosialModel {
|
|||
DanaSosialModel.fromJson(Map<String, dynamic> json) {
|
||||
idDanaSosial = json['id_dana_sosial'];
|
||||
bentuk = json['bentuk'];
|
||||
nama = json['nama'];
|
||||
nama = json['nama'] ?? '';
|
||||
jumlah = json['jumlah'];
|
||||
tanggal = json['tanggal'];
|
||||
keterangan = json['ket'];
|
||||
keterangan = json['ket'] ?? '';
|
||||
jenisDonasi = json['jenis'];
|
||||
status =
|
||||
json['status'] == '0' ? 'Belum Dikonfirmasi' : 'Sudah Dikonfirmasi';
|
||||
|
|
|
@ -270,7 +270,9 @@ class EditDialogSiswaView extends StatelessWidget {
|
|||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
completer(DialogResponse(confirmed: false));
|
||||
},
|
||||
child: const Text(
|
||||
'Batal',
|
||||
style: TextStyle(
|
||||
|
@ -281,15 +283,14 @@ class EditDialogSiswaView extends StatelessWidget {
|
|||
TextButton(
|
||||
onPressed: () async {
|
||||
if (model.formKey.currentState!.validate()) {
|
||||
// bool res = await model.postData();
|
||||
// model.log.i("res: $res");
|
||||
// if (res) {
|
||||
// completer(
|
||||
// DialogResponse(
|
||||
// confirmed: true,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
bool res = await model.updateSiswa();
|
||||
|
||||
if (res) {
|
||||
Navigator.pop(context);
|
||||
completer(DialogResponse(confirmed: true));
|
||||
}
|
||||
|
||||
// completer(DialogResponse(confirmed: true));
|
||||
}
|
||||
},
|
||||
child: const Text(
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_holo_date_picker/flutter_holo_date_picker.dart';
|
||||
|
||||
import '../../../../../app/app.locator.dart';
|
||||
import '../../../../../app/app.logger.dart';
|
||||
import '../../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../../model/siswa_model.dart';
|
||||
import '../../../../../services/http_services.dart';
|
||||
import '../../../../../services/my_easyloading.dart';
|
||||
|
||||
class EditDialogSiswaViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('EditDialogSiswaViewModel');
|
||||
final easyLoading = locator<MyEasyLoading>();
|
||||
final _httpService = locator<MyHttpServices>();
|
||||
SiswaModel? siswaModel;
|
||||
String jenisKelamin = 'Laki-laki';
|
||||
List<String> jenisKelaminList = ['Laki-laki', 'Perempuan'];
|
||||
|
@ -66,4 +72,37 @@ class EditDialogSiswaViewModel extends CustomBaseViewModel {
|
|||
tanggalLahirController.text = date;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> updateSiswa() async {
|
||||
setBusy(true);
|
||||
easyLoading.customLoading('Updating data...');
|
||||
|
||||
try {
|
||||
var formData = FormData.fromMap({
|
||||
'id': siswaModel!.idSiswa,
|
||||
'nama': namaController.text,
|
||||
'tanggal_lahir': tanggalLahirController.text,
|
||||
'tempat_lahir': tempatLahirController.text,
|
||||
'jenis_kelamin': jenisKelamin,
|
||||
'alamat': alamatController.text,
|
||||
'no_telpon': noTelponController.text,
|
||||
'agama': agamaController.text,
|
||||
'kewarganegaraan': kewarganegaraanController.text,
|
||||
'pendidikan_sd': pendidikanSDController.text,
|
||||
'pendidikan_smp': pendidikanSMPController.text,
|
||||
'pendidikan_sma': pendidikanSMAController.text,
|
||||
'kemampuan': kemampuanController.text,
|
||||
'hobi': hobiController.text,
|
||||
});
|
||||
await _httpService.postWithFormData('siswa_edit', formData);
|
||||
snackbarService.showSnackbar(message: 'Data berhasil diupdate');
|
||||
return true;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
return false;
|
||||
} finally {
|
||||
easyLoading.dismissLoading();
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,7 +226,8 @@ class EditSiswaView extends StatelessWidget {
|
|||
// ),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
model.role == 'admin'
|
||||
? Positioned(
|
||||
top: 0,
|
||||
right: 45,
|
||||
// create a edit rounded button
|
||||
|
@ -250,8 +251,10 @@ class EditSiswaView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
)
|
||||
: SizedBox(),
|
||||
model.role == 'admin'
|
||||
? Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
// create a close rounded button
|
||||
|
@ -295,7 +298,8 @@ class EditSiswaView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../../app/app.dialogs.dart';
|
||||
import '../../../../app/app.locator.dart';
|
||||
|
@ -13,6 +14,7 @@ class EditSiswaViewModel extends CustomBaseViewModel {
|
|||
final log = getLogger('EditSiswaViewModel');
|
||||
final _httpService = locator<MyHttpServices>();
|
||||
final easyLoading = locator<MyEasyLoading>();
|
||||
String? role;
|
||||
SiswaModel? siswaModel;
|
||||
List<String> jenisKelaminList = ['Laki-laki', 'Perempuan'];
|
||||
String jenisKelamin = 'Laki-laki';
|
||||
|
@ -34,6 +36,9 @@ class EditSiswaViewModel extends CustomBaseViewModel {
|
|||
Future<void> init(int idSiswa) async {
|
||||
log.i('idSiswa: $idSiswa');
|
||||
getData(idSiswa);
|
||||
prefs.then((SharedPreferences prefs) {
|
||||
role = prefs.getString('role');
|
||||
});
|
||||
}
|
||||
|
||||
getData(int idSiswa) async {
|
||||
|
@ -101,11 +106,13 @@ class EditSiswaViewModel extends CustomBaseViewModel {
|
|||
}
|
||||
|
||||
editData() async {
|
||||
var res = dialogService.showCustomDialog(
|
||||
var res = await dialogService.showCustomDialog(
|
||||
variant: DialogType.editDialogSiswaView,
|
||||
data: siswaModel,
|
||||
);
|
||||
|
||||
res;
|
||||
if (res?.confirmed != true) {
|
||||
init(int.parse(siswaModel!.idSiswa!));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,12 +203,14 @@ class SecondWidget extends ViewModelWidget<StrukturOrganisasiViewModel> {
|
|||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
IconButton(
|
||||
viewModel.role == 'admin'
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
viewModel.editData(title, true);
|
||||
},
|
||||
icon: const Icon(Icons.edit),
|
||||
)
|
||||
: const SizedBox(),
|
||||
],
|
||||
),
|
||||
for (var i = 0; i < length; i++)
|
||||
|
@ -287,12 +289,14 @@ class FirstWidget extends ViewModelWidget<StrukturOrganisasiViewModel> {
|
|||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
IconButton(
|
||||
viewModel.role == 'admin'
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
viewModel.editData(title, false);
|
||||
},
|
||||
icon: const Icon(Icons.edit),
|
||||
)
|
||||
: const SizedBox(),
|
||||
],
|
||||
),
|
||||
Center(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../../app/app.dialogs.dart';
|
||||
import '../../../../app/app.locator.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
|
@ -9,6 +11,7 @@ class StrukturOrganisasiViewModel extends CustomBaseViewModel {
|
|||
final log = getLogger('StrukturOrganisasiViewModel');
|
||||
final _httpService = locator<MyHttpServices>();
|
||||
final easyLoading = locator<MyEasyLoading>();
|
||||
String? role;
|
||||
|
||||
Map<String, dynamic> dataKetua = {};
|
||||
Map<String, dynamic> dataSekretaris = {};
|
||||
|
@ -54,6 +57,9 @@ class StrukturOrganisasiViewModel extends CustomBaseViewModel {
|
|||
int dataKelompokPutriLength = 0;
|
||||
|
||||
Future<void> init() async {
|
||||
prefs.then((SharedPreferences prefs) {
|
||||
role = prefs.getString('role');
|
||||
});
|
||||
getData('Ketua', false, null);
|
||||
getData('Sekretaris', false, null);
|
||||
getData('Bendahara', false, null);
|
||||
|
|
|
@ -32,7 +32,28 @@ class DetailDanaSosialView extends StatelessWidget {
|
|||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: Column(
|
||||
child: model.danaSosialModel == null
|
||||
? Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: (model.danaSosialModel!.bentuk == 'Pemasukan'
|
||||
? PemasukanWidget()
|
||||
: PengeluaranWidget()),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PengeluaranWidget extends ViewModelWidget<DetailDanaSosialViewModel> {
|
||||
const PengeluaranWidget({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, DetailDanaSosialViewModel viewModel) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
@ -40,12 +61,12 @@ class DetailDanaSosialView extends StatelessWidget {
|
|||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Nama Donator",
|
||||
"Bentuk",
|
||||
style: regularTextStyle.copyWith(color: mainColor),
|
||||
),
|
||||
),
|
||||
MyTextFormField(
|
||||
controller: model.namaController,
|
||||
controller: viewModel.bentukController,
|
||||
maxLines: 1,
|
||||
readOnly: true,
|
||||
),
|
||||
|
@ -60,7 +81,7 @@ class DetailDanaSosialView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
MyTextFormField(
|
||||
controller: model.tanggalController,
|
||||
controller: viewModel.tanggalController,
|
||||
maxLines: 1,
|
||||
readOnly: true,
|
||||
),
|
||||
|
@ -75,18 +96,18 @@ class DetailDanaSosialView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
MyTextFormField(
|
||||
controller: model.jenisController,
|
||||
controller: viewModel.jenisController,
|
||||
maxLines: 1,
|
||||
readOnly: true,
|
||||
),
|
||||
Visibility(
|
||||
visible: model.jenisBool,
|
||||
visible: viewModel.jenisBool,
|
||||
child: const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: model.jenisBool,
|
||||
visible: viewModel.jenisBool,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
|
@ -96,21 +117,21 @@ class DetailDanaSosialView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: model.jenisBool,
|
||||
visible: viewModel.jenisBool,
|
||||
child: MyTextFormField(
|
||||
controller: model.jumlahController,
|
||||
controller: viewModel.jumlahController,
|
||||
maxLines: 1,
|
||||
readOnly: true,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: !model.jenisBool,
|
||||
visible: !viewModel.jenisBool,
|
||||
child: const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: !model.jenisBool,
|
||||
visible: !viewModel.jenisBool,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
|
@ -120,9 +141,9 @@ class DetailDanaSosialView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: !model.jenisBool,
|
||||
visible: !viewModel.jenisBool,
|
||||
child: MyTextFormField(
|
||||
controller: model.keteranganController,
|
||||
controller: viewModel.keteranganController,
|
||||
maxLines: 2,
|
||||
readOnly: true,
|
||||
),
|
||||
|
@ -143,13 +164,13 @@ class DetailDanaSosialView extends StatelessWidget {
|
|||
SizedBox(
|
||||
height: 150,
|
||||
width: 150,
|
||||
child: model.danaSosialModel == null
|
||||
child: viewModel.danaSosialModel == null
|
||||
? Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: mainColor),
|
||||
),
|
||||
)
|
||||
: (model.danaSosialModel!.status! ==
|
||||
: (viewModel.danaSosialModel!.status! ==
|
||||
'Belum Dikonfirmasi'
|
||||
? const TtdWidget()
|
||||
: Image.asset(
|
||||
|
@ -173,10 +194,158 @@ class DetailDanaSosialView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
class PemasukanWidget extends ViewModelWidget<DetailDanaSosialViewModel> {
|
||||
const PemasukanWidget({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, DetailDanaSosialViewModel viewModel) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Nama Donator",
|
||||
style: regularTextStyle.copyWith(color: mainColor),
|
||||
),
|
||||
),
|
||||
MyTextFormField(
|
||||
controller: viewModel.namaController,
|
||||
maxLines: 1,
|
||||
readOnly: true,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Tanggal",
|
||||
style: regularTextStyle.copyWith(color: mainColor),
|
||||
),
|
||||
),
|
||||
MyTextFormField(
|
||||
controller: viewModel.tanggalController,
|
||||
maxLines: 1,
|
||||
readOnly: true,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Jenis",
|
||||
style: regularTextStyle.copyWith(color: mainColor),
|
||||
),
|
||||
),
|
||||
MyTextFormField(
|
||||
controller: viewModel.jenisController,
|
||||
maxLines: 1,
|
||||
readOnly: true,
|
||||
),
|
||||
Visibility(
|
||||
visible: viewModel.jenisBool,
|
||||
child: const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: viewModel.jenisBool,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Jumlah",
|
||||
style: regularTextStyle.copyWith(color: mainColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: viewModel.jenisBool,
|
||||
child: MyTextFormField(
|
||||
controller: viewModel.jumlahController,
|
||||
maxLines: 1,
|
||||
readOnly: true,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: !viewModel.jenisBool,
|
||||
child: const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: !viewModel.jenisBool,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Keterangan",
|
||||
style: regularTextStyle.copyWith(color: mainColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: !viewModel.jenisBool,
|
||||
child: MyTextFormField(
|
||||
controller: viewModel.keteranganController,
|
||||
maxLines: 2,
|
||||
readOnly: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Tanda Tangan",
|
||||
style: regularTextStyle.copyWith(color: mainColor),
|
||||
),
|
||||
SizedBox(
|
||||
height: 150,
|
||||
width: 150,
|
||||
child: viewModel.danaSosialModel == null
|
||||
? Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: mainColor),
|
||||
),
|
||||
)
|
||||
: (viewModel.danaSosialModel!.status! ==
|
||||
'Belum Dikonfirmasi'
|
||||
? const TtdWidget()
|
||||
: Image.asset(
|
||||
'assets/qrcode.png',
|
||||
fit: BoxFit.cover,
|
||||
)),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Text(
|
||||
"Dr. Andi Fitriani D, S.Ag, M.Pd",
|
||||
style: regularTextStyle.copyWith(
|
||||
color: mainColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
// create a horizontal line
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ class DetailDanaSosialViewModel extends CustomBaseViewModel {
|
|||
TextEditingController jenisController = TextEditingController();
|
||||
TextEditingController keteranganController = TextEditingController();
|
||||
|
||||
TextEditingController bentukController = TextEditingController();
|
||||
|
||||
Future<void> init(int id) async {
|
||||
log.i('init and id: $id');
|
||||
getData(id);
|
||||
|
@ -41,7 +43,7 @@ class DetailDanaSosialViewModel extends CustomBaseViewModel {
|
|||
easyLoading.showLoading();
|
||||
try {
|
||||
var response = await _httpService.get('dana_sosial_detail?id=$id');
|
||||
log.i(response.data);
|
||||
log.i(response.data['data']);
|
||||
danaSosialModel = DanaSosialModel.fromJson(response.data['data']);
|
||||
namaController.text = danaSosialModel!.nama!;
|
||||
tanggalController.text = danaSosialModel!.tanggal!;
|
||||
|
@ -50,12 +52,14 @@ class DetailDanaSosialViewModel extends CustomBaseViewModel {
|
|||
jenisController.text = danaSosialModel!.jenisDonasi!;
|
||||
keteranganController.text = danaSosialModel!.keterangan!;
|
||||
|
||||
bentukController.text = danaSosialModel!.bentuk!;
|
||||
|
||||
if (danaSosialModel!.jenisDonasi == 'Uang') {
|
||||
jenisBool = true;
|
||||
} else {
|
||||
jenisBool = false;
|
||||
}
|
||||
log.i('status: ${danaSosialModel!.status}');
|
||||
// log.i('status: ${danaSosialModel!.status}');
|
||||
setBusy(false);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
|
|
Loading…
Reference in New Issue