From 9b5147b565a73533ca6e39d47bd6b241cef4acf8 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Tue, 10 May 2022 17:38:19 +0300 Subject: [PATCH] merge improvements --- lib/api/api_client.dart | 6 +++++- lib/app_state/app_state.dart | 4 ++++ lib/classes/utils.dart | 5 +++-- lib/provider/dashboard_provider_model.dart | 4 ++-- lib/ui/landing/dashboard_screen.dart | 2 +- lib/ui/landing/today_attendance_screen.dart | 11 +++++------ lib/ui/login/login_screen.dart | 4 +--- .../missing_swipe/fragments/info_fragments.dart | 4 ++-- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index 17eac0d..3263bf4 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -5,6 +5,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; import 'package:http/io_client.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/exceptions/api_exception.dart'; import '../main.dart'; @@ -81,6 +82,9 @@ class ApiClient { logger.i("res: " + response.body); } var jsonData = jsonDecode(response.body); + if (jsonData["IsAuthenticated"] != null) { + AppState().setIsAuthenticated = jsonData["IsAuthenticated"]; + } if (jsonData["ErrorMessage"] == null) { return factoryConstructor(jsonData); } else { @@ -237,4 +241,4 @@ class ApiClient { } Future _post(url, {Map? headers, body, Encoding? encoding}) => _withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding)); - } +} diff --git a/lib/app_state/app_state.dart b/lib/app_state/app_state.dart index 51337ff..de05b56 100644 --- a/lib/app_state/app_state.dart +++ b/lib/app_state/app_state.dart @@ -12,6 +12,10 @@ class AppState { factory AppState() => _instance; + bool isAuthenticated = false; + + set setIsAuthenticated(v) => isAuthenticated = v; + bool isLogged = false; set setLogged(v) => isLogged = v; diff --git a/lib/classes/utils.dart b/lib/classes/utils.dart index d3081d4..1634fd5 100644 --- a/lib/classes/utils.dart +++ b/lib/classes/utils.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/config/routes.dart'; // import 'package:fluttertoast/fluttertoast.dart'; @@ -83,12 +84,12 @@ class Utils { if (onErrorMessage != null) { onErrorMessage(errorMessage); } else { - if (errorMessage.contains("User session is not valid")) { + if (!AppState().isAuthenticated) { showDialog( context: cxt, builder: (cxt) => ConfirmDialog( message: errorMessage, - onTap: (){ + onTap: () { Navigator.pushNamedAndRemoveUntil(cxt, AppRoutes.login, (Route route) => false); }, ), diff --git a/lib/provider/dashboard_provider_model.dart b/lib/provider/dashboard_provider_model.dart index 61b66c6..9316182 100644 --- a/lib/provider/dashboard_provider_model.dart +++ b/lib/provider/dashboard_provider_model.dart @@ -71,8 +71,8 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin { return ((hour * 60 * 60) + (mints * 60) + seconds); } - update() { - fetchAttendanceTracking(); + update(context) { + fetchAttendanceTracking(context); // isAttendanceTrackingLoading = !isAttendanceTrackingLoading; // isWorkListLoading = !isWorkListLoading; // attendanceTracking?.pSwipeIn = "a"; diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index 4d9fdef..029da02 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -96,7 +96,7 @@ class _DashboardScreenState extends State { ], ), ).onPress(() { - data.update(); + data.update(context); }) ], ).paddingOnly(left: 21, right: 21, top: 48, bottom: 7), diff --git a/lib/ui/landing/today_attendance_screen.dart b/lib/ui/landing/today_attendance_screen.dart index cfba3fd..6268425 100644 --- a/lib/ui/landing/today_attendance_screen.dart +++ b/lib/ui/landing/today_attendance_screen.dart @@ -42,7 +42,7 @@ class _TodayAttendanceScreenState extends State { data = Provider.of(context, listen: false); } - checkAttendanceAvailablity() async { + void checkAttendanceAvailablity() async { bool isAvailable = await NfcManager.instance.isAvailable(); setState(() { AppState().privilegeListModel!.forEach((element) { @@ -84,7 +84,7 @@ class _TodayAttendanceScreenState extends State { actions: [ IconButton( onPressed: () { - data.fetchAttendanceTracking(); + data.fetchAttendanceTracking(context); }, icon: Icon( Icons.ac_unit, @@ -192,8 +192,7 @@ class _TodayAttendanceScreenState extends State { attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () { if (isNfcLocationEnabled) { Location.getCurrentLocation((LatLng? latlng) { - print(latlng!.longitude.toString()); - performNfcAttendance(model, lat: latlng.latitude.toString() ?? "", lng: latlng.longitude.toString() ?? ""); + performNfcAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); }); } else { performNfcAttendance(model); @@ -246,12 +245,12 @@ class _TodayAttendanceScreenState extends State { Utils.showLoading(context); try { GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "", isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng); - bool status = await model.fetchAttendanceTracking(); + bool status = await model.fetchAttendanceTracking(context); Utils.hideLoading(context); } catch (ex) { print(ex); Utils.hideLoading(context); - Utils.handleException(ex, (msg) { + Utils.handleException(ex, context, (msg) { Utils.confirmDialog(context, msg); }); } diff --git a/lib/ui/login/login_screen.dart b/lib/ui/login/login_screen.dart index 9b09023..29fbbfe 100644 --- a/lib/ui/login/login_screen.dart +++ b/lib/ui/login/login_screen.dart @@ -75,18 +75,16 @@ class _LoginScreenState extends State { Utils.showLoading(context); firebaseToken = await _firebaseMessaging.getToken(); loginInfo = await LoginApiClient().getMobileLoginInfoNEW(firebaseToken ?? "", Platform.isAndroid ? "android" : "ios"); - loginInfo!.deviceToken = firebaseToken; if (loginInfo == null) { Utils.hideLoading(context); - print("Device token not found"); return; } else { + loginInfo!.deviceToken = firebaseToken; await checkPrefs(); Utils.hideLoading(context); performLogin(); } } catch (ex) { - print(ex); Utils.hideLoading(context); Utils.handleException(ex, context, null); } diff --git a/lib/ui/work_list/missing_swipe/fragments/info_fragments.dart b/lib/ui/work_list/missing_swipe/fragments/info_fragments.dart index df883c8..ba0e57e 100644 --- a/lib/ui/work_list/missing_swipe/fragments/info_fragments.dart +++ b/lib/ui/work_list/missing_swipe/fragments/info_fragments.dart @@ -165,13 +165,13 @@ class InfoFragment extends StatelessWidget { ItemDetailView(LocaleKeys.operatingUnit.tr(), itemCreationHeader[index].oPERATINGUNIT?.toString() ?? ""), ItemDetailView(LocaleKeys.category.tr(), itemCreationHeader[index].cATEGORY?.toString() ?? ""), ItemDetailView(LocaleKeys.requester.tr(), itemCreationHeader[index].rEQUESTER?.toString() ?? ""), - ItemDetailView(LocaleKeys.analyzedBy.tr(), itemCreationHeader[index].aNALYZEDBY.toString() ?? ""), + ItemDetailView(LocaleKeys.analyzedBy.tr(), itemCreationHeader[index].aNALYZEDBY?.toString() ?? ""), ItemDetailView(LocaleKeys.approvedDate.tr(), itemCreationHeader[index].aPPROVEDDATE?.toString() ?? ""), ItemDetailView(LocaleKeys.itemType.tr(), itemCreationHeader[index].iTEMTYPE?.toString() ?? ""), ItemDetailView(LocaleKeys.relatedTo.tr(), itemCreationHeader[index].rELATEDTO?.toString() ?? ""), ItemDetailView(LocaleKeys.requestDate.tr(), DateUtil.formatDateToDate(DateUtil.convertStringToDate(itemCreationHeader[index].rEQUESTDATE.toString()), false) ?? ""), ItemDetailView(LocaleKeys.analyzedDate.tr(), itemCreationHeader[index].aNALYZEDDATE?.toString() ?? ""), - ItemDetailView(LocaleKeys.urgent.tr(), itemCreationHeader[index].uRGENTFLAGDISP.toString() ?? ""), + ItemDetailView(LocaleKeys.urgent.tr(), itemCreationHeader[index].uRGENTFLAGDISP?.toString() ?? ""), ], ).objectContainerView(), separatorBuilder: (cxt, index) => 18.height,