added add siswa and dana sosial

This commit is contained in:
kicap
2023-05-18 18:58:21 +08:00
parent 949474b8ef
commit e0b5213a3b
14 changed files with 519 additions and 161 deletions

View File

@ -40,89 +40,97 @@ class TambahDanaSosialView extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
child: Form(
key: model.formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Keterangan",
style: regularTextStyle.copyWith(color: mainColor),
),
MyTextFormField(
hintText: "Keterangan",
controller: model.ketController,
maxLines: 3,
validator: Validatorless.required(
'Keterangan tidak boleh kosong'),
),
const SizedBox(height: 20),
Text(
"Jumlah (Rp. )",
style: regularTextStyle.copyWith(color: mainColor),
),
MyTextFormField(
hintText: "Jumlah (Rp. )",
keyboardType: TextInputType.number,
controller: model.jumlahController,
validator: Validatorless.multiple(
[
Validatorless.required('Jumlah tidak boleh kosong'),
Validatorless.number('Jumlah harus angka'),
],
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Keterangan",
style: regularTextStyle.copyWith(color: mainColor),
),
),
const SizedBox(height: 20),
Text(
"Tanggal",
style: regularTextStyle.copyWith(color: mainColor),
),
MyTextFormField(
hintText: 'Tanggal',
readOnly: true,
validator: Validatorless.required(
'Tanggal lahir tidak boleh kosong'),
onTap: () {
model.changeDate(context);
},
),
const SizedBox(height: 20),
Text(
"Jenis Dana",
style: regularTextStyle.copyWith(color: mainColor),
),
Container(
width: double.infinity,
height: 60,
padding: const EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
border: Border.all(
color: mainColor,
MyTextFormField(
hintText: "Keterangan",
controller: model.ketController,
maxLines: 3,
validator: Validatorless.required(
'Keterangan tidak boleh kosong'),
),
const SizedBox(height: 20),
Text(
"Jumlah (Rp. )",
style: regularTextStyle.copyWith(color: mainColor),
),
MyTextFormField(
hintText: "Jumlah (Rp. )",
keyboardType: TextInputType.number,
controller: model.jumlahController,
validator: Validatorless.multiple(
[
Validatorless.required('Jumlah tidak boleh kosong'),
Validatorless.number('Jumlah harus angka'),
],
),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: model.jenisDana,
onChanged: (String? newValue) {
model.jenisDana = newValue!;
},
items: model.jenisDanaList
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value,
style: const TextStyle(fontSize: 16)),
);
}).toList(),
const SizedBox(height: 20),
Text(
"Tanggal",
style: regularTextStyle.copyWith(color: mainColor),
),
MyTextFormField(
hintText: 'Tanggal',
readOnly: true,
controller: model.tanggalController,
validator: Validatorless.required(
'Tanggal lahir tidak boleh kosong'),
onTap: () {
model.changeDate(context);
},
),
const SizedBox(height: 20),
Text(
"Jenis Dana",
style: regularTextStyle.copyWith(color: mainColor),
),
Container(
width: double.infinity,
height: 60,
padding: const EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
border: Border.all(
color: mainColor,
),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: model.jenisDana,
onChanged: (String? newValue) {
model.jenisDana = newValue!;
},
items: model.jenisDanaList
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value,
style: const TextStyle(fontSize: 16)),
);
}).toList(),
),
),
),
),
const SizedBox(height: 20),
MyButton(
text: "Simpan",
onPressed: () {},
),
],
const SizedBox(height: 20),
MyButton(
text: "Simpan",
onPressed: () {
if (model.formKey.currentState!.validate()) {
model.log.i('Form Valid');
model.addData();
}
},
),
],
),
),
),
),

View File

@ -1,7 +1,18 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:panti_asuhan/app/core/custom_base_view_model.dart';
import '../../../app/app.locator.dart';
import '../../../app/app.logger.dart';
import '../../../app/app.router.dart';
import '../../../app/core/custom_base_view_model.dart';
import '../../../services/http_services.dart';
import '../../../services/my_easyloading.dart';
class TambahDanaSosialViewModel extends CustomBaseViewModel {
final log = getLogger('TambahDanaSosialViewModel');
final _httpService = locator<MyHttpServices>();
final easyLoading = locator<MyEasyLoading>();
String jenisDana = 'Pemasukan';
List<String> jenisDanaList = ['Pemasukan', 'Pengeluaran'];
@ -28,4 +39,30 @@ class TambahDanaSosialViewModel extends CustomBaseViewModel {
tanggalController.text = date;
}
}
void addData() async {
easyLoading.customLoading('Menambahkan data...');
try {
var formData = FormData.fromMap({
'jenis': jenisDana,
'keterangan': ketController.text,
'jumlah': jumlahController.text,
'tanggal': tanggalController.text,
});
var response =
await _httpService.postWithFormData('dana_sosial', formData);
log.i(response.data);
easyLoading.showSuccess(" Data berhasil ditambahkan");
navigationService.navigateTo(Routes.adminIndexTrackingView);
} catch (e) {
log.e(e);
snackbarService.showSnackbar(
message: 'Gagal menambahkan data',
title: 'Error',
duration: const Duration(seconds: 4),
);
} finally {
easyLoading.dismissLoading();
}
}
}