first commit

This commit is contained in:
kicap
2024-08-10 07:35:00 +08:00
commit 88390a01ce
34 changed files with 2850 additions and 0 deletions

View File

@ -0,0 +1,110 @@
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import '../../../../app/themes/app_text.dart';
import './log_data_view_model.dart';
class LogDataView extends StatelessWidget {
const LogDataView({super.key});
@override
Widget build(BuildContext context) {
return ViewModelBuilder<LogDataViewModel>.reactive(
viewModelBuilder: () => LogDataViewModel(),
onViewModelReady: (LogDataViewModel model) async {
await model.init();
},
builder: (
BuildContext context,
LogDataViewModel model,
Widget? child,
) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(30),
child: model.isBusy
? const Center(
child: CircularProgressIndicator(),
)
: Table(
border: TableBorder.all(),
children: [
const TableRow(
children: [
TableCell(
child: Center(
child: Text(
'Waktu',
style: boldTextStyle,
),
),
),
TableCell(
child: Center(
child: Text(
'Status',
style: boldTextStyle,
),
),
),
TableCell(
child: Center(
child: Text(
'Ketinggian Air',
style: boldTextStyle,
),
),
),
],
),
...model.dataList.map((data) {
return TableRow(
children: [
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10,
),
child: Text(
data.createdAt!,
style: regularTextStyle,
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10),
child: Text(
data.status! == 0
? "Air Dalam \nTahap Normal"
: data.status! == 1
? "Air Dalam \nTahap Warning"
: "Air Dalam \nTahap Danger",
style: regularTextStyle,
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Center(
child: Text(
data.status == 2
? "${data.waterHeight!} m"
: "-",
style: regularTextStyle,
),
),
),
],
);
}),
],
),
),
);
},
);
}
}

View File

@ -0,0 +1,33 @@
import 'package:flood_app/model/data_model.dart';
import '../../../../app/app.logger.dart';
import '../../../../app/core/custom_base_view_model.dart';
class LogDataViewModel extends CustomBaseViewModel {
final log = getLogger('LogDataViewModel');
List<DataModel> dataList = [];
Future<void> init() async {
await getData(null);
}
getData(String? date) async {
setBusy(true);
try {
// wait 2 seconds
await Future.delayed(const Duration(seconds: 2));
var response = await httpService.get("");
var data = response.data;
data = data['data'];
log.i(data);
for (var i = 0; i < data.length; i++) {
dataList.add(DataModel.fromJson(data[i]));
}
notifyListeners();
} catch (e) {
log.e(e);
} finally {
setBusy(false);
}
}
}