diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index cecc978c..8b254a27 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -21,6 +21,18 @@ class HomePageWidget extends StatefulWidget { class _HomePageWidgetState extends State { final scaffoldKey = GlobalKey(); + @override + void initState() { + super.initState(); + _initializePage(); + } + + Future _initializePage() async { + await LocalsRepositoryImpl().processLocals(context).whenComplete(() async { + context.read().add(LocalProfileEvent()); + }); + } + @override Widget build(BuildContext context) { return BlocProvider( diff --git a/lib/main.dart b/lib/main.dart index c747270d..1053f9bd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,6 +15,7 @@ import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/deeplink/deep_link_service.dart'; import 'package:responsive_framework/responsive_framework.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'backend/notifications/firebase_messaging_service.dart'; import 'initialization.dart'; @@ -23,7 +24,7 @@ final GlobalKey navigatorKey = GlobalKey(); void main() async { await initializeApp(); - runApp(const App()); + runApp(const ProviderScope(child: App())); FirebaseMessaging.onBackgroundMessage(_backgroundHandlerMessage); } diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index 9cba14c4..f5523433 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -17,6 +17,8 @@ class LocalProfileComponentWidget extends StatefulWidget { } class _LocalProfileComponentWidgetState extends State { + + @override Widget build(BuildContext context) { return BlocProvider( diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart index c85dd950..fab4e6f0 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart @@ -11,6 +11,7 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; +import 'package:hub/shared/services/authentication/authentication_service.dart'; class MenuViewEvent {} @@ -95,6 +96,11 @@ class MenuViewBloc extends Bloc { try { switch (display) { case 'VISIVEL': + if(opt.value == 'FRE-HUB-LOGOUT') + await addMenuEntry(entries, opt.icon, opt.name, () async { + await AuthenticationService.signOut(navigatorKey.currentContext!); + }); + else await addMenuEntry(entries, opt.icon, opt.name, () async { await nav(opt.route); }); diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart index 373b9b4a..5b86aae6 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart @@ -52,6 +52,10 @@ enum DrawerMenuEntries implements MenuEntry { return 'FRE-HUB-QRCODE'; case DrawerMenuEntries.peopleOnTheProperty: return 'FRE-HUB-PEOPLE'; + case DrawerMenuEntries.settings: + return 'FRE-HUB-SETTINGS'; + case DrawerMenuEntries.logout: + return 'FRE-HUB-LOGOUT'; default: return ''; } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart index 8ab3a975..3915c3d9 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart @@ -51,6 +51,8 @@ enum HomeMenuEntries implements MenuEntry { return 'FRE-HUB-QRCODE'; case HomeMenuEntries.peopleOnTheProperty: return 'FRE-HUB-PEOPLE'; + case HomeMenuEntries.settings: + return 'FRE-HUB-SETTINGS'; default: return ''; } diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 6411e35c..18ca868c 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -38,7 +38,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { @override Future setupLicense(Database database, bool isNewVersion) async { - final License license = License.getLicense(isNewVersion); + final License license = await License.getLicense(isNewVersion); final List inactiveModuleKey = license.modules .where((module) => module.display == ModuleStatus.inactive.key) @@ -113,7 +113,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } static bool licenseContainsKey(final String key) { - return License.mods.contains(key); + return LicenseKeys.values.map((e) => e.value).contains(key); } static Future _saveModule(final dynamic body) async { diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 50f71990..49306773 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -7,6 +7,76 @@ import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'module.dart'; +enum LicenseKeys { + messages, + liberations, + reservations, + access, + openedVisits, + vehicles, + residents, + pets, + orders, + completeSchedule, + providerSchedule, + deliverySchedule, + property, + fastPass, + visitors, + qrCode, + people, + petsHistory, + settings, + logout, +} + +extension LicenseKeysExtension on LicenseKeys { + String get value { + switch (this) { + case LicenseKeys.messages: + return 'FRE-HUB-MESSAGES'; + case LicenseKeys.liberations: + return 'FRE-HUB-LIBERATIONS'; + case LicenseKeys.reservations: + return 'FRE-HUB-RESERVATIONS'; + case LicenseKeys.access: + return 'FRE-HUB-ACCESS'; + case LicenseKeys.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case LicenseKeys.vehicles: + return 'FRE-HUB-VEHICLES'; + case LicenseKeys.residents: + return 'FRE-HUB-RESIDENTS'; + case LicenseKeys.pets: + return 'FRE-HUB-PETS'; + case LicenseKeys.orders: + return 'FRE-HUB-ORDERS'; + case LicenseKeys.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case LicenseKeys.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case LicenseKeys.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case LicenseKeys.property: + return 'FRE-HUB-PROPERTY'; + case LicenseKeys.fastPass: + return 'FRE-HUB-FASTPASS'; + case LicenseKeys.visitors: + return 'FRE-HUB-VISITORS'; + case LicenseKeys.qrCode: + return 'FRE-HUB-QRCODE'; + case LicenseKeys.people: + return 'FRE-HUB-PEOPLE'; + case LicenseKeys.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + case LicenseKeys.settings: + return 'FRE-HUB-SETTINGS'; + case LicenseKeys.logout: + return 'FRE-HUB-LOGOUT'; + } + } +} + class License { final List modules; @@ -14,161 +84,208 @@ class License { this.modules, ); - static List mods = [ - 'FRE-HUB-MESSAGES', - 'FRE-HUB-LIBERATIONS', - 'FRE-HUB-RESERVATIONS', - 'FRE-HUB-ACCESS', - 'FRE-HUB-OPENED-VISITS', - 'FRE-HUB-VEHICLES', - 'FRE-HUB-RESIDENTS', - 'FRE-HUB-PETS', - 'FRE-HUB-ORDERS', - 'FRE-HUB-COMPLETE-SCHEDULE', - 'FRE-HUB-AGE-PROV-PRESTADOR', - 'FRE-HUB-AGE-PROV-DELIVERY', - 'FRE-HUB-PROPERTY', - 'FRE-HUB-FASTPASS', - 'FRE-HUB-VISITORS', - 'FRE-HUB-QRCODE', - 'FRE-HUB-PEOPLE', - 'FRE-HUB-PETS-HISTORY' - ]; + // static List mods = [ + // 'FRE-HUB-MESSAGES', + // 'FRE-HUB-LIBERATIONS', + // 'FRE-HUB-RESERVATIONS', + // 'FRE-HUB-ACCESS', + // 'FRE-HUB-OPENED-VISITS', + // 'FRE-HUB-VEHICLES', + // 'FRE-HUB-RESIDENTS', + // 'FRE-HUB-PETS', + // 'FRE-HUB-ORDERS', + // 'FRE-HUB-COMPLETE-SCHEDULE', + // 'FRE-HUB-AGE-PROV-PRESTADOR', + // 'FRE-HUB-AGE-PROV-DELIVERY', + // 'FRE-HUB-PROPERTY', + // 'FRE-HUB-FASTPASS', + // 'FRE-HUB-VISITORS', + // 'FRE-HUB-QRCODE', + // 'FRE-HUB-PEOPLE', + // 'FRE-HUB-PETS-HISTORY' + // 'FRE-HUB-SETTINGS', + // 'FRE-HUB-LOGOUT', + // ]; - void processOldVersion() async { - final bool whatsapp = await StorageHelper().g(KeychainStorageKey.whatsapp as String).then((v) => v.toBoolean()); - final bool provisional = await StorageHelper().g(KeychainStorageKey.provisional as String).then((v) => v.toBoolean()); - final bool pets = await StorageHelper().g(KeychainStorageKey.pets as String).then((v) => v.toBoolean()); + static Future _proceessOldVersion(LicenseKeys key) async { + switch(key) { + case LicenseKeys.fastPass: + return await _precessWpp(); + case LicenseKeys.providerSchedule: + return await _processProvisional(); + case LicenseKeys.deliverySchedule: + return await _processProvisional(); + case LicenseKeys.pets: + return await _processPets(); + case LicenseKeys.petsHistory: + return await _processPets(); + default: + return ModuleStatus.active.key; + } } - factory License.getLicense(bool isNewVersion) { + static Future _precessWpp() async { + final bool whatsapp = await StorageHelper().g(KeychainStorageKey.whatsapp.value).then((v) => v.toBoolean()); + if (whatsapp) return ModuleStatus.active.key; + else return ModuleStatus.inactive.key; + } + static Future _processProvisional() async { + final bool provisional = await StorageHelper().g(KeychainStorageKey.provisional.value).then((v) => v.toBoolean()); + if (provisional) return ModuleStatus.active.key; + else return ModuleStatus.inactive.key; + } + + static Future _processPets() async { + final bool pets = await StorageHelper().g(KeychainStorageKey.pets.value).then((v) => v.toBoolean()); + if (pets) return ModuleStatus.active.key; + else return ModuleStatus.inactive.key; + } + + + + static Future getLicense(bool isNewVersion) async { return License([ Module( - key: 'FRE-HUB-MESSAGES', + key: LicenseKeys.messages.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-LIBERATIONS', + key: LicenseKeys.liberations.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-RESERVATIONS', + key: LicenseKeys.reservations.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-ACCESS', + key: LicenseKeys.access.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-OPENED-VISITS', + key: LicenseKeys.openedVisits.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-VEHICLES', + key: LicenseKeys.vehicles.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-RESIDENTS', + key: LicenseKeys.residents.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-PETS', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + key: LicenseKeys.pets.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.pets), expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-ORDERS', + key: LicenseKeys.orders.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-COMPLETE-SCHEDULE', + key: LicenseKeys.completeSchedule.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-AGE-PROV-PRESTADOR', + key: LicenseKeys.providerSchedule.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.providerSchedule), + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: LicenseKeys.deliverySchedule.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.deliverySchedule), + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: LicenseKeys.fastPass.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.fastPass), + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: LicenseKeys.qrCode.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-AGE-PROV-DELIVERY', + key: LicenseKeys.visitors.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-FASTPASS', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, - expirationDate: '', - startDate: '', - quantity: 0, - ), - Module( - key: 'FRE-HUB-QRCODE', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, - expirationDate: '', - startDate: '', - quantity: 0, - ), - Module( - key: 'FRE-HUB-VISITORS', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, - expirationDate: '', - startDate: '', - quantity: 0, - ), - Module( - key: 'FRE-HUB-PROPERTY', + key: LicenseKeys.property.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-PEOPLE', + key: LicenseKeys.people.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-PETS-HISTORY', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + key: LicenseKeys.petsHistory.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.petsHistory), expirationDate: '', startDate: '', quantity: 0, ), + Module( + key: LicenseKeys.settings.value, + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: LicenseKeys.logout.value, + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + ]); } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 6953fe7f..48463b0e 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -194,21 +194,13 @@ class AuthenticationService { String content; try { await PhpGroup.deleteAccount.call().then((value) async { - final Map extra = { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }; if (value.jsonBody['error'] == false) { content = FFLocalizations.of(context).getVariableText( enText: 'Account deleted successfully', ptText: 'Conta deletada com sucesso', ); - await StorageHelper().c(Storage.secureStorage); - context.pop(); - context.go('/welcomePage', extra: extra); + return await signOut(context); + } }).catchError((err) { context.pop(); @@ -216,7 +208,8 @@ class AuthenticationService { enText: 'Error deleting account', ptText: 'Erro ao deletar conta', ); - SnackBarUtil.showSnackBar(context, content); + SnackBarUtil.showSnackBar(context, content); + return; }); } catch (err) { context.pop(); @@ -225,6 +218,7 @@ class AuthenticationService { ptText: 'Erro ao deletar conta', ); SnackBarUtil.showSnackBar(context, content, isError: true); + return; } } } diff --git a/pubspec.lock b/pubspec.lock index 554f2649..b40d3b0b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -640,6 +640,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.23" + flutter_riverpod: + dependency: "direct main" + description: + name: flutter_riverpod + sha256: "9532ee6db4a943a1ed8383072a2e3eeda041db5657cdf6d2acecf3c21ecbe7e1" + url: "https://pub.dev" + source: hosted + version: "2.6.1" flutter_secure_storage: dependency: "direct main" description: @@ -1378,6 +1386,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" + riverpod: + dependency: transitive + description: + name: riverpod + sha256: "59062512288d3056b2321804332a13ffdd1bf16df70dcc8e506e411280a72959" + url: "https://pub.dev" + source: hosted + version: "2.6.1" rxdart: dependency: "direct main" description: @@ -1559,6 +1575,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.1" + state_notifier: + dependency: transitive + description: + name: state_notifier + sha256: b8677376aa54f2d7c58280d5a007f9e8774f1968d1fb1c096adcb4792fba29bb + url: "https://pub.dev" + source: hosted + version: "1.0.0" stream_channel: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index becd74ab..ffdff88d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -93,7 +93,7 @@ dependencies: fluttertoast: ^8.2.8 cupertino_icons: ^1.0.0 flutter_bloc: ^8.1.6 - # flutter_riverpod: ^2.5.1 + flutter_riverpod: ^2.5.1 qr_flutter: ^4.1.0 permission_handler: ^11.3.1 firebase_crashlytics: ^4.0.1