slight changes

This commit is contained in:
kicap 2023-11-13 18:33:06 +08:00
parent 667aae745b
commit 41ecbc0065
10 changed files with 139 additions and 52 deletions

View File

@ -67,7 +67,7 @@ class DanaSosialAdminView extends StatelessWidget {
), ),
), ),
Text( Text(
'Rp. 1.000.000', 'Rp. ${OtherFunction().commaFormat(model.jumlahDonasi)}',
style: regularTextStyle.copyWith( style: regularTextStyle.copyWith(
color: Colors.white, color: Colors.white,
fontSize: 15, fontSize: 15,
@ -229,23 +229,47 @@ class TheData extends ViewModelWidget<DanaSosialAdminViewModel> {
trailing: viewModel.isLogin == null trailing: viewModel.isLogin == null
? null ? null
: (viewModel.isLogin == true : (viewModel.isLogin == true
? Container( ? Row(
width: 50, mainAxisSize: MainAxisSize.min,
height: 50, children: [
decoration: BoxDecoration( Container(
color: mainColor, width: 50,
borderRadius: BorderRadius.circular(50), height: 50,
), decoration: BoxDecoration(
child: IconButton( color: mainColor,
onPressed: () { borderRadius: BorderRadius.circular(50),
viewModel.goToEditDanaSosial(int.parse(viewModel ),
.danaSosialModelList[index].idDanaSosial!)); child: IconButton(
}, onPressed: () {
icon: const Icon( viewModel.goToEditDanaSosial(int.parse(viewModel
Icons.edit, .danaSosialModelList[index].idDanaSosial!));
color: Colors.white, },
icon: const Icon(
Icons.edit,
color: Colors.white,
),
),
), ),
), const SizedBox(width: 10),
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(50),
),
child: IconButton(
onPressed: () {
viewModel.deleteData(int.parse(viewModel
.danaSosialModelList[index].idDanaSosial!));
},
icon: const Icon(
Icons.delete,
color: Colors.white,
),
),
),
],
) )
: null), : null),
), ),

View File

@ -17,17 +17,45 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
final _httpService = locator<MyHttpServices>(); final _httpService = locator<MyHttpServices>();
final easyLoading = locator<MyEasyLoading>(); final easyLoading = locator<MyEasyLoading>();
int bulan = DateTime.now().month;
List<DanaSosialModel> danaSosialModelList = []; List<DanaSosialModel> danaSosialModelList = [];
String? role; String? role;
bool? isLogin; bool? isLogin;
int jumlahDonasi = 0;
Future<void> init() async { Future<void> init() async {
await getData(); await getData();
await getJumlahDonasi();
prefs.then((SharedPreferences prefs) { prefs.then((SharedPreferences prefs) {
role = prefs.getString('role'); role = prefs.getString('role');
isLogin = prefs.getBool('isLogin'); isLogin = prefs.getBool('isLogin');
}); });
// log.i(bulan);
}
getJumlahDonasi() async {
setBusy(true);
easyLoading.showLoading();
// get the month
var bulan = DateTime.now().month;
log.i(bulan);
// change bulan to string and add 0 if it is less than 10
String bulanString = bulan.toString().length == 1 ? '0$bulan' : '$bulan';
log.i(bulanString);
try {
var response = await _httpService.get('pemasukan?bulan=$bulanString');
log.i(response.data['jumlah']);
// var theJumlahDonasi = response.data['jumlah'];
jumlahDonasi = response.data['jumlah'];
} catch (e) {
log.e(e);
} finally {
setBusy(false);
easyLoading.dismissLoading();
}
} }
getData() async { getData() async {
@ -35,7 +63,7 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
easyLoading.showLoading(); easyLoading.showLoading();
try { try {
var response = await _httpService.get('dana_sosial'); var response = await _httpService.get('dana_sosial');
log.i(response.data); // log.i(response.data);
danaSosialModelList = []; danaSosialModelList = [];
var datanya = response.data['data']; var datanya = response.data['data'];
@ -72,7 +100,7 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
'filter_dana', 'filter_dana',
formData, formData,
); );
log.i(response.data); // log.i(response.data);
danaSosialModelList = []; danaSosialModelList = [];
var datanya = response.data['data']; var datanya = response.data['data'];
@ -149,4 +177,46 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
), ),
); );
} }
deleteData(int parse) async {
await dialogService
.showDialog(
title: 'Hapus Data',
description: 'Apakah anda yakin ingin menghapus data ini?',
buttonTitle: 'Hapus',
cancelTitle: 'Batal',
buttonTitleColor: Colors.red,
cancelTitleColor: Colors.green,
)
.then(
(value) async {
if (value!.confirmed) {
easyLoading.showLoading();
setBusy(true);
try {
var response = await _httpService.postWithFormData(
'hapus_dana_sosial',
FormData.fromMap({
'id_dana_sosial': parse,
}));
log.i(response.data);
easyLoading.dismissLoading();
easyLoading.showSuccess('Data berhasil dihapus');
getData();
getJumlahDonasi();
} on DioError catch (e) {
// easyLoading.dismissLoading();
log.e(e);
easyLoading.showError('Terjadi kesalahan');
} finally {
setBusy(false);
easyLoading.dismissLoading();
}
} else {
log.i('cancel');
return;
}
},
);
}
} }

