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

View File

@ -17,17 +17,45 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
final _httpService = locator<MyHttpServices>();
final easyLoading = locator<MyEasyLoading>();
int bulan = DateTime.now().month;
List<DanaSosialModel> danaSosialModelList = [];
String? role;
bool? isLogin;
int jumlahDonasi = 0;
Future<void> init() async {
await getData();
await getJumlahDonasi();
prefs.then((SharedPreferences prefs) {
role = prefs.getString('role');
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 {
@ -35,7 +63,7 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
easyLoading.showLoading();
try {
var response = await _httpService.get('dana_sosial');
log.i(response.data);
// log.i(response.data);
danaSosialModelList = [];
var datanya = response.data['data'];
@ -72,7 +100,7 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
'filter_dana',
formData,
);
log.i(response.data);
// log.i(response.data);
danaSosialModelList = [];
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(
'20 orang',
'${model.jumlahSiswa} orang',
style: regularTextStyle.copyWith(
color: Colors.white,
fontSize: 15,

View File

@ -17,15 +17,33 @@ class DataSiswaViewModel extends CustomBaseViewModel {
List<SiswaModel> siswaModelList = [];
int jumlahSiswa = 0;
String? role;
Future<void> init() async {
await getData();
await getJumlahSiswa();
prefs.then((SharedPreferences prefs) {
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 {
setBusy(true);
easyLoading.showLoading();

View File

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

View File

@ -252,7 +252,7 @@ class EditSiswaView extends StatelessWidget {
),
),
)
: SizedBox(),
: const SizedBox(),
model.role == 'admin'
? Positioned(
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(
padding: const EdgeInsets.all(15),
child: model.danaSosialModel == null
? Center(
? const Center(
child: CircularProgressIndicator(),
)
: (model.danaSosialModel!.bentuk == 'Pemasukan'
? PemasukanWidget()
: PengeluaranWidget()),
? const PemasukanWidget()
: const PengeluaranWidget()),
),
);
},

View File

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

View File

@ -464,30 +464,6 @@ packages:
url: "https://pub.dev"
source: hosted
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:
dependency: transitive
description:

View File

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