added add siswa and dana sosial
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:panti_asuhan/services/other_function.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
@ -75,38 +76,45 @@ class DataSiswaView extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15, vertical: 10),
|
||||
itemCount: 20,
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
model.log.i('Card $index tapped');
|
||||
child: (model.siswaModelList.isEmpty)
|
||||
? Center(
|
||||
child: Text(
|
||||
'Tidak ada data',
|
||||
style: boldTextStyle.copyWith(
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
)
|
||||
: // ListView.builder(
|
||||
ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15, vertical: 10),
|
||||
itemCount: model.siswaModelList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
model.siswaModelList[index].nama ?? '',
|
||||
style: boldTextStyle.copyWith(
|
||||
fontSize: 13, color: mainColor)),
|
||||
subtitle: Text(
|
||||
'Umur : ${OtherFunction().umur(model.siswaModelList[index].tanggalLahir ?? '')}'),
|
||||
// circle avatar
|
||||
trailing: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person,
|
||||
color: Colors.white,
|
||||
),
|
||||
)),
|
||||
);
|
||||
},
|
||||
child: ListTile(
|
||||
title: Text('Namanya',
|
||||
style: boldTextStyle.copyWith(
|
||||
fontSize: 13, color: mainColor)),
|
||||
subtitle: Text('Umurnya : $index'),
|
||||
// circle avatar
|
||||
trailing: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: mainColor,
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person,
|
||||
color: Colors.white,
|
||||
),
|
||||
)),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@ -1,12 +1,49 @@
|
||||
import 'package:panti_asuhan/app/core/custom_base_view_model.dart';
|
||||
|
||||
import '../../../../app/app.dialogs.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';
|
||||
import '../add_siswa_dialog/add_siswa_dialog/add_siswa_dialog_view.dart';
|
||||
|
||||
class DataSiswaViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('DataSiswaViewModel');
|
||||
Future<void> init() async {}
|
||||
final _httpService = locator<MyHttpServices>();
|
||||
final easyLoading = locator<MyEasyLoading>();
|
||||
|
||||
List<SiswaModel> siswaModelList = [];
|
||||
|
||||
Future<void> init() async {
|
||||
await getData();
|
||||
}
|
||||
|
||||
getData() async {
|
||||
setBusy(true);
|
||||
easyLoading.showLoading();
|
||||
try {
|
||||
var response = await _httpService.get('siswa');
|
||||
log.i(response.data);
|
||||
siswaModelList = [];
|
||||
|
||||
var datanya = response.data['data'];
|
||||
// log.i(datanya.length);
|
||||
if (datanya.length > 0) {
|
||||
for (var item in datanya) {
|
||||
siswaModelList.add(SiswaModel.fromJson(item));
|
||||
}
|
||||
}
|
||||
|
||||
setBusy(false);
|
||||
notifyListeners();
|
||||
log.i(siswaModelList);
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
setBusy(false);
|
||||
} finally {
|
||||
easyLoading.dismissLoading();
|
||||
}
|
||||
}
|
||||
|
||||
void addSiswa() async {
|
||||
final res = await dialogService.showCustomDialog(
|
||||
@ -15,5 +52,7 @@ class DataSiswaViewModel extends CustomBaseViewModel {
|
||||
);
|
||||
|
||||
if (res?.confirmed != true) return;
|
||||
siswaModelList = [];
|
||||
await getData();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user