View File

@ -51,7 +51,7 @@ class DataSiswaView extends StatelessWidget {
), ),
), ),
Text( Text(
'20 orang', '${model.jumlahSiswa} orang',
style: regularTextStyle.copyWith( style: regularTextStyle.copyWith(
color: Colors.white, color: Colors.white,
fontSize: 15, fontSize: 15,

View File

@ -17,15 +17,33 @@ class DataSiswaViewModel extends CustomBaseViewModel {
List<SiswaModel> siswaModelList = []; List<SiswaModel> siswaModelList = [];
int jumlahSiswa = 0;
String? role; String? role;
Future<void> init() async { Future<void> init() async {
await getData(); await getData();
await getJumlahSiswa();
prefs.then((SharedPreferences prefs) { prefs.then((SharedPreferences prefs) {
role = prefs.getString('role'); role = prefs.getString('role');
}); });
} }
getJumlahSiswa() async {
setBusy(true);
easyLoading.showLoading();
try {
var response = await _httpService.get('jumlah_siswa');
log.i(response.data['data']);
jumlahSiswa = int.parse(response.data['data']['jumlah']);
} catch (e) {
log.e(e);
} finally {
setBusy(false);
easyLoading.dismissLoading();
}
}
getData() async { getData() async {
setBusy(true); setBusy(true);
easyLoading.showLoading(); easyLoading.showLoading();

View File

@ -286,6 +286,7 @@ class EditDialogSiswaView extends StatelessWidget {
bool res = await model.updateSiswa(); bool res = await model.updateSiswa();
if (res) { if (res) {
// ignore: use_build_context_synchronously
Navigator.pop(context); Navigator.pop(context);
completer(DialogResponse(confirmed: true)); completer(DialogResponse(confirmed: true));
} }

View File

@ -252,7 +252,7 @@ class EditSiswaView extends StatelessWidget {
), ),
), ),
) )
: SizedBox(), : const SizedBox(),
model.role == 'admin' model.role == 'admin'
? Positioned( ? Positioned(
top: 0, top: 0,
@ -299,7 +299,7 @@ class EditSiswaView extends StatelessWidget {
), ),
), ),
) )
: SizedBox(), : const SizedBox(),
], ],
), ),
), ),

View File

@ -33,12 +33,12 @@ class DetailDanaSosialView extends StatelessWidget {
body: Padding( body: Padding(
padding: const EdgeInsets.all(15), padding: const EdgeInsets.all(15),
child: model.danaSosialModel == null child: model.danaSosialModel == null
? Center( ? const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
) )
: (model.danaSosialModel!.bentuk == 'Pemasukan' : (model.danaSosialModel!.bentuk == 'Pemasukan'
? PemasukanWidget() ? const PemasukanWidget()
: PengeluaranWidget()), : const PengeluaranWidget()),
), ),
); );
}, },

View File

@ -5,12 +5,10 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import location
import path_provider_foundation import path_provider_foundation
import shared_preferences_foundation import shared_preferences_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
LocationPlugin.register(with: registry.registrar(forPlugin: "LocationPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
} }

View File

@ -464,30 +464,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
location:
dependency: "direct main"
description:
name: location
sha256: "9051959f6f2ccadd887b28b66e9cbbcc25b6838e37cf9e894c421ccc0ebf80b5"
url: "https://pub.dev"
source: hosted
version: "4.4.0"
location_platform_interface:
dependency: transitive
description:
name: location_platform_interface
sha256: "62eeaf1658e92e4459b727f55a3c328eccbac8ba043fa6d262ac5286ad48384c"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
location_web:
dependency: transitive
description:
name: location_web
sha256: "6c08c408a040534c0269c4ff9fe17eebb5a36dea16512fbaf116b9c8bc21545b"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
logger: logger:
dependency: transitive dependency: transitive
description: description:

View File

@ -42,7 +42,7 @@ dependencies:
path_provider: ^2.0.9 path_provider: ^2.0.9
dio: dio:
flutter_easyloading: flutter_easyloading:
location: ^4.4.0 # location: ^4.4.0
google_fonts: google_fonts:
flutter_svg: flutter_svg:
stylish_bottom_bar: ^1.0.0 stylish_bottom_bar: ^1.0.0