WIP FIX
This commit is contained in:
parent
9427c0bdb2
commit
e646f56bff
|
@ -1,5 +1,3 @@
|
|||
|
||||
import 'package:hub/shared/helpers/sqlite_storage_helper.dart';
|
||||
import 'package:hub/shared/utils/storage_util.dart';
|
||||
|
||||
import '/flutter_flow/flutter_flow_util.dart';
|
||||
|
|
|
@ -5,10 +5,8 @@ import 'package:flutter/material.dart';
|
|||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:hub/backend/api_requests/api_calls.dart';
|
||||
import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart';
|
||||
import 'package:hub/shared/helpers/sqlite_storage_helper.dart';
|
||||
import 'package:hub/shared/utils/dialog_util.dart';
|
||||
import 'package:hub/shared/utils/storage_util.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '/flutter_flow/custom_functions.dart' as functions;
|
||||
import '/flutter_flow/flutter_flow_theme.dart';
|
||||
|
@ -43,11 +41,7 @@ class _LocalProfileComponentWidgetState
|
|||
_model.setStateCallback = () => safeSetState(() {});
|
||||
|
||||
() async {
|
||||
_model.cliUUID = StorageUtil().cliUUID;
|
||||
|
||||
if (_model.cliUUID.isEmpty) {
|
||||
await processLocals();
|
||||
}
|
||||
await processLocals();
|
||||
}();
|
||||
}
|
||||
|
||||
|
@ -102,6 +96,7 @@ class _LocalProfileComponentWidgetState
|
|||
final GetLocalsCall callback = PhpGroup.getLocalsCall;
|
||||
|
||||
final cliUUID = StorageUtil().cliUUID;
|
||||
final cliName = StorageUtil().cliName;
|
||||
var response = await callback.call();
|
||||
|
||||
List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
||||
|
@ -109,7 +104,7 @@ class _LocalProfileComponentWidgetState
|
|||
final activeLocals =
|
||||
locals.where((local) => local['CLU_STATUS'] == 'A').toList();
|
||||
|
||||
if (activeLocals.isEmpty || cliUUID.isEmpty) {
|
||||
if (activeLocals.isEmpty || cliUUID.isEmpty || cliName.isEmpty) {
|
||||
await showModalSelectLocal();
|
||||
} else {
|
||||
await processData();
|
||||
|
@ -125,6 +120,8 @@ class _LocalProfileComponentWidgetState
|
|||
backgroundColor: Colors.transparent,
|
||||
enableDrag: false,
|
||||
isDismissible: false,
|
||||
showDragHandle: false,
|
||||
useSafeArea: true,
|
||||
context: context,
|
||||
builder: (context) => Padding(
|
||||
padding: MediaQuery.viewInsetsOf(context),
|
||||
|
@ -137,8 +134,6 @@ class _LocalProfileComponentWidgetState
|
|||
await processData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void onUpdate() {
|
||||
safeSetState(() {
|
||||
_model.getData();
|
||||
|
|
|
@ -102,7 +102,6 @@ class SignInTemplateComponentModel
|
|||
final String userName;
|
||||
final String email;
|
||||
final String passwd;
|
||||
final bool isLogged;
|
||||
|
||||
email = emailAdress!;
|
||||
passwd = password!;
|
||||
|
@ -112,11 +111,10 @@ class SignInTemplateComponentModel
|
|||
if ((email != '') && (passwd != '')) {
|
||||
StorageUtil().email = email;
|
||||
StorageUtil().passwd = passwd;
|
||||
StorageUtil().devUUID = devUUID!;
|
||||
StorageUtil().devUUID = devUUID!;
|
||||
response = await callback.call();
|
||||
|
||||
if (response.jsonBody['error'] == false) {
|
||||
|
||||
userUUID = response.jsonBody['uid'];
|
||||
status = response.jsonBody['user']['status'];
|
||||
userDevUUID = response.jsonBody['user']['dev_id'];
|
||||
|
@ -127,10 +125,9 @@ class SignInTemplateComponentModel
|
|||
StorageUtil().status = status;
|
||||
StorageUtil().userName = userName;
|
||||
|
||||
isLogged = true;
|
||||
await checkLocals(context: context, model: model).then((value) {
|
||||
StorageUtil().haveLocal = value;
|
||||
StorageUtil().isLogged = isLogged;
|
||||
StorageUtil().isLogged = true;
|
||||
toggleApp(context);
|
||||
});
|
||||
} else {
|
||||
|
@ -156,15 +153,7 @@ class SignInTemplateComponentModel
|
|||
if (haveLocal == true) {
|
||||
context.go('/homePage');
|
||||
} else if (haveLocal == false) {
|
||||
context.go(
|
||||
'/receptionPage',
|
||||
extra: <String, dynamic>{
|
||||
kTransitionInfoKey: const TransitionInfo(
|
||||
hasTransition: true,
|
||||
transitionType: PageTransitionType.fade,
|
||||
)
|
||||
},
|
||||
);
|
||||
context.go('/receptionPage');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hub/flutter_flow/nav/nav.dart';
|
||||
|
@ -40,171 +41,179 @@ class AppStateNotifier extends ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter(
|
||||
initialLocation: '/',
|
||||
debugLogDiagnostics: true,
|
||||
refreshListenable: appStateNotifier,
|
||||
// errorBuilder: (context, state) => appStateNotifier.showSplashImage
|
||||
// ? Builder(
|
||||
// builder: (context) => Container(
|
||||
// color: FlutterFlowTheme.of(context).primary,
|
||||
// child: Image.asset(
|
||||
// 'assets/images/logo.svg',
|
||||
// fit: BoxFit.cover,
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// : const PeopleOnThePropertyPageWidget(),
|
||||
routes: [
|
||||
// FFRoute(
|
||||
// name: '_initialize',
|
||||
// path: '/',
|
||||
// builder: (context, _) => appStateNotifier.showSplashImage
|
||||
// ? Builder(
|
||||
// builder: (context) => Container(
|
||||
// color: FlutterFlowTheme.of(context).primary,
|
||||
// child: Image.asset(
|
||||
// 'assets/images/favicon.png',
|
||||
// fit: BoxFit.cover,
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// : const OnBoardingPageWidget(),
|
||||
// ),
|
||||
FFRoute(
|
||||
name: '_initialize',
|
||||
path: '/',
|
||||
builder: (context, _) => StorageUtil().isLogged &&
|
||||
(StorageUtil().userUUID.isNotEmpty &&
|
||||
StorageUtil().userUUID.isNotEmpty)
|
||||
? StorageUtil().haveLocal == true
|
||||
? const HomePageWidget()
|
||||
: const ReceptionPageWidget()
|
||||
: const WelcomePageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'homePage',
|
||||
path: '/homePage',
|
||||
builder: (context, params) {
|
||||
return HomePageWidget(
|
||||
key: UniqueKey(),
|
||||
);
|
||||
},
|
||||
),
|
||||
FFRoute(
|
||||
name: 'receptionPage',
|
||||
path: '/receptionPage',
|
||||
builder: (context, params) => const ReceptionPageWidget()),
|
||||
FFRoute(
|
||||
name: 'messageHistoryPage',
|
||||
path: '/messageHistoryPage',
|
||||
builder: (context, params) => const MessageHistoryPageWidget()),
|
||||
FFRoute(
|
||||
name: 'registerVisitorPage',
|
||||
path: '/registerVisitorPage',
|
||||
builder: (context, params) => const RegisterVisitorPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'scheduleCompleteVisitPage',
|
||||
path: '/scheduleCompleteVisitPage',
|
||||
builder: (context, params) {
|
||||
return const ScheduleCompleteVisitPageWidget();
|
||||
}),
|
||||
FFRoute(
|
||||
name: 'deliverySchedule',
|
||||
path: '/deliverySchedule',
|
||||
builder: (context, params) => const DeliverySchedule(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'provisionalSchedule',
|
||||
path: '/provisionalSchedule',
|
||||
builder: (context, params) => const ProvisionalSchedule(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'fastPassPage',
|
||||
path: '/fastPassPage',
|
||||
builder: (context, params) => /*const*/ FastPassPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'preferencesSettings',
|
||||
path: '/preferencesSettings',
|
||||
builder: (context, params) => PreferencesPageWidget()),
|
||||
FFRoute(
|
||||
name: 'peopleOnThePropertyPage',
|
||||
path: '/peopleOnThePropertyPage',
|
||||
builder: (context, params) => const PeopleOnThePropertyPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'acessHistoryPage',
|
||||
path: '/acessHistoryPage',
|
||||
builder: (context, params) => AccessHistoryScreen(opt: const {
|
||||
'personType': '.*',
|
||||
'accessType': '.*',
|
||||
'search': '.*',
|
||||
})),
|
||||
FFRoute(
|
||||
name: 'liberationHistory',
|
||||
path: '/liberationHistory',
|
||||
builder: (context, params) => const LiberationHistoryWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'signInPage',
|
||||
path: '/signInPage',
|
||||
builder: (context, params) => const SignInPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'signUpPage',
|
||||
path: '/signUpPage',
|
||||
builder: (context, params) => const SignUpPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'welcomePage',
|
||||
path: '/welcomePage',
|
||||
builder: (context, params) => const WelcomePageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'qrCodePage',
|
||||
path: '/qrCodePage',
|
||||
builder: (context, params) => const QrCodePageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'preferencesPage',
|
||||
path: '/preferencesPage',
|
||||
builder: (context, params) => PreferencesPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'packageOrder',
|
||||
path: '/packageOrder',
|
||||
builder: (context, params) => const PackageOrderPage(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'reservation',
|
||||
path: '/reservation',
|
||||
builder: (context, params) => ReservationPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'petsPage',
|
||||
path: '/petsPage',
|
||||
builder: (context, params) {
|
||||
final pet = params.getParam(
|
||||
'pet',
|
||||
ParamType.JSON,
|
||||
);
|
||||
GoRouter createRouter(AppStateNotifier appStateNotifier) {
|
||||
final bool? isLogged = StorageUtil().isLogged;
|
||||
final bool? haveLocal = StorageUtil().haveLocal;
|
||||
final bool haveUserUUID = StorageUtil().userUUID.isNotEmpty;
|
||||
final bool haveDevUUID = StorageUtil().devUUID.isNotEmpty;
|
||||
|
||||
return PetsPageWidget(
|
||||
pet: pet,
|
||||
);
|
||||
},
|
||||
),
|
||||
// FFRoute(
|
||||
// name: 'settingsPage',
|
||||
// path: '/settingsPage',
|
||||
// builder: (context, params) => params.isEmpty
|
||||
// ? const NavBarPage(initialPage: 'settingsPage')
|
||||
// : const SettingsPageWidget(),
|
||||
// )
|
||||
].map((r) => r.toRoute(appStateNotifier)).toList(),
|
||||
);
|
||||
log('() => isLogged: $isLogged');
|
||||
log('() => haveLocal: $haveLocal');
|
||||
|
||||
return GoRouter(
|
||||
initialLocation: '/',
|
||||
debugLogDiagnostics: true,
|
||||
refreshListenable: appStateNotifier,
|
||||
// errorBuilder: (context, state) => appStateNotifier.showSplashImage
|
||||
// ? Builder(
|
||||
// builder: (context) => Container(
|
||||
// color: FlutterFlowTheme.of(context).primary,
|
||||
// child: Image.asset(
|
||||
// 'assets/images/logo.svg',
|
||||
// fit: BoxFit.cover,
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// : const PeopleOnThePropertyPageWidget(),
|
||||
routes: [
|
||||
// FFRoute(
|
||||
// name: '_initialize',
|
||||
// path: '/',
|
||||
// builder: (context, _) => appStateNotifier.showSplashImage
|
||||
// ? Builder(
|
||||
// builder: (context) => Container(
|
||||
// color: FlutterFlowTheme.of(context).primary,
|
||||
// child: Image.asset(
|
||||
// 'assets/images/favicon.png',
|
||||
// fit: BoxFit.cover,
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// : const OnBoardingPageWidget(),
|
||||
// ),
|
||||
FFRoute(
|
||||
name: '_initialize',
|
||||
path: '/',
|
||||
builder: (context, _) => isLogged == true && haveDevUUID && haveUserUUID
|
||||
? haveLocal == true
|
||||
? const HomePageWidget()
|
||||
: const ReceptionPageWidget()
|
||||
: const WelcomePageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'homePage',
|
||||
path: '/homePage',
|
||||
builder: (context, params) {
|
||||
return HomePageWidget(
|
||||
key: UniqueKey(),
|
||||
);
|
||||
},
|
||||
),
|
||||
FFRoute(
|
||||
name: 'receptionPage',
|
||||
path: '/receptionPage',
|
||||
builder: (context, params) => const ReceptionPageWidget()),
|
||||
FFRoute(
|
||||
name: 'messageHistoryPage',
|
||||
path: '/messageHistoryPage',
|
||||
builder: (context, params) => const MessageHistoryPageWidget()),
|
||||
FFRoute(
|
||||
name: 'registerVisitorPage',
|
||||
path: '/registerVisitorPage',
|
||||
builder: (context, params) => const RegisterVisitorPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'scheduleCompleteVisitPage',
|
||||
path: '/scheduleCompleteVisitPage',
|
||||
builder: (context, params) {
|
||||
return const ScheduleCompleteVisitPageWidget();
|
||||
}),
|
||||
FFRoute(
|
||||
name: 'deliverySchedule',
|
||||
path: '/deliverySchedule',
|
||||
builder: (context, params) => const DeliverySchedule(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'provisionalSchedule',
|
||||
path: '/provisionalSchedule',
|
||||
builder: (context, params) => const ProvisionalSchedule(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'fastPassPage',
|
||||
path: '/fastPassPage',
|
||||
builder: (context, params) => /*const*/ FastPassPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'preferencesSettings',
|
||||
path: '/preferencesSettings',
|
||||
builder: (context, params) => PreferencesPageWidget()),
|
||||
FFRoute(
|
||||
name: 'peopleOnThePropertyPage',
|
||||
path: '/peopleOnThePropertyPage',
|
||||
builder: (context, params) => const PeopleOnThePropertyPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'acessHistoryPage',
|
||||
path: '/acessHistoryPage',
|
||||
builder: (context, params) => AccessHistoryScreen(opt: const {
|
||||
'personType': '.*',
|
||||
'accessType': '.*',
|
||||
'search': '.*',
|
||||
})),
|
||||
FFRoute(
|
||||
name: 'liberationHistory',
|
||||
path: '/liberationHistory',
|
||||
builder: (context, params) => const LiberationHistoryWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'signInPage',
|
||||
path: '/signInPage',
|
||||
builder: (context, params) => const SignInPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'signUpPage',
|
||||
path: '/signUpPage',
|
||||
builder: (context, params) => const SignUpPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'welcomePage',
|
||||
path: '/welcomePage',
|
||||
builder: (context, params) => const WelcomePageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'qrCodePage',
|
||||
path: '/qrCodePage',
|
||||
builder: (context, params) => const QrCodePageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'preferencesPage',
|
||||
path: '/preferencesPage',
|
||||
builder: (context, params) => PreferencesPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'packageOrder',
|
||||
path: '/packageOrder',
|
||||
builder: (context, params) => const PackageOrderPage(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'reservation',
|
||||
path: '/reservation',
|
||||
builder: (context, params) => ReservationPageWidget(),
|
||||
),
|
||||
FFRoute(
|
||||
name: 'petsPage',
|
||||
path: '/petsPage',
|
||||
builder: (context, params) {
|
||||
final pet = params.getParam(
|
||||
'pet',
|
||||
ParamType.JSON,
|
||||
);
|
||||
|
||||
return PetsPageWidget(
|
||||
pet: pet,
|
||||
);
|
||||
},
|
||||
),
|
||||
// FFRoute(
|
||||
// name: 'settingsPage',
|
||||
// path: '/settingsPage',
|
||||
// builder: (context, params) => params.isEmpty
|
||||
// ? const NavBarPage(initialPage: 'settingsPage')
|
||||
// : const SettingsPageWidget(),
|
||||
// )
|
||||
].map((r) => r.toRoute(appStateNotifier)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
extension NavParamExtensions on Map<String, String?> {
|
||||
Map<String, String> get withoutNulls => Map.fromEntries(
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:developer';
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:app_tracking_transparency/app_tracking_transparency.dart';
|
||||
import 'package:awesome_notifications/awesome_notifications.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
@ -23,6 +24,7 @@ final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|||
void main() async {
|
||||
await _initializeApp();
|
||||
runApp(const App());
|
||||
FirebaseMessaging.onBackgroundMessage(_backgroundHandlerMessage);
|
||||
}
|
||||
|
||||
Future<void> _initializeApp() async {
|
||||
|
@ -77,7 +79,7 @@ Future<void> _initializeFlutterFlow() async {
|
|||
usePathUrlStrategy();
|
||||
}
|
||||
|
||||
Future<void> _foregroundHandleMessage(RemoteMessage message) async {
|
||||
Future<void> _foregroundHandlerMessage(RemoteMessage message) async {
|
||||
if (message.data['click_action'] == 'enroll_cond') {
|
||||
StorageUtil().haveLocal = true;
|
||||
StorageUtil().context?.go('/homePage');
|
||||
|
@ -90,8 +92,9 @@ Future<void> _foregroundHandleMessage(RemoteMessage message) async {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _backgroundHandleMessage(RemoteMessage message) async {
|
||||
Future<void> _backgroundHandlerMessage(RemoteMessage message) async {
|
||||
if (message.data['click_action'] == 'enroll_cond') {
|
||||
log('backgroundHandlerMessage');
|
||||
StorageUtil().haveLocal = true;
|
||||
StorageUtil().context?.go('/homePage');
|
||||
}
|
||||
|
@ -177,20 +180,41 @@ class _AppState extends State<App> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
|
||||
|
||||
_appStateNotifier = AppStateNotifier.instance;
|
||||
_router = createRouter(_appStateNotifier);
|
||||
Future.delayed(const Duration(milliseconds: 1000),
|
||||
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
||||
FirebaseMessaging.onMessage.listen(_foregroundHandleMessage);
|
||||
|
||||
_setupFirebaseMessaging();
|
||||
}
|
||||
|
||||
void _setupFirebaseMessaging() async {
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
RemoteMessage? initialMessage = await messaging.getInitialMessage();
|
||||
if (initialMessage != null) {
|
||||
log('initialMessage');
|
||||
_backgroundHandlerMessage(initialMessage);
|
||||
}
|
||||
|
||||
FirebaseMessaging.onMessage.listen(_foregroundHandlerMessage);
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||
onMessageReceived(message.data, message.notification!.body,
|
||||
message.data['click_action']);
|
||||
if (message.data['click_action'] == 'enroll_cond') {
|
||||
StorageUtil().haveLocal = true;
|
||||
log('onMessageOpenedApp');
|
||||
} else {
|
||||
onMessageReceived(message.data, message.notification!.body,
|
||||
message.data['click_action']);
|
||||
}
|
||||
});
|
||||
FirebaseMessaging.onBackgroundMessage(_backgroundHandleMessage);
|
||||
FirebaseMessaging.instance.getInitialMessage().then((message) {
|
||||
if (message != null) {
|
||||
_backgroundHandleMessage(message);
|
||||
if (message.data['click_action'] == 'enroll_cond') {
|
||||
StorageUtil().haveLocal = true;
|
||||
log('getInitialMessage');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
import 'dart:developer';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hub/app_state.dart';
|
||||
import 'package:hub/backend/api_requests/api_calls.dart';
|
||||
import 'package:hub/flutter_flow/internationalization.dart';
|
||||
import 'package:hub/shared/helpers/sqlite_storage_helper.dart';
|
||||
import 'package:hub/shared/utils/dialog_util.dart';
|
||||
import 'package:hub/shared/utils/storage_util.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:awesome_notifications/awesome_notifications.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:hub/backend/api_requests/api_calls.dart';
|
||||
|
@ -22,12 +24,27 @@ class ReceptionPageWidget extends StatefulWidget {
|
|||
State<ReceptionPageWidget> createState() => _ReceptionPageWidgetState();
|
||||
}
|
||||
|
||||
class _ReceptionPageWidgetState extends State<ReceptionPageWidget> {
|
||||
class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
|
||||
with WidgetsBindingObserver {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
() async {
|
||||
final lifecycle = await AwesomeNotifications().getAppLifeCycle();
|
||||
log('lifecycle: $lifecycle');
|
||||
}();
|
||||
|
||||
FirebaseMessagingService().updateDeviceToken();
|
||||
() async => await processData();
|
||||
|
||||
processLocals();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance
|
||||
.removeObserver(this); // Remove a classe como observador
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> processLocals() async {
|
||||
|
@ -39,14 +56,17 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget> {
|
|||
if (response.jsonBody['error'] == false) {
|
||||
List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
||||
|
||||
final locales = locals.where((local) => local['CLU_STATUS']).toList();
|
||||
|
||||
StorageUtil().haveLocal = true;
|
||||
StorageUtil().context?.go('/homePage');
|
||||
if (locales.isNotEmpty) await showModalSelectLocal();
|
||||
if (locals.isNotEmpty) {
|
||||
StorageUtil().haveLocal = true;
|
||||
StorageUtil().isLogged = true;
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
dispose();
|
||||
StorageUtil().context?.go('/homePage');
|
||||
await showModalSelectLocal();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// await showModalSelectLocal();
|
||||
} catch (e, s) {
|
||||
log(e.toString(), stackTrace: s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +108,7 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget> {
|
|||
|
||||
return;
|
||||
} catch (e) {
|
||||
log('() => error: $e'); // Add this line to log the error
|
||||
log('() => error: $e');
|
||||
final BuildContext? context = StorageUtil().context;
|
||||
if (context != null) {
|
||||
DialogUtil.warningDefault(context).whenComplete(() => processLocals());
|
||||
|
@ -114,6 +134,15 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget> {
|
|||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
setState(() {
|
||||
processLocals();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
StorageUtil().context = context;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hub/shared/utils/storage_util.dart';
|
||||
|
||||
export 'context_entensions.dart' show ContextExtensions;
|
||||
|
||||
extension ContextExtensions on BuildContext {
|
||||
void setStateStatic(VoidCallback callback) {
|
||||
final element = findAncestorStateOfType<State<StatefulWidget>>();
|
||||
element?.setState(callback);
|
||||
}
|
||||
}
|
|
@ -49,13 +49,15 @@ class SecureStorageHelper extends ChangeNotifier implements Storage {
|
|||
}
|
||||
|
||||
Future<bool?> getBool(String key) async {
|
||||
log('getBool value for key: $key');
|
||||
var value = CacheUtil.instance.get(key);
|
||||
if (value == null) {
|
||||
if (value == null || value == 'null') {
|
||||
value = await _secureStorage.read(key: key);
|
||||
CacheUtil.instance.set(key, value == 'true');
|
||||
CacheUtil.instance.set(key, value);
|
||||
log('getBool $value for key: $key');
|
||||
return value == 'true';
|
||||
}
|
||||
return value == 'true';
|
||||
log('getBool $value for key: $key');
|
||||
return value;
|
||||
}
|
||||
|
||||
Future<BuildContext?> getObject(String key) async {
|
||||
|
@ -71,11 +73,11 @@ class SecureStorageHelper extends ChangeNotifier implements Storage {
|
|||
@override
|
||||
Future<void> set(
|
||||
String key, dynamic value, Function(dynamic) cacheSetter) async {
|
||||
if (value is String) {
|
||||
await setAndCacheString(key, value, cacheSetter);
|
||||
} else if (value is bool) {
|
||||
if (value is String? || value is String) {
|
||||
await setAndCacheString(key, value!, cacheSetter);
|
||||
} else if (value is bool? || value is bool) {
|
||||
await setAndCacheBool(key, value, cacheSetter);
|
||||
} else if (value is BuildContext) {
|
||||
} else if (value is BuildContext || value is BuildContext?) {
|
||||
await setAndCacheObject(key, value.toString(), cacheSetter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,9 +125,9 @@ class StorageUtil {
|
|||
|
||||
Future<void> initSharedPreferences() async {
|
||||
_sharedPreferences.prefs ??= await SharedPreferences.getInstance();
|
||||
_isFirstRun = _sharedPreferences.prefs?.getBool('first_run') ?? true;
|
||||
isFirstRun = _sharedPreferences.prefs?.getBool('first_run') ?? true;
|
||||
if (isFirstRun) {
|
||||
_sharedPreferences.isFirstRun = false;
|
||||
isFirstRun = false;
|
||||
_secureStorage.purge();
|
||||
}
|
||||
}
|
||||
|
@ -261,8 +261,8 @@ class StorageUtil {
|
|||
}
|
||||
|
||||
bool? _isLogged;
|
||||
bool get isLogged => _isLogged ?? false;
|
||||
set isLogged(bool value) {
|
||||
bool? get isLogged => _isLogged;
|
||||
set isLogged(bool? value) {
|
||||
_isLogged = value;
|
||||
_secureStorage.set('ff_isLogged', value, (v) => _isLogged = v);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue