diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index f63c044e..d1c2ad24 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -29,18 +29,23 @@ class _HomePageWidgetState extends State { BlocProvider( create: (context) => HomeBloc()..add(HomeEvent()), ), - BlocProvider( + BlocProvider( create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), ), ], - child: Scaffold( - key: scaffoldKey, - backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - drawerEnableOpenDragGesture: true, - drawerDragStartBehavior: DragStartBehavior.start, - drawer: CustomDrawer(), - appBar: buildAppBar(context), - body: buildPage(context), + child: Builder( + builder: (context) { + context.read().updateProfile(context); + return Scaffold( + key: scaffoldKey, + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, + drawerEnableOpenDragGesture: true, + drawerDragStartBehavior: DragStartBehavior.start, + drawer: CustomDrawer(), + appBar: buildAppBar(context), + body: buildPage(context), + ); + }, ), ); } diff --git a/lib/features/property/presentation/pages/about_property_screen.dart b/lib/features/property/presentation/pages/about_property_screen.dart index dea748d2..7560cc25 100644 --- a/lib/features/property/presentation/pages/about_property_screen.dart +++ b/lib/features/property/presentation/pages/about_property_screen.dart @@ -78,7 +78,7 @@ class _AboutPropertyPageState extends State with SingleTicker child: Container( color: FlutterFlowTheme.of(context).primaryBackground, child: Menufactory( - entry: MenuEntry.getEntriesByType(MenuEntryType.Drawer), + entry: MenuEntry.getEntriesByType(MenuEntryType.Property), item: EnumMenuItem.button, view: MenuView.list_grid, ), diff --git a/lib/main.dart b/lib/main.dart index 409d2a04..324221f9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,9 +16,11 @@ 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 'package:hub/shared/extensions/string_extensions.dart'; import 'backend/notifications/firebase_messaging_service.dart'; import 'initialization.dart'; +import 'shared/components/molecules/modules/index.dart'; final GlobalKey navigatorKey = GlobalKey(); diff --git a/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart b/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart index fb3b4696..cdc96579 100644 --- a/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart +++ b/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart @@ -34,7 +34,7 @@ class _ResidentsOnThePropertyState extends State with Ti void initState() { super.initState(); model = createModel(context, () => ResidentsOnThePropertyModel(onRefresh: () => safeSetState(() {}))); - _future = _fetchVisits(); + _future = _fetch(); _scrollController = ScrollController() ..addListener(() { @@ -160,7 +160,7 @@ class _ResidentsOnThePropertyState extends State with Ti ); } - Future _fetchVisits() async { + Future _fetch() async { try { setState(() => _loading = true); @@ -202,7 +202,7 @@ class _ResidentsOnThePropertyState extends State with Ti if (_hasData == true) { _pageNumber++; - _future = _fetchVisits(); + _future = _fetch(); } } diff --git a/lib/shared/components/molecules/drawer/drawer_widget.dart b/lib/shared/components/molecules/drawer/drawer_widget.dart index 253540d1..a022f8c8 100644 --- a/lib/shared/components/molecules/drawer/drawer_widget.dart +++ b/lib/shared/components/molecules/drawer/drawer_widget.dart @@ -190,7 +190,7 @@ class CustomDrawer extends StatelessWidget { Widget _buildDrawerBody(BuildContext context) { return Menufactory( - entry: MenuEntry.getEntriesByType(MenuEntryType.Property), + entry: MenuEntry.getEntriesByType(MenuEntryType.Drawer), item: EnumMenuItem.tile, view: MenuView.list, ); diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index c2321d4d..42b16d9c 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -162,12 +162,12 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { if (isError == true) { final GetLocalsCall callback = PhpGroup.getLocalsCall; response = await callback.call(); - final String errorMsg = response.jsonBody['error_msg'] ?? 'Unknown error'; + final String errorMsg = response.jsonBody['error_msg'] ?? 'Local indisponível'; await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; } else { final bool isNewVersion = await LocalUtil.updateStorageUtil(response.jsonBody); - return await LicenseRepositoryImpl().updateLicense(isNewVersion); + return await LicenseRepositoryImpl().updateLicense(); } } catch (e, s) { log('() => error processData: $e', stackTrace: s); diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index b91360f2..d79f115c 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -1,11 +1,14 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; -class LocalProfileEvent {} +class LocalProfileEvent { + +} class LocalProfileState { final String cliName; @@ -14,6 +17,7 @@ class LocalProfileState { LocalProfileState({this.cliName = '', this.cliUUID = ''}); LocalProfileState copyWith({String? cliName, String? cliUUID}) { + return LocalProfileState( cliName: cliName ?? this.cliName, cliUUID: cliUUID ?? this.cliUUID, @@ -23,11 +27,18 @@ class LocalProfileState { class LocalProfileBloc extends Bloc { LocalProfileBloc() : super(LocalProfileState()) { - on((event, emit) async { - final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; - final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; - emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); - }); + on(_onLocalProfileEvent); + } + + Future _onLocalProfileEvent(LocalProfileEvent event, Emitter emit) async { + final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); + } + + void updateProfile(BuildContext context) { + add(LocalProfileEvent()); + LocalsRepositoryImpl().update(context); } } diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index ebccda7b..f88d1c55 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -9,10 +9,12 @@ import 'package:hub/shared/extensions/dialog_extensions.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; import 'package:hub/shared/utils/path_util.dart'; +import '../../../modules/domain/entities/index.dart'; + abstract class MenuLocalDataSource { Future addMenuEntry(EnumMenuItem item, List entries, IconData icon, String text, Function() action); Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries); - Future processDisplay(EnumMenuItem item, String display, MenuEntry opt, List entries); + Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries); Future processStartDate(String startDate, MenuEntry opt); Future processExpirationDate(String expirationDate, MenuEntry opt); } @@ -48,9 +50,9 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { } @override - Future processDisplay(EnumMenuItem item, String display, MenuEntry opt, List entries) async { + Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries) async { try { - switch (display) { + switch (display.value) { case 'VISIVEL': await addMenuEntry(item, entries, opt.icon, opt.name, () async { await PathUtil.nav(opt.route); diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index fdf1d434..7f692ccb 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -23,7 +23,7 @@ class MenuRepositoryImpl implements MenuRepository { final licenseValue = await LicenseRepositoryImpl().getLicense(opt.value); if (licenseValue != null) { final licenseMap = await stringToMap(licenseValue); - final display = licenseMap['display'] ?? 'INVISIVEL'; + final display = EnumDisplay.fromString(licenseMap['display']); final startDate = licenseMap['startDate'] ?? ''; final expirationDate = licenseMap['expirationDate'] ?? ''; final isStarted = await menuDataSource.processStartDate(startDate, opt); diff --git a/lib/shared/components/molecules/menu/presentation/blocs/index.dart b/lib/shared/components/molecules/menu/presentation/blocs/index.dart index 952e1026..3f1ac83b 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/index.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/index.dart @@ -1 +1,3 @@ +export 'menu_bloc.dart'; +export 'menu_item_bloc.dart'; export 'menu_view_bloc.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart index 59a48fbe..6866013a 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart @@ -1,9 +1,55 @@ + +import 'dart:async'; + import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; + +import 'package:flutter_bloc/flutter_bloc.dart'; + + class MenuEvent {} -class MenuState {} +class MenuState { + final List menuEntries; + final bool isGrid; + + MenuState({this.menuEntries = const [], this.isGrid = false}); + + MenuState copyWith({List? menuEntries, bool? isGrid}) { + return MenuState( + menuEntries: menuEntries ?? this.menuEntries, + isGrid: isGrid ?? this.isGrid, + ); + } +} class MenuBloc extends Bloc { - MenuBloc() : super(MenuState()); + final MenuView style; + final EnumMenuItem item; + final List menuOptions; + late StreamSubscription _completer; + + + MenuBloc({required this.style, required this.item, required this.menuOptions}) : super(MenuState()) { + on((event, emit) async { + await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); + final entries = await MenuRepositoryImpl().generateMenuEntries(menuOptions, item); + emit(state.copyWith(menuEntries: entries)); + }); + + _completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) { + add(MenuEvent()); + }); + } + + @override + Future close() { + _completer.cancel(); + return super.close(); + } + + } 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 fa22cbfc..bd77e2de 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 @@ -1,52 +1,11 @@ -import 'dart:async'; + import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; - - class MenuViewEvent {} -class MenuViewState { - final List menuEntries; - final bool isGrid; - - MenuViewState({this.menuEntries = const [], this.isGrid = false}); - - MenuViewState copyWith({List? menuEntries, bool? isGrid}) { - return MenuViewState( - menuEntries: menuEntries ?? this.menuEntries, - isGrid: isGrid ?? this.isGrid, - ); - } -} +class MenuViewState {} class MenuViewBloc extends Bloc { - final MenuView style; - final EnumMenuItem item; - final List menuOptions; - late StreamSubscription _completer; - - - MenuViewBloc({required this.style, required this.item, required this.menuOptions}) : super(MenuViewState()) { - on((event, emit) async { - await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); - final entries = await MenuRepositoryImpl().generateMenuEntries(menuOptions, item); - emit(state.copyWith(menuEntries: entries)); - }); - - _completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) { - add(MenuViewEvent()); - }); - } - - @override - Future close() { - _completer.cancel(); - return super.close(); - } - - + MenuViewBloc() : super(MenuViewState()); } diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index 39b8e3c7..42b535fd 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -214,6 +214,7 @@ class MenuEntry implements BaseModule { static List getEntriesByType(MenuEntryType type) { return entries.where((entry) => entry.types.contains(type)).toList(); } + } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart index 927fda08..3528588d 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart @@ -44,12 +44,12 @@ class Menufactory extends StatelessWidget { Widget _buildMenuBloc(BuildContext context) { return BlocProvider( - create: (context) => MenuViewBloc( + create: (context) => MenuBloc( style: view, item: item, menuOptions: entry, - )..add(MenuViewEvent()), - child: BlocBuilder( + )..add(MenuEvent()), + child: BlocBuilder( builder: (context, state) { if (view == MenuView.list_grid) { return MenuStaggeredView( diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart index f5204eca..7e861894 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart @@ -44,7 +44,7 @@ class _MenuButtonWidgetState extends State { setState(() { _isProcessing = true; }); - widget.action.call(); + await widget.action.call(); setState(() { _isProcessing = false; }); diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart index 074d5a22..b120a09d 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart @@ -39,7 +39,7 @@ class _MenuCardItemState extends State { setState(() { _isProcessing = true; }); - widget.action.call(); + await widget.action.call(); setState(() { _isProcessing = false; }); diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 06cc2e68..138e114f 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -1,18 +1,19 @@ -import 'dart:developer'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:hub/shared/extensions/string_extensions.dart'; import 'package:sqflite/sqflite.dart'; abstract class LicenseLocalDataSource { Future init(); Future setDisplayByKey(final List key, final String display); Future isNewVersion(); - Future g(String key); - Future s(String key, T value); - Future d(String key); - Future c(); + Future get(String key); + Future set(String key, T value); + Future del(String key); + Future clear(); } class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { @@ -21,15 +22,17 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { LicenseLocalDataSourceImpl._internal(); + @override Future init() async { await DatabaseStorage.instance.init(); } + @override Future setDisplayByKey(final List key, final String display) async { if (key.isEmpty) return; for (var element in key) { if (element != null) { - await s(element, { + await set(element, { 'display': display, 'expirationDate': '', 'startDate': '', @@ -39,15 +42,15 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { } } + @override Future isNewVersion() async { - var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [KeychainStorageKey.isNewVersion.value], columns: ['display']); - if (response.isEmpty) { - return false; - } - return response.first['display'] == 'true'; + final String? reponse = await StorageHelper().get(KeychainStorageKey.isNewVersion.value); + final bool isNewVersion = reponse.toBoolean(); + return isNewVersion; } - Future g(String key) async { + @override + Future get(String key) async { var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; @@ -55,7 +58,8 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { return response.first.toString(); } - Future s(String key, T value) async { + @override + Future set(String key, T value) async { value as Map; await DatabaseStorage.database.insert( @@ -71,11 +75,13 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { return; } - Future d(String key) async { + @override + Future del(String key) async { await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); } - Future c() async { + @override + Future clear() async { await DatabaseStorage.database.delete(tableLicense); } } 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 8755b436..5835bd60 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 @@ -7,7 +7,6 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; -import 'package:rxdart/rxdart.dart'; import 'package:sqflite/sqflite.dart'; abstract class LicenseRemoteDataSource { @@ -118,6 +117,6 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { static Future _saveModule(final dynamic body) async { if (body is! Map) return; - await LicenseLocalDataSourceImpl().s(body['key'], body); + await LicenseLocalDataSourceImpl().set(body['key'], body); } } diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index 8cb1c549..48cd0436 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -17,7 +17,8 @@ class LicenseRepositoryImpl implements LicenseRepository { static final license = BehaviorSubject(); static get stream => license.stream; - Future updateLicense(bool isNewVersion) async { + Future updateLicense() async { + final bool isNewVersion = await localDataSource.isNewVersion(); await remoteDataSource.setupLicense(database, isNewVersion); if (isNewVersion) { return await remoteDataSource.fetchLicenses(isNewVersion); @@ -31,10 +32,10 @@ class LicenseRepositoryImpl implements LicenseRepository { } Future getLicense(String key) async { - return await localDataSource.g(key); + return await localDataSource.get(key); } Future setLicense(String key, T value) async { - return await localDataSource.s(key, value); + return await localDataSource.set(key, value); } } diff --git a/lib/shared/components/molecules/modules/domain/entities/base_module.dart b/lib/shared/components/molecules/modules/domain/entities/base_module.dart index b67b25a9..662fa7b2 100644 --- a/lib/shared/components/molecules/modules/domain/entities/base_module.dart +++ b/lib/shared/components/molecules/modules/domain/entities/base_module.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; + + abstract class BaseModule { String get value; String get name; diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 1c3d6410..7daaac0e 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -6,8 +6,8 @@ import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'module.dart'; -enum LicenseKeys { +enum LicenseKeys { messages('FRE-HUB-MESSAGES'), liberations('FRE-HUB-LIBERATIONS'), reservations('FRE-HUB-RESERVATIONS'), diff --git a/lib/shared/components/molecules/modules/domain/entities/module.dart b/lib/shared/components/molecules/modules/domain/entities/module.dart index 060586aa..7dc2e8c2 100644 --- a/lib/shared/components/molecules/modules/domain/entities/module.dart +++ b/lib/shared/components/molecules/modules/domain/entities/module.dart @@ -3,6 +3,30 @@ import 'package:hub/shared/components/molecules/modules/data/models/module_model enum ModuleStatus { active, inactive, disabled } +enum EnumDisplay { + active('VISIVEL'), + inactive('INVISIVEL'), + expired('DESABILITADO'); + + final String value; + const EnumDisplay(this.value); + + static EnumDisplay fromString(String? value) { + if (value == null) return EnumDisplay.inactive; + switch (value) { + case 'VISIVEL': + return EnumDisplay.active; + case 'INVISIVEL': + return EnumDisplay.inactive; + case 'DESABILITADO': + return EnumDisplay.expired; + default: + return EnumDisplay.inactive; + } + } +} + + extension ModuleStatusExtension on ModuleStatus { String get key { switch (this) { diff --git a/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart b/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart index 1d1691d2..732e7baf 100644 --- a/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart +++ b/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart @@ -1,5 +1,5 @@ abstract class LicenseRepository { - Future updateLicense(bool isNewVersion); + Future updateLicense(); Future cleanLicense(); Future getLicense(String key); diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index e3093ad5..86830d4b 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -32,7 +32,7 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - await LicenseRepositoryImpl().updateLicense(false); + await LicenseRepositoryImpl().updateLicense(); isInitialized = true; } diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index ec1f6e80..0431c8f1 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -23,15 +23,18 @@ class KeychainHelper implements BaseStorage { @override Future get(String key) async { + var response = await DatabaseStorage.database.query(tableKeychain, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; } + log('() => get keychain: $key : ${response.first['value']}'); return response.first['value'].toString(); } @override Future set(String key, T value) async { + var date = DateTime.now().toIso8601String(); await DatabaseStorage.database.insert( tableKeychain, @@ -44,6 +47,7 @@ class KeychainHelper implements BaseStorage { 'createdAt': date, }, conflictAlgorithm: ConflictAlgorithm.replace); + log('() => set keychain: $key : $value'); } @override @@ -53,7 +57,11 @@ class KeychainHelper implements BaseStorage { @override Future clearAll() async { - await DatabaseStorage.database.delete(tableKeychain); + try { + await DatabaseStorage.database.delete(tableKeychain); + } catch (e, s) { + log('() => clearAll keychain: $e', stackTrace: s); + } } diff --git a/lib/shared/helpers/storage/storage_helper.dart b/lib/shared/helpers/storage/storage_helper.dart index 9600a652..e59c39ea 100644 --- a/lib/shared/helpers/storage/storage_helper.dart +++ b/lib/shared/helpers/storage/storage_helper.dart @@ -26,7 +26,7 @@ class StorageHelper { if (isFirstRun != 'false') { await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, false); - await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false); + await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false); } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 2053ede1..ae3d457a 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; @@ -138,6 +140,8 @@ class AuthenticationService { alignment: Alignment.bottomCenter, ), }; + + await StorageHelper().clean(Storage.databaseStorage); await StorageHelper().clean(Storage.secureStorage); await StorageHelper().clean(Storage.databaseStorage); context.go('/welcomePage', extra: extra);