first commit
This commit is contained in:
110
lib/ui/views/nav_bar/log_data/log_data_view.dart
Normal file
110
lib/ui/views/nav_bar/log_data/log_data_view.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
33
lib/ui/views/nav_bar/log_data/log_data_view_model.dart
Normal file
33
lib/ui/views/nav_bar/log_data/log_data_view_model.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user