first commit

This commit is contained in:
kicap
2025-07-13 06:59:30 +08:00
commit 86d84de7e3
165 changed files with 7941 additions and 0 deletions

View File

@ -0,0 +1,152 @@
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();
},
fireOnViewModelReadyOnce: true,
createNewViewModelOnInsert: true,
builder: (
BuildContext context,
LogDataViewModel model,
Widget? child,
) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(30),
child: model.isBusy
? const Center(
child: CircularProgressIndicator(),
)
: SingleChildScrollView(
child: 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(
'Download',
style: boldTextStyle,
),
),
),
TableCell(
child: Center(
child: Text(
'Upload',
style: boldTextStyle,
),
),
),
],
),
...model.otherFunction.listDataOnt.isEmpty
? [
TableRow(
children: List.generate(
4, // Ensure the same number of columns
(index) => TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10),
child: Text(
"Loading...",
style: regularTextStyle,
textAlign: TextAlign.center,
),
),
),
),
),
]
: model.otherFunction.listDataOnt
.map((data) => TableRow(
children: [
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10),
child: Text(
data.getFormattedDate(),
style: regularTextStyle,
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10),
child: Text(
data.status,
style: regularTextStyle,
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10),
child: Text(
data.download == "-"
? "-"
: data.download + " Mbps",
style: regularTextStyle,
textAlign: TextAlign.center,
),
),
),
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10),
child: Text(
data.upload == "-"
? "-"
: data.upload + " Mbps",
style: regularTextStyle,
textAlign: TextAlign.center,
),
),
),
],
))
.toList(),
],
),
),
),
);
},
);
}
}

View File

@ -0,0 +1,15 @@
import 'dart:async';
import '../../../../app/app.logger.dart';
import '../../../../app/core/custom_base_view_model.dart';
class LogDataViewModel extends CustomBaseViewModel {
final log = getLogger('LogDataViewModel');
Future<void> init() async {
Timer.periodic(const Duration(seconds: 10), (timer) {
log.i('timer dan refresh data');
notifyListeners();
});
}
}

View File

@ -0,0 +1,137 @@
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import '../../../../app/themes/app_colors.dart';
import '../../../../app/themes/app_text.dart';
import './monitoring_view_model.dart';
class MonitoringView extends StatelessWidget {
const MonitoringView({super.key});
@override
Widget build(BuildContext context) {
return ViewModelBuilder<MonitoringViewModel>.reactive(
viewModelBuilder: () => MonitoringViewModel(),
onViewModelReady: (MonitoringViewModel model) async {
await model.init();
},
fireOnViewModelReadyOnce: true,
createNewViewModelOnInsert: true,
builder: (
BuildContext context,
MonitoringViewModel model,
Widget? child,
) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(30),
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Monitoring Router",
style: boldTextStyle.copyWith(fontSize: 30),
),
const SizedBox(height: 20),
const Image(
image: AssetImage("assets/logo.png"),
width: 125,
height: 125,
),
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(20),
width: double.infinity,
decoration: BoxDecoration(
color: mainColor,
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TheText(
title: 'Nama',
text: model.otherFunction.ontModel!.nama!,
),
TheText(
title: 'No Internet',
text: model.otherFunction.ontModel!.noInternet!,
),
TheText(
title: 'No Telpon',
text: model.otherFunction.ontModel!.noHp!,
),
TheText(
title: 'Alamat',
text: model.otherFunction.ontModel!.alamat!,
),
TheText(
title: 'Paket',
text: model.otherFunction.ontModel!.langganan!,
),
TheText(
title: 'Status',
text: model.otherFunction.ontModel!.status!,
),
TheText(
title: 'Speed',
// text: "0.04 Mbps Down/0.03Mbps Up",
text:
"${model.otherFunction.ontModel!.download!} Mbps Down/${model.otherFunction.ontModel!.upload!} Mbps Up",
),
TheText(
title: 'Last Updated',
// text: "2023-01-01 00:00:00",
text: model.otherFunction.ontModel!
.getFormattedDate(),
),
],
),
),
],
),
),
),
),
);
},
);
}
}
class TheText extends StatelessWidget {
const TheText({
super.key,
required this.title,
required this.text,
});
final String title;
final String text;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 10),
child: RichText(
text: TextSpan(
text: '$title : ',
style: boldTextStyle.copyWith(
color: lightColor,
),
children: [
TextSpan(
text: text,
style: regularTextStyle.copyWith(
color: lightColor,
),
),
],
),
),
);
}
}

View File

@ -0,0 +1,15 @@
import 'dart:async';
import '../../../../app/app.logger.dart';
import '../../../../app/core/custom_base_view_model.dart';
class MonitoringViewModel extends CustomBaseViewModel {
final log = getLogger('MonitoringViewModel');
Future<void> init() async {
Timer.periodic(const Duration(seconds: 5), (timer) {
log.i('timer dan refresh data');
notifyListeners();
});
}
}

View File

