first commit
This commit is contained in:
91
lib/ui/views/login/login_view.dart
Normal file
91
lib/ui/views/login/login_view.dart
Normal file
@ -0,0 +1,91 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ont_app2/ui/widgets/my_button.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:validatorless/validatorless.dart';
|
||||
|
||||
import '../../widgets/my_textformfield.dart';
|
||||
import './login_view_model.dart';
|
||||
|
||||
class LoginView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<LoginViewModel>.reactive(
|
||||
viewModelBuilder: () => LoginViewModel(),
|
||||
onViewModelReady: (LoginViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
LoginViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
child: Form(
|
||||
key: model.formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Image(
|
||||
image: AssetImage("assets/logo1.png"),
|
||||
width: 200,
|
||||
height: 200,
|
||||
),
|
||||
const Text(
|
||||
"Silahkan Login",
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
MyTextFormField(
|
||||
controller: model.nomorInternetController,
|
||||
labelText: "Nomor Internet",
|
||||
hintText: "Masukkan Nomor Internet",
|
||||
prefixIcon: const Icon(
|
||||
Icons.phone,
|
||||
),
|
||||
validator: Validatorless.multiple(
|
||||
[
|
||||
Validatorless.required("Masukkan Nomor Internet"),
|
||||
Validatorless.min(
|
||||
12, "Nomor Internet harus 12 angka"),
|
||||
Validatorless.number(
|
||||
"Nomor Internet harus berupa angka"),
|
||||
],
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 12,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
MyTextFormField(
|
||||
controller: model.passwordController,
|
||||
labelText: "Password",
|
||||
hintText: "Masukkan Password",
|
||||
obscureText: true,
|
||||
prefixIcon: const Icon(
|
||||
Icons.lock,
|
||||
),
|
||||
validator: Validatorless.required("Masukkan Password"),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
MyButton(
|
||||
text: "Login",
|
||||
onPressed: () {
|
||||
// if (!model.formKey.currentState!.validate()) {
|
||||
// return;
|
||||
// }
|
||||
model.login();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
64
lib/ui/views/login/login_view_model.dart
Normal file
64
lib/ui/views/login/login_view_model.dart
Normal file
@ -0,0 +1,64 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../app/app.logger.dart';
|
||||
import '../../../app/app.router.dart';
|
||||
import '../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../app/enum/snackbar_enum.dart';
|
||||
import '../../../model/ont_model.dart';
|
||||
|
||||
class LoginViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('LoginViewModel');
|
||||
|
||||
// form variable
|
||||
final formKey = GlobalKey<FormState>();
|
||||
TextEditingController nomorInternetController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
|
||||
Future<void> init() async {}
|
||||
|
||||
login() async {
|
||||
log.wtf('login proses');
|
||||
easyLoading.customLoading("Login...");
|
||||
setBusy(true);
|
||||
|
||||
try {
|
||||
var formData = FormData.fromMap({
|
||||
"no_internet": nomorInternetController.text,
|
||||
"password": passwordController.text,
|
||||
});
|
||||
var res = await httpService.postWithFormData(
|
||||
'login',
|
||||
formData,
|
||||
);
|
||||
|
||||
// log.wtf(res.statusCode);
|
||||
if (res.statusCode == 200) {
|
||||
// log.wtf(res.data["data"]['id']);
|
||||
OntModel ontModel = OntModel.fromJson(res.data["data"]);
|
||||
otherFunction.ontModel = ontModel;
|
||||
await mySharedPrefs.setString('id', ontModel.id.toString());
|
||||
// log.wtf(await mySharedPrefs.getString('id'));
|
||||
// log.wtf(ontModel.toJson());
|
||||
// snackbarService.showCustomSnackBar(
|
||||
// message: "Login Berhasil",
|
||||
// variant: SnackbarType.sukses,
|
||||
// duration: const Duration(milliseconds: 2000),
|
||||
// );
|
||||
// await 2 seconds
|
||||
// await Future.delayed(const Duration(seconds: 2));
|
||||
navigationService.replaceWith(Routes.navBarView);
|
||||
snackbarService.showCustomSnackBar(
|
||||
message: "Login Berhasil",
|
||||
variant: SnackbarType.sukses,
|
||||
duration: const Duration(milliseconds: 10000),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
return;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
easyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
152
lib/ui/views/nav_bar/log_data/log_data_view.dart
Normal file
152
lib/ui/views/nav_bar/log_data/log_data_view.dart
Normal 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(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
15
lib/ui/views/nav_bar/log_data/log_data_view_model.dart
Normal file
15
lib/ui/views/nav_bar/log_data/log_data_view_model.dart
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
137
lib/ui/views/nav_bar/monitoring/monitoring_view.dart
Normal file
137
lib/ui/views/nav_bar/monitoring/monitoring_view.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
15
lib/ui/views/nav_bar/monitoring/monitoring_view_model.dart
Normal file
15
lib/ui/views/nav_bar/monitoring/monitoring_view_model.dart
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
81
lib/ui/views/nav_bar/nav_bar_view.dart
Normal file
81
lib/ui/views/nav_bar/nav_bar_view.dart
Normal 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),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
158
lib/ui/views/nav_bar/nav_bar_view_model.dart
Normal file
158
lib/ui/views/nav_bar/nav_bar_view_model.dart
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
61
lib/ui/views/splash_screen/splash_screen_view.dart
Normal file
61
lib/ui/views/splash_screen/splash_screen_view.dart
Normal file
@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
import '../../../app/themes/app_text.dart';
|
||||
import './splash_screen_view_model.dart';
|
||||
|
||||
class SplashScreenView extends StatelessWidget {
|
||||
const SplashScreenView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<SplashScreenViewModel>.nonReactive(
|
||||
viewModelBuilder: () => SplashScreenViewModel(),
|
||||
onViewModelReady: (SplashScreenViewModel model) async {
|
||||
await model.init();
|
||||
},
|
||||
builder: (
|
||||
BuildContext context,
|
||||
SplashScreenViewModel model,
|
||||
Widget? child,
|
||||
) {
|
||||
return Scaffold(
|
||||
// backgroundColor: mainColor,
|
||||
body: Column(
|
||||
children: [
|
||||
const SizedBox(),
|
||||
Expanded(
|
||||
child: Center(
|
||||
// show the logo.png
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Image(
|
||||
image: AssetImage("assets/logo1.png"),
|
||||
width: 200,
|
||||
height: 200,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
"Monitoring Indihome Router",
|
||||
style: boldTextStyle.copyWith(
|
||||
fontSize: 20,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const Text(
|
||||
"Made with Flutter and Passion By Febri",
|
||||
textAlign: TextAlign.center,
|
||||
style: regularTextStyle,
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
23
lib/ui/views/splash_screen/splash_screen_view_model.dart
Normal file
23
lib/ui/views/splash_screen/splash_screen_view_model.dart
Normal file
@ -0,0 +1,23 @@
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
|
||||
import '../../../app/app.logger.dart';
|
||||
import '../../../app/app.router.dart';
|
||||
import '../../../app/core/custom_base_view_model.dart';
|
||||
import '../../../services/my_notification.dart';
|
||||
|
||||
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
|
||||
class SplashScreenViewModel extends CustomBaseViewModel {
|
||||
final log = getLogger('SplashScreenViewModel');
|
||||
Future<void> init() async {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
// navigate to login page
|
||||
// ignore: use_build_context_synchronously
|
||||
MyNotification.initialize(flutterLocalNotificationsPlugin);
|
||||
socketIoClient.init();
|
||||
// socketIoClient.connect();
|
||||
|
||||
navigationService.replaceWith(Routes.loginView);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user