first commit
This commit is contained in:
161
lib/ui/views/caleg_index_tracking/log_suara/log_suara_view.dart
Normal file
161
lib/ui/views/caleg_index_tracking/log_suara/log_suara_view.dart
Normal file
@ -0,0 +1,161 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../../../../app/themes/app_colors.dart';
|
||||
import '../../../../app/themes/app_text.dart';
|
||||
import './log_suara_view_model.dart';
|
||||
|
||||
class LogSuaraView extends StatelessWidget {
|
||||
const LogSuaraView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<LogSuaraViewModel>.reactive(
|
||||
viewModelBuilder: () => LogSuaraViewModel(),
|
||||
onViewModelReady: (LogSuaraViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
LogSuaraViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Scaffold(
|
||||
body: WillPopScope(
|
||||
onWillPop: () async {
|
||||
// model.log.i('backPressed: ${model.globalVar.backPressed}');
|
||||
if (model.globalVar.backPressed == 'exitApp') {
|
||||
// model.back();
|
||||
model.quitApp(context);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: SafeArea(
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: warningColor,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"Jumlah Suara : ",
|
||||
style: italicTextStyle.copyWith(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${model.counter} suara',
|
||||
style: boldTextStyle.copyWith(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.people_alt_outlined,
|
||||
color: fontColor,
|
||||
),
|
||||
// SizedBox(width: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: Container(
|
||||
alignment: model.isBusy
|
||||
? Alignment.center
|
||||
: model.status == true
|
||||
? model.counter > 0
|
||||
? Alignment.topCenter
|
||||
: Alignment.center
|
||||
: Alignment.center,
|
||||
height: double.infinity,
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: warningColor,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (model.isBusy)
|
||||
const Center(
|
||||
child: CircularProgressIndicator()),
|
||||
if (!model.isBusy &&
|
||||
model.status == true &&
|
||||
model.counter > 0)
|
||||
for (var i = 0; i < model.counter; i++)
|
||||
Card(
|
||||
child: ListTile(
|
||||
// leading is datetime dummy
|
||||
leading: Text(model.myFunction
|
||||
.convertDateTime2(model
|
||||
.listPemilih[i].createdAt!)),
|
||||
title: Text(
|
||||
model.listPemilih[i].namaPemilih!,
|
||||
style: boldTextStyle,
|
||||
),
|
||||
subtitle: Text(
|
||||
model.listPemilih[i].namaArea!,
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.info_outline,
|
||||
color: mainColor,
|
||||
),
|
||||
onPressed: () {
|
||||
model.showDetailPemilih(
|
||||
model.listPemilih[i],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!model.isBusy &&
|
||||
model.status == true &&
|
||||
model.counter == 0)
|
||||
const Center(
|
||||
child: Text(
|
||||
'Belum ada data',
|
||||
style: boldTextStyle,
|
||||
),
|
||||
),
|
||||
if (!model.isBusy && model.status == false)
|
||||
const Center(
|
||||
child: Text(
|
||||
'Error: Gagal mengambil data dari server',
|
||||
style: boldTextStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
import '../../../../app/app.bottomsheets.dart';
|
||||
import '../../../../app/app.logger.dart';
|
||||
import '../../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../../model/my_response.model.dart';
|
||||
import '../../../../model/pemilih_model.dart';
|
||||
|
||||
class LogSuaraViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('LogSuaraViewModel');
|
||||
int counter = 0;
|
||||
List<PemilihModel> listPemilih = [];
|
||||
bool status = false;
|
||||
|
||||
Future<void> init() async {
|
||||
globalVar.backPressed = 'exitApp';
|
||||
String? idCaleg = await mySharedPrefs.getString('id');
|
||||
await getData(idCaleg!);
|
||||
}
|
||||
|
||||
getData(String idCaleg) async {
|
||||
setBusy(true);
|
||||
|
||||
try {
|
||||
var response = await httpService.get('caleg/suara/$idCaleg');
|
||||
MyResponseModel myResponseModel = MyResponseModel.fromJson(response.data);
|
||||
PemilihDetailModel pemilihDetailModel =
|
||||
PemilihDetailModel.fromJson(myResponseModel.data);
|
||||
listPemilih = pemilihDetailModel.pemilihModel!;
|
||||
counter = listPemilih.length;
|
||||
|
||||
status = true;
|
||||
} catch (e) {
|
||||
log.e('error: $e');
|
||||
status = false;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
showDetailPemilih(PemilihModel listPemilih) async {
|
||||
await bottomSheetService.showCustomSheet(
|
||||
variant: BottomSheetType.detailSuaraPemilihBottomSheetView,
|
||||
title: 'Detail Suara Pemilih',
|
||||
description: 'Detail Suara Pemilih',
|
||||
// isScrollControlled: true,
|
||||
data: listPemilih,
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user