@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:stylish_bottom_bar/stylish_bottom_bar.dart';
import '../../../app/app.router.dart';
import '../../../app/themes/app_colors.dart';
import '../../../app/themes/app_text.dart';
import './nav_bar_view_model.dart';
class NavBarView extends StatelessWidget {
const NavBarView({super.key});
@override
Widget build(BuildContext context) {
return ViewModelBuilder<NavBarViewModel>.reactive(
viewModelBuilder: () => NavBarViewModel(),
onViewModelReady: (NavBarViewModel model) async {
await model.init();
},
builder: (
BuildContext context,
NavBarViewModel model,
Widget? child,
) {
return PopScope(
canPop: false,
child: Scaffold(
appBar: AppBar(
backgroundColor: mainColor,
title: Text(
model.bottomNavBarList[model.currentIndex]['name'],
style: boldTextStyle.copyWith(color: fifthGrey),
),
),
body: ExtendedNavigator(
navigatorKey: StackedService.nestedNavigationKey(3),
router: NavBarViewRouter(),
initialRoute: NavBarViewRoutes.monitoringView,
),
bottomNavigationBar: StylishBottomBar(
items: [
for (var item in model.bottomNavBarList)
BottomBarItem(
icon: Icon(item['icon'],
color: model.currentIndex ==
model.bottomNavBarList.indexOf(item)
? fifthGrey
: backgroundColor),
title: Text(
item['name'],
style: regularTextStyle.copyWith(
color: model.currentIndex ==
model.bottomNavBarList.indexOf(item)
? fifthGrey
: mainGrey,
),
),
backgroundColor: model.currentIndex ==
model.bottomNavBarList.indexOf(item)
? fontColor
: mainGrey,
),
],
currentIndex: model.currentIndex,
hasNotch: true,
backgroundColor: mainColor,
onTap: (value) {
model.handleNavigation(value);
},
option: BubbleBarOptions(
barStyle: BubbleBarStyle.horizontal,
bubbleFillStyle: BubbleFillStyle.fill,
opacity: 0.3),
),
),
);
},
);
}
}

View File

@ -0,0 +1,158 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:ont_app2/model/ont_data_model.dart';
import 'package:ont_app2/model/ont_model.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
import '../../../app/app.locator.dart';
import '../../../app/app.logger.dart';
import '../../../app/app.router.dart';
import '../../../services/http_services.dart';
import '../../../services/my_notification.dart';
import '../../../services/my_preferences.dart';
import '../../../services/my_socket_io_client.dart';
import '../../../services/other_function.dart';
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
class NavBarViewModel extends IndexTrackingViewModel {
final log = getLogger('NavBarViewModel');
final _navigationService = locator<NavigationService>();
final _mySharedPrefs = locator<MySharedPrefs>();
final _socketIoClient = locator<MySocketIoClient>();
final _myNotification = locator<MyNotification>();
final _otherFunction = locator<OtherFunction>();
final _httpServices = locator<MyHttpServices>();
final _bottomNavBarList = [
{
'name': 'Monitoring',
'icon': Icons.home_outlined,
},
{
'name': 'Log Data',
'icon': Icons.list_alt_outlined,
},
];
List<Map<String, dynamic>> get bottomNavBarList => _bottomNavBarList;
final List<String> _views = [
NavBarViewRoutes.monitoringView,
NavBarViewRoutes.logDataView,
];
Future<void> init() async {
String? id = await _mySharedPrefs.getString('id');
refreshData(id!);
Timer.periodic(const Duration(seconds: 10), (timer) {
log.i('timer dan refresh data');
refreshData(id);
refreshOnt(id);
});
// _socketIoClient.on('data', (data) {
// // log.i('data : $data');
// var waterHeight = data['water_height'];
// _socketIoClient.waterHeight = waterHeight is int
// ? waterHeight.toDouble()
// : waterHeight is double
// ? waterHeight
// : double.parse(waterHeight as String);
// _socketIoClient.warningLevel = data['warning_level'];
// _socketIoClient.dangerLevel = data['danger_level'];
// if (_socketIoClient.dangerLevel == 1) {
// _socketIoClient.status =
// "Bahaya , Peringatan Banjir, Air Melewati Batas";
// if (_socketIoClient.notif < 2) {
// _myNotification.showNotification(
// id: 1,
// title: 'Peringatan Banjir',
// body: 'Air Melewati Batas',
// payload: 'payload',
// flutterLocalNotificationsPlugin: flutterLocalNotificationsPlugin,
// );
// _socketIoClient.notif = 2;
// }
// } else if (_socketIoClient.warningLevel == 1) {
// _socketIoClient.status =
// "Peringatan Banjir, Air Dalam Skala 4:5 atau lebih";
// if (_socketIoClient.notif == 0) {
// _myNotification.showNotification(
// id: 2,
// title: 'Peringatan Banjir',
// body: 'Air Dalam Skala 4:5 atau lebih',
// payload: 'payload',
// flutterLocalNotificationsPlugin: flutterLocalNotificationsPlugin,
// );
// _socketIoClient.notif = 1;
// }
// } else {
// _socketIoClient.status = "Normal";
// _socketIoClient.notif = 0;
// }
// notifyListeners();
// });
}
refreshData(String id) async {
log.wtf("lakukan pengambilan data");
setBusy(true);
try {
var res = await _httpServices.get('/data_ont?id=$id', stat: false);
List<Map<String, dynamic>> data =
List<Map<String, dynamic>>.from(res.data);
List<OntDataModel> dataModel =
data.map((e) => OntDataModel.fromJson(e)).toList();
_otherFunction.listDataOnt.clear();
_otherFunction.listDataOnt = dataModel;
for (var i = 0; i < dataModel.length; i++) {
log.i(dataModel[i].toJson());
}
notifyListeners();
} catch (e) {
log.e(e);
} finally {
setBusy(false);
}
}
refreshOnt(String id) async {
log.wtf("lakukan pengambilan data ont");
setBusy(true);
try {
var res = await _httpServices.get('/data-ont/$id', stat: false);
log.wtf(res.data);
OntModel data = OntModel.fromJson(res.data);
_otherFunction.ontModel = data;
notifyListeners();
} catch (e) {
log.e(e);
log.e("Disini yang error");
} finally {
setBusy(false);
}
}
void handleNavigation(int index) {
log.d("handleNavigation: $index");
log.d("currentIndex: $currentIndex");
if (currentIndex == index) return;
setIndex(index);
// header = _bottomNavBarList[index]['header'] as String;
_navigationService.navigateTo(
_views[index],
id: 3,
);
}
}