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 'package:hub/shared/utils/storage_util.dart';
|
||||||
|
|
||||||
import '/flutter_flow/flutter_flow_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:google_fonts/google_fonts.dart';
|
||||||
import 'package:hub/backend/api_requests/api_calls.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/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/dialog_util.dart';
|
||||||
import 'package:hub/shared/utils/storage_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/custom_functions.dart' as functions;
|
||||||
import '/flutter_flow/flutter_flow_theme.dart';
|
import '/flutter_flow/flutter_flow_theme.dart';
|
||||||
|
@ -43,11 +41,7 @@ class _LocalProfileComponentWidgetState
|
||||||
_model.setStateCallback = () => safeSetState(() {});
|
_model.setStateCallback = () => safeSetState(() {});
|
||||||
|
|
||||||
() async {
|
() async {
|
||||||
_model.cliUUID = StorageUtil().cliUUID;
|
await processLocals();
|
||||||
|
|
||||||
if (_model.cliUUID.isEmpty) {
|
|
||||||
await processLocals();
|
|
||||||
}
|
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +96,7 @@ class _LocalProfileComponentWidgetState
|
||||||
final GetLocalsCall callback = PhpGroup.getLocalsCall;
|
final GetLocalsCall callback = PhpGroup.getLocalsCall;
|
||||||
|
|
||||||
final cliUUID = StorageUtil().cliUUID;
|
final cliUUID = StorageUtil().cliUUID;
|
||||||
|
final cliName = StorageUtil().cliName;
|
||||||
var response = await callback.call();
|
var response = await callback.call();
|
||||||
|
|
||||||
List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
||||||
|
@ -109,7 +104,7 @@ class _LocalProfileComponentWidgetState
|
||||||
final activeLocals =
|
final activeLocals =
|
||||||
locals.where((local) => local['CLU_STATUS'] == 'A').toList();
|
locals.where((local) => local['CLU_STATUS'] == 'A').toList();
|
||||||
|
|
||||||
if (activeLocals.isEmpty || cliUUID.isEmpty) {
|
if (activeLocals.isEmpty || cliUUID.isEmpty || cliName.isEmpty) {
|
||||||
await showModalSelectLocal();
|
await showModalSelectLocal();
|
||||||
} else {
|
} else {
|
||||||
await processData();
|
await processData();
|
||||||
|
@ -125,6 +120,8 @@ class _LocalProfileComponentWidgetState
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
enableDrag: false,
|
enableDrag: false,
|
||||||
isDismissible: false,
|
isDismissible: false,
|
||||||
|
showDragHandle: false,
|
||||||
|
useSafeArea: true,
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => Padding(
|
builder: (context) => Padding(
|
||||||
padding: MediaQuery.viewInsetsOf(context),
|
padding: MediaQuery.viewInsetsOf(context),
|
||||||
|
@ -137,8 +134,6 @@ class _LocalProfileComponentWidgetState
|
||||||
await processData();
|
await processData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void onUpdate() {
|
void onUpdate() {
|
||||||
safeSetState(() {
|
safeSetState(() {
|
||||||
_model.getData();
|
_model.getData();
|
||||||
|
|
|
@ -102,7 +102,6 @@ class SignInTemplateComponentModel
|
||||||
final String userName;
|
final String userName;
|
||||||
final String email;
|
final String email;
|
||||||
final String passwd;
|
final String passwd;
|
||||||
final bool isLogged;
|
|
||||||
|
|
||||||
email = emailAdress!;
|
email = emailAdress!;
|
||||||
passwd = password!;
|
passwd = password!;
|
||||||
|
@ -112,11 +111,10 @@ class SignInTemplateComponentModel
|
||||||
if ((email != '') && (passwd != '')) {
|
if ((email != '') && (passwd != '')) {
|
||||||
StorageUtil().email = email;
|
StorageUtil().email = email;
|
||||||
StorageUtil().passwd = passwd;
|
StorageUtil().passwd = passwd;
|
||||||
StorageUtil().devUUID = devUUID!;
|
StorageUtil().devUUID = devUUID!;
|
||||||
response = await callback.call();
|
response = await callback.call();
|
||||||
|
|
||||||
if (response.jsonBody['error'] == false) {
|
if (response.jsonBody['error'] == false) {
|
||||||
|
|
||||||
userUUID = response.jsonBody['uid'];
|
userUUID = response.jsonBody['uid'];
|
||||||
status = response.jsonBody['user']['status'];
|
status = response.jsonBody['user']['status'];
|
||||||
userDevUUID = response.jsonBody['user']['dev_id'];
|
userDevUUID = response.jsonBody['user']['dev_id'];
|
||||||
|
@ -127,10 +125,9 @@ class SignInTemplateComponentModel
|
||||||
StorageUtil().status = status;
|
StorageUtil().status = status;
|
||||||
StorageUtil().userName = userName;
|
StorageUtil().userName = userName;
|
||||||
|
|
||||||
isLogged = true;
|
|
||||||
await checkLocals(context: context, model: model).then((value) {
|
await checkLocals(context: context, model: model).then((value) {
|
||||||
StorageUtil().haveLocal = value;
|
StorageUtil().haveLocal = value;
|
||||||
StorageUtil().isLogged = isLogged;
|
StorageUtil().isLogged = true;
|
||||||
toggleApp(context);
|
toggleApp(context);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -156,15 +153,7 @@ class SignInTemplateComponentModel
|
||||||
if (haveLocal == true) {
|
if (haveLocal == true) {
|
||||||
context.go('/homePage');
|
context.go('/homePage');
|
||||||
} else if (haveLocal == false) {
|
} else if (haveLocal == false) {
|
||||||
context.go(
|
context.go('/receptionPage');
|
||||||
'/receptionPage',
|
|
||||||
extra: <String, dynamic>{
|
|
||||||
kTransitionInfoKey: const TransitionInfo(
|
|
||||||
hasTransition: true,
|
|
||||||
transitionType: PageTransitionType.fade,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hub/flutter_flow/nav/nav.dart';
|
import 'package:hub/flutter_flow/nav/nav.dart';
|
||||||
|
@ -40,171 +41,179 @@ class AppStateNotifier extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter(
|
GoRouter createRouter(AppStateNotifier appStateNotifier) {
|
||||||
initialLocation: '/',
|
final bool? isLogged = StorageUtil().isLogged;
|
||||||
debugLogDiagnostics: true,
|
final bool? haveLocal = StorageUtil().haveLocal;
|
||||||
refreshListenable: appStateNotifier,
|
final bool haveUserUUID = StorageUtil().userUUID.isNotEmpty;
|
||||||
// errorBuilder: (context, state) => appStateNotifier.showSplashImage
|
final bool haveDevUUID = StorageUtil().devUUID.isNotEmpty;
|
||||||
// ? 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,
|
|
||||||
);
|
|
||||||
|
|
||||||
return PetsPageWidget(
|
log('() => isLogged: $isLogged');
|
||||||
pet: pet,
|
log('() => haveLocal: $haveLocal');
|
||||||
);
|
|
||||||
},
|
return GoRouter(
|
||||||
),
|
initialLocation: '/',
|
||||||
// FFRoute(
|
debugLogDiagnostics: true,
|
||||||
// name: 'settingsPage',
|
refreshListenable: appStateNotifier,
|
||||||
// path: '/settingsPage',
|
// errorBuilder: (context, state) => appStateNotifier.showSplashImage
|
||||||
// builder: (context, params) => params.isEmpty
|
// ? Builder(
|
||||||
// ? const NavBarPage(initialPage: 'settingsPage')
|
// builder: (context) => Container(
|
||||||
// : const SettingsPageWidget(),
|
// color: FlutterFlowTheme.of(context).primary,
|
||||||
// )
|
// child: Image.asset(
|
||||||
].map((r) => r.toRoute(appStateNotifier)).toList(),
|
// '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?> {
|
extension NavParamExtensions on Map<String, String?> {
|
||||||
Map<String, String> get withoutNulls => Map.fromEntries(
|
Map<String, String> get withoutNulls => Map.fromEntries(
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:developer';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:app_tracking_transparency/app_tracking_transparency.dart';
|
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_core/firebase_core.dart';
|
||||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
|
@ -23,6 +24,7 @@ final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
void main() async {
|
void main() async {
|
||||||
await _initializeApp();
|
await _initializeApp();
|
||||||
runApp(const App());
|
runApp(const App());
|
||||||
|
FirebaseMessaging.onBackgroundMessage(_backgroundHandlerMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _initializeApp() async {
|
Future<void> _initializeApp() async {
|
||||||
|
@ -77,7 +79,7 @@ Future<void> _initializeFlutterFlow() async {
|
||||||
usePathUrlStrategy();
|
usePathUrlStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _foregroundHandleMessage(RemoteMessage message) async {
|
Future<void> _foregroundHandlerMessage(RemoteMessage message) async {
|
||||||
if (message.data['click_action'] == 'enroll_cond') {
|
if (message.data['click_action'] == 'enroll_cond') {
|
||||||
StorageUtil().haveLocal = true;
|
StorageUtil().haveLocal = true;
|
||||||
StorageUtil().context?.go('/homePage');
|
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') {
|
if (message.data['click_action'] == 'enroll_cond') {
|
||||||
|
log('backgroundHandlerMessage');
|
||||||
StorageUtil().haveLocal = true;
|
StorageUtil().haveLocal = true;
|
||||||
StorageUtil().context?.go('/homePage');
|
StorageUtil().context?.go('/homePage');
|
||||||
}
|
}
|
||||||
|
@ -177,20 +180,41 @@ class _AppState extends State<App> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
|
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
|
||||||
|
|
||||||
_appStateNotifier = AppStateNotifier.instance;
|
_appStateNotifier = AppStateNotifier.instance;
|
||||||
_router = createRouter(_appStateNotifier);
|
_router = createRouter(_appStateNotifier);
|
||||||
Future.delayed(const Duration(milliseconds: 1000),
|
Future.delayed(const Duration(milliseconds: 1000),
|
||||||
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
() => 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) {
|
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||||
onMessageReceived(message.data, message.notification!.body,
|
if (message.data['click_action'] == 'enroll_cond') {
|
||||||
message.data['click_action']);
|
StorageUtil().haveLocal = true;
|
||||||
|
log('onMessageOpenedApp');
|
||||||
|
} else {
|
||||||
|
onMessageReceived(message.data, message.notification!.body,
|
||||||
|
message.data['click_action']);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
FirebaseMessaging.onBackgroundMessage(_backgroundHandleMessage);
|
|
||||||
FirebaseMessaging.instance.getInitialMessage().then((message) {
|
FirebaseMessaging.instance.getInitialMessage().then((message) {
|
||||||
if (message != null) {
|
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: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/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:hub/shared/utils/storage_util.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:awesome_notifications/awesome_notifications.dart';
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:hub/backend/api_requests/api_calls.dart';
|
import 'package:hub/backend/api_requests/api_calls.dart';
|
||||||
|
@ -22,12 +24,27 @@ class ReceptionPageWidget extends StatefulWidget {
|
||||||
State<ReceptionPageWidget> createState() => _ReceptionPageWidgetState();
|
State<ReceptionPageWidget> createState() => _ReceptionPageWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ReceptionPageWidgetState extends State<ReceptionPageWidget> {
|
class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
|
||||||
|
with WidgetsBindingObserver {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
() async {
|
||||||
|
final lifecycle = await AwesomeNotifications().getAppLifeCycle();
|
||||||
|
log('lifecycle: $lifecycle');
|
||||||
|
}();
|
||||||
|
|
||||||
FirebaseMessagingService().updateDeviceToken();
|
FirebaseMessagingService().updateDeviceToken();
|
||||||
() async => await processData();
|
|
||||||
|
processLocals();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
WidgetsBinding.instance
|
||||||
|
.removeObserver(this); // Remove a classe como observador
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> processLocals() async {
|
Future<void> processLocals() async {
|
||||||
|
@ -39,14 +56,17 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget> {
|
||||||
if (response.jsonBody['error'] == false) {
|
if (response.jsonBody['error'] == false) {
|
||||||
List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
||||||
|
|
||||||
final locales = locals.where((local) => local['CLU_STATUS']).toList();
|
if (locals.isNotEmpty) {
|
||||||
|
StorageUtil().haveLocal = true;
|
||||||
StorageUtil().haveLocal = true;
|
StorageUtil().isLogged = true;
|
||||||
StorageUtil().context?.go('/homePage');
|
await WidgetsBinding.instance.endOfFrame;
|
||||||
if (locales.isNotEmpty) await showModalSelectLocal();
|
dispose();
|
||||||
|
StorageUtil().context?.go('/homePage');
|
||||||
|
await showModalSelectLocal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e, s) {
|
||||||
// await showModalSelectLocal();
|
log(e.toString(), stackTrace: s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +108,7 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget> {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('() => error: $e'); // Add this line to log the error
|
log('() => error: $e');
|
||||||
final BuildContext? context = StorageUtil().context;
|
final BuildContext? context = StorageUtil().context;
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
DialogUtil.warningDefault(context).whenComplete(() => processLocals());
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
StorageUtil().context = 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 {
|
Future<bool?> getBool(String key) async {
|
||||||
log('getBool value for key: $key');
|
|
||||||
var value = CacheUtil.instance.get(key);
|
var value = CacheUtil.instance.get(key);
|
||||||
if (value == null) {
|
if (value == null || value == 'null') {
|
||||||
value = await _secureStorage.read(key: key);
|
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 {
|
Future<BuildContext?> getObject(String key) async {
|
||||||
|
@ -71,11 +73,11 @@ class SecureStorageHelper extends ChangeNotifier implements Storage {
|
||||||
@override
|
@override
|
||||||
Future<void> set(
|
Future<void> set(
|
||||||
String key, dynamic value, Function(dynamic) cacheSetter) async {
|
String key, dynamic value, Function(dynamic) cacheSetter) async {
|
||||||
if (value is String) {
|
if (value is String? || value is String) {
|
||||||
await setAndCacheString(key, value, cacheSetter);
|
await setAndCacheString(key, value!, cacheSetter);
|
||||||
} else if (value is bool) {
|
} else if (value is bool? || value is bool) {
|
||||||
await setAndCacheBool(key, value, cacheSetter);
|
await setAndCacheBool(key, value, cacheSetter);
|
||||||
} else if (value is BuildContext) {
|
} else if (value is BuildContext || value is BuildContext?) {
|
||||||
await setAndCacheObject(key, value.toString(), cacheSetter);
|
await setAndCacheObject(key, value.toString(), cacheSetter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,9 +125,9 @@ class StorageUtil {
|
||||||
|
|
||||||
Future<void> initSharedPreferences() async {
|
Future<void> initSharedPreferences() async {
|
||||||
_sharedPreferences.prefs ??= await SharedPreferences.getInstance();
|
_sharedPreferences.prefs ??= await SharedPreferences.getInstance();
|
||||||
_isFirstRun = _sharedPreferences.prefs?.getBool('first_run') ?? true;
|
isFirstRun = _sharedPreferences.prefs?.getBool('first_run') ?? true;
|
||||||
if (isFirstRun) {
|
if (isFirstRun) {
|
||||||
_sharedPreferences.isFirstRun = false;
|
isFirstRun = false;
|
||||||
_secureStorage.purge();
|
_secureStorage.purge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,8 +261,8 @@ class StorageUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool? _isLogged;
|
bool? _isLogged;
|
||||||
bool get isLogged => _isLogged ?? false;
|
bool? get isLogged => _isLogged;
|
||||||
set isLogged(bool value) {
|
set isLogged(bool? value) {
|
||||||
_isLogged = value;
|
_isLogged = value;
|
||||||
_secureStorage.set('ff_isLogged', value, (v) => _isLogged = v);
|
_secureStorage.set('ff_isLogged', value, (v) => _isLogged = v);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue