support oldVersion license processing

This commit is contained in:
J. A. Messias 2024-12-02 10:48:53 -03:00
parent 39afcc91ef
commit 9a426079fb
11 changed files with 240 additions and 78 deletions

View File

@ -21,6 +21,18 @@ class HomePageWidget extends StatefulWidget {
class _HomePageWidgetState extends State<HomePageWidget> {
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
void initState() {
super.initState();
_initializePage();
}
Future<void> _initializePage() async {
await LocalsRepositoryImpl().processLocals(context).whenComplete(() async {
context.read<LocalProfileBloc>().add(LocalProfileEvent());
});
}
@override
Widget build(BuildContext context) {
return BlocProvider(

View File

@ -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<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
void main() async {
await initializeApp();
runApp(const App());
runApp(const ProviderScope(child: App()));
FirebaseMessaging.onBackgroundMessage(_backgroundHandlerMessage);
}

View File

@ -17,6 +17,8 @@ class LocalProfileComponentWidget extends StatefulWidget {
}
class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidget> {
@override
Widget build(BuildContext context) {
return BlocProvider<LocalProfileBloc>(

View File

@ -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<MenuViewEvent, MenuViewState> {
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);
});

View File

@ -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 '';
}

View File

@ -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 '';
}

View File

@ -38,7 +38,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
@override
Future<void> setupLicense(Database database, bool isNewVersion) async {
final License license = License.getLicense(isNewVersion);
final License license = await License.getLicense(isNewVersion);
final List<String> 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<void> _saveModule(final dynamic body) async {

View File

@ -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<Module> modules;
@ -14,161 +84,208 @@ class License {
this.modules,
);
static List<String> 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<String> 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<String> _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<String> _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<String> _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<String> _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<License> 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,
),
]);
}
}

View File

@ -194,21 +194,13 @@ class AuthenticationService {
String content;
try {
await PhpGroup.deleteAccount.call().then((value) async {
final Map<String, dynamic> extra = <String, dynamic>{
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;
}
}
}

View File

@ -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:

View File

@ -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