WIP
This commit is contained in:
parent
4925433c92
commit
3080eac50b
|
@ -25,4 +25,4 @@ class OrderFilterModalModel extends FlutterFlowModel<OrderFilterModalWidget> {
|
||||||
textFieldFocusNode?.dispose();
|
textFieldFocusNode?.dispose();
|
||||||
textController?.dispose();
|
textController?.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,6 @@ import 'package:hub/components/molecular_components/order_filter_modal/order_fil
|
||||||
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
||||||
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
||||||
import 'package:hub/flutter_flow/nav/nav.dart';
|
import 'package:hub/flutter_flow/nav/nav.dart';
|
||||||
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
|
||||||
// ignore: unused_import
|
// ignore: unused_import
|
||||||
|
|
||||||
import 'package:hub/shared/utils/limited_text_size.dart';
|
import 'package:hub/shared/utils/limited_text_size.dart';
|
||||||
|
@ -29,22 +28,22 @@ class _OrderFilterModalWidgetState extends State<OrderFilterModalWidget> {
|
||||||
late Map<String, dynamic> selected;
|
late Map<String, dynamic> selected;
|
||||||
final List<Map<String, String>> adresseeTypeOptions = [
|
final List<Map<String, String>> adresseeTypeOptions = [
|
||||||
{
|
{
|
||||||
'title': FFLocalizations.of(StorageHelper().context!).getVariableText(enText: 'Resident', ptText: 'Morador'),
|
'title': FFLocalizations.of(navigatorKey.currentContext!).getVariableText(enText: 'Resident', ptText: 'Morador'),
|
||||||
'value': 'MOR'
|
'value': 'MOR'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'title': FFLocalizations.of(StorageHelper().context!).getVariableText(enText: 'Property', ptText: 'Propriedade'),
|
'title': FFLocalizations.of(navigatorKey.currentContext!).getVariableText(enText: 'Property', ptText: 'Propriedade'),
|
||||||
'value': 'PRO'
|
'value': 'PRO'
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
final List<Map<String, String>> statusOptions = [
|
final List<Map<String, String>> statusOptions = [
|
||||||
{
|
{
|
||||||
'title': FFLocalizations.of(StorageHelper().context!)
|
'title': FFLocalizations.of(navigatorKey.currentContext!)
|
||||||
.getVariableText(ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'),
|
.getVariableText(ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'),
|
||||||
'value': 'notPickedUp'
|
'value': 'notPickedUp'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'title': FFLocalizations.of(StorageHelper().context!).getVariableText(ptText: 'Retirado', enText: 'Picked Up'),
|
'title': FFLocalizations.of(navigatorKey.currentContext!).getVariableText(ptText: 'Retirado', enText: 'Picked Up'),
|
||||||
'value': 'pickedUp'
|
'value': 'pickedUp'
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -232,4 +231,4 @@ class _OrderFilterModalWidgetState extends State<OrderFilterModalWidget> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -42,8 +42,11 @@ class _HomePageWidgetState extends State<HomePageWidget> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Builder(
|
return Builder(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
|
// LocalsRepositoryImpl.license.add(false);
|
||||||
|
// context.read<LocalProfileBloc>().add(LocalProfileEvent());
|
||||||
|
// context.read<MenuBloc>().add(MenuEvent());
|
||||||
LocalsRepositoryImpl.license.add(true);
|
LocalsRepositoryImpl.license.add(true);
|
||||||
// context.read<LocalProfileBloc>().updateProfile(context);
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: scaffoldKey,
|
key: scaffoldKey,
|
||||||
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
||||||
|
|
|
@ -123,10 +123,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
FFRoute(name: 'homePage', path: '/homePage', builder: (context, params) {
|
FFRoute(name: 'homePage', path: '/homePage', builder: (context, params) {
|
||||||
log('params: $params');
|
|
||||||
final Future<bool> Function(BuildContext context)? update = params.getParam('update', ParamType.Function);
|
final Future<bool> Function(BuildContext context)? update = params.getParam('update', ParamType.Function);
|
||||||
log('update: $update');
|
|
||||||
|
|
||||||
return HomePageWidget(key: UniqueKey(), update: update);
|
return HomePageWidget(key: UniqueKey(), update: update);
|
||||||
|
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -192,11 +192,15 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
||||||
if (state == AppLifecycleState.detached) {
|
if (state == AppLifecycleState.detached) {
|
||||||
|
final isLogged = await StorageHelper().get(SecureStorageKey.isLogged.value);
|
||||||
|
log('isLogged: $isLogged');
|
||||||
|
if (isLogged.toBoolean()) {
|
||||||
LocalsRepositoryImpl.license.add(false);
|
LocalsRepositoryImpl.license.add(false);
|
||||||
final response = await LocalsRepositoryImpl().update(context);
|
final response = await LocalsRepositoryImpl().update(context);
|
||||||
LocalsRepositoryImpl.license.add(response);
|
LocalsRepositoryImpl.license.add(response);
|
||||||
await FirebaseMessagingService().updateDeviceToken();
|
await FirebaseMessagingService().updateDeviceToken();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -36,11 +36,11 @@ class _PackageOrderPage extends State<PackageOrderPage> {
|
||||||
List<dynamic> _orderList = [];
|
List<dynamic> _orderList = [];
|
||||||
|
|
||||||
final Map<String, String> filter = {
|
final Map<String, String> filter = {
|
||||||
'adresseeType': 'PRO',
|
'adresseeType': '.*',
|
||||||
'status': 'notPickedUp',
|
'status': 'notPickedUp',
|
||||||
};
|
};
|
||||||
|
|
||||||
String _adresseeType = 'PRO';
|
String _adresseeType = '.*';
|
||||||
String _status = 'notPickedUp';
|
String _status = 'notPickedUp';
|
||||||
|
|
||||||
late BehaviorSubject<Map<String, String>> _selectedTypeSubject;
|
late BehaviorSubject<Map<String, String>> _selectedTypeSubject;
|
||||||
|
@ -64,7 +64,7 @@ class _PackageOrderPage extends State<PackageOrderPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initDatabase() async {
|
Future<void> initDatabase() async {
|
||||||
cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? '';
|
cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value) ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -224,7 +224,7 @@ class _PackageOrderPage extends State<PackageOrderPage> {
|
||||||
return AppBar(
|
return AppBar(
|
||||||
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
title: Text(FFLocalizations.of(context).getVariableText(enText: 'Orders', ptText: 'Encomendas'),
|
title: Text(FFLocalizations.of(context).getVariableText(enText: 'My Orders', ptText: 'Minhas Encomendas'),
|
||||||
style: FlutterFlowTheme.of(context).headlineMedium.override(
|
style: FlutterFlowTheme.of(context).headlineMedium.override(
|
||||||
fontFamily: 'Nunito',
|
fontFamily: 'Nunito',
|
||||||
color: FlutterFlowTheme.of(context).primaryText,
|
color: FlutterFlowTheme.of(context).primaryText,
|
||||||
|
@ -412,9 +412,8 @@ class _PackageOrderPage extends State<PackageOrderPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
|
||||||
appBar: _appBar(context),
|
appBar: _appBar(context),
|
||||||
body: _appBody(context),
|
body: _appBody(context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ import 'dart:developer';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:hub/shared/components/molecules/locals/index.dart';
|
import 'package:hub/shared/components/molecules/locals/index.dart';
|
||||||
|
import 'package:hub/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart';
|
||||||
import 'package:hub/shared/components/molecules/modules/index.dart';
|
import 'package:hub/shared/components/molecules/modules/index.dart';
|
||||||
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
||||||
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
||||||
|
@ -23,18 +24,34 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
||||||
@override
|
@override
|
||||||
Future<bool> update(BuildContext context) async {
|
Future<bool> update(BuildContext context) async {
|
||||||
bool response = false;
|
bool response = false;
|
||||||
while (!response) {
|
try {
|
||||||
response = await remoteDataSource.processLocals(context);
|
while (!response) {
|
||||||
if (!response) {
|
response = await remoteDataSource.processLocals(context);
|
||||||
await StorageHelper().set(KeychainStorageKey.clientUUID.value, '');
|
if (!response) {
|
||||||
const String errorMsg = 'Erro ao atualizar locais';
|
await _handleUpdateError(context);
|
||||||
await DialogUtil.error(context, errorMsg);
|
}
|
||||||
}
|
}
|
||||||
|
await _notifyBlocs(context);
|
||||||
|
} catch (e) {
|
||||||
|
log('Error updating locals: $e');
|
||||||
|
await _handleUpdateError(context);
|
||||||
}
|
}
|
||||||
context.read<LocalProfileBloc>().add(LocalProfileEvent());
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _handleUpdateError(BuildContext context) async {
|
||||||
|
await StorageHelper().set(KeychainStorageKey.clientUUID.value, '');
|
||||||
|
const String errorMsg = 'Erro ao atualizar locais';
|
||||||
|
await DialogUtil.error(context, errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _notifyBlocs(BuildContext context) async {
|
||||||
|
LocalsRepositoryImpl.license.add(false);
|
||||||
|
context.read<LocalProfileBloc>().add(LocalProfileEvent());
|
||||||
|
context.read<MenuBloc>().add(MenuEvent());
|
||||||
|
LocalsRepositoryImpl.license.add(true);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> unlinkLocal(BuildContext context) {
|
Future<void> unlinkLocal(BuildContext context) {
|
||||||
return remoteDataSource.detachLocal(context);
|
return remoteDataSource.detachLocal(context);
|
||||||
|
|
|
@ -36,7 +36,6 @@ class LocalProfileBloc extends Bloc<LocalProfileEvent, LocalProfileState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLocalProfileEvent(LocalProfileEvent event, Emitter<LocalProfileState> emit) async {
|
Future<void> _onLocalProfileEvent(LocalProfileEvent event, Emitter<LocalProfileState> emit) async {
|
||||||
log('LocalProfileBloc: _onLocalProfileEvent');
|
|
||||||
final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? '';
|
final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? '';
|
||||||
final ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? '';
|
final ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? '';
|
||||||
final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? '';
|
final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? '';
|
||||||
|
|
|
@ -22,17 +22,16 @@ class MenuRepositoryImpl implements MenuRepository {
|
||||||
Future<List<MenuItem?>> generateMenuEntries(List<MenuEntry> menuEntries, EnumMenuItem item) async {
|
Future<List<MenuItem?>> generateMenuEntries(List<MenuEntry> menuEntries, EnumMenuItem item) async {
|
||||||
log('Generating menu entries for $item');
|
log('Generating menu entries for $item');
|
||||||
List<MenuItem?> entries = [];
|
List<MenuItem?> entries = [];
|
||||||
final bool isNewVersion = await StorageHelper().get(KeychainStorageKey.isNewVersion.value).then((v) => v.toBoolean());
|
// final bool isNewVersion = await StorageHelper().get(KeychainStorageKey.isNewVersion.value).then((v) => v.toBoolean());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (var entry in menuEntries) {
|
for (var entry in menuEntries) {
|
||||||
log('Processing entry: ${entry.key}');
|
|
||||||
final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries);
|
final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries);
|
||||||
if (isDefault) continue;
|
if (isDefault) continue;
|
||||||
final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key);
|
final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key);
|
||||||
if (licenseValue != null) {
|
if (licenseValue != null) {
|
||||||
final licenseMap = await stringToMap(licenseValue);
|
final licenseMap = await stringToMap(licenseValue);
|
||||||
final display = await processDisplay(licenseMap, isNewVersion);
|
final display = EnumDisplay.fromString(licenseMap['display']);
|
||||||
final startDate = licenseMap['startDate'] ?? '';
|
final startDate = licenseMap['startDate'] ?? '';
|
||||||
final expirationDate = licenseMap['expirationDate'] ?? '';
|
final expirationDate = licenseMap['expirationDate'] ?? '';
|
||||||
final isStarted = await menuDataSource.processStartDate(startDate, entry);
|
final isStarted = await menuDataSource.processStartDate(startDate, entry);
|
||||||
|
@ -57,13 +56,9 @@ class MenuRepositoryImpl implements MenuRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<EnumDisplay> processDisplay(Map<String, dynamic> module, bool isNewVersion) async {
|
Future<EnumDisplay> processDisplay(Map<String, dynamic> module, bool isNewVersion) async {
|
||||||
const keysToCheck = [
|
|
||||||
LicenseKeys.residents,
|
|
||||||
LicenseKeys.vehicles,
|
|
||||||
LicenseKeys.openedVisits
|
|
||||||
];
|
|
||||||
|
|
||||||
if (isNewVersion && keysToCheck.any((key) => module['key'] == key.value)) {
|
|
||||||
|
if (await _shouldUpdateDisplay(module, isNewVersion)) {
|
||||||
final displayValue = module['display'] == EnumDisplay.active ? 'VISIVEL' : 'INVISIVEL';
|
final displayValue = module['display'] == EnumDisplay.active ? 'VISIVEL' : 'INVISIVEL';
|
||||||
await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-ABOUT-PROPERTY'], displayValue);
|
await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-ABOUT-PROPERTY'], displayValue);
|
||||||
return EnumDisplay.fromString(displayValue);
|
return EnumDisplay.fromString(displayValue);
|
||||||
|
@ -72,5 +67,14 @@ class MenuRepositoryImpl implements MenuRepository {
|
||||||
return EnumDisplay.fromString(module['display']);
|
return EnumDisplay.fromString(module['display']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> _shouldUpdateDisplay(Map<String, dynamic> module, bool isNewVersion) async {
|
||||||
|
const keysToCheck = [
|
||||||
|
LicenseKeys.residents,
|
||||||
|
LicenseKeys.vehicles,
|
||||||
|
LicenseKeys.openedVisits
|
||||||
|
];
|
||||||
|
return isNewVersion && keysToCheck.any((key) => module['key'] == key.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -33,24 +33,21 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
|
||||||
final MenuView style;
|
final MenuView style;
|
||||||
final EnumMenuItem item;
|
final EnumMenuItem item;
|
||||||
final List<MenuEntry> entries;
|
final List<MenuEntry> entries;
|
||||||
late StreamSubscription<void> _completer;
|
late StreamSubscription<bool> _completer;
|
||||||
|
|
||||||
|
|
||||||
MenuBloc({required this.style, required this.item, required this.entries}) : super(MenuState()) {
|
MenuBloc({required this.style, required this.item, required this.entries}) : super(MenuState()) {
|
||||||
on<MenuEvent>(_onMenuEvent);
|
on<MenuEvent>(_onMenuEvent);
|
||||||
|
_completer = LocalsRepositoryImpl.license.stream.listen((v) {
|
||||||
_completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) {
|
|
||||||
add(MenuEvent());
|
add(MenuEvent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onMenuEvent(MenuEvent event, Emitter<MenuState> emit) async {
|
Future<void> _onMenuEvent(MenuEvent event, Emitter<MenuState> emit) async {
|
||||||
|
|
||||||
await LicenseRemoteDataSourceImpl().waitForSaveCompletion();
|
await LicenseRemoteDataSourceImpl().waitForSaveCompletion();
|
||||||
|
|
||||||
final List<MenuItem?> NewEntries = await MenuRepositoryImpl().generateMenuEntries(entries, item);
|
final List<MenuItem?> newEntries = await MenuRepositoryImpl().generateMenuEntries(entries, item);
|
||||||
emit(state.copyWith(menuEntries: NewEntries));
|
emit(state.copyWith(menuEntries: newEntries));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() {
|
Future<void> close() {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
|
||||||
const String tableLicense = 'license';
|
const String tableLicense = 'license';
|
||||||
|
|
||||||
String get createLicenseTable => '''
|
class LicenseConstants {
|
||||||
|
static String get createLicenseTable => '''
|
||||||
CREATE TABLE IF NOT EXISTS $tableLicense (
|
CREATE TABLE IF NOT EXISTS $tableLicense (
|
||||||
key TEXT UNIQUE,
|
key TEXT UNIQUE,
|
||||||
display TEXT,
|
display TEXT,
|
||||||
|
@ -11,9 +12,9 @@
|
||||||
);
|
);
|
||||||
''';
|
''';
|
||||||
|
|
||||||
String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;';
|
static String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;';
|
||||||
|
|
||||||
String get updatePetsHistoryTrigger => '''
|
static String get updatePetsHistoryTrigger => '''
|
||||||
CREATE TRIGGER update_fre_hub_pets_history
|
CREATE TRIGGER update_fre_hub_pets_history
|
||||||
AFTER INSERT ON $tableLicense
|
AFTER INSERT ON $tableLicense
|
||||||
WHEN NEW.key = 'FRE-HUB-PETS'
|
WHEN NEW.key = 'FRE-HUB-PETS'
|
||||||
|
@ -23,15 +24,35 @@
|
||||||
END;
|
END;
|
||||||
''';
|
''';
|
||||||
|
|
||||||
String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;';
|
static String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;';
|
||||||
|
|
||||||
String get updateDisplayTrigger => '''
|
static String get updateDisplayTrigger => '''
|
||||||
CREATE TRIGGER update_display_trigger
|
CREATE TRIGGER update_display_trigger
|
||||||
|
AFTER UPDATE ON $tableLicense
|
||||||
|
WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS')
|
||||||
|
BEGIN
|
||||||
|
INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity)
|
||||||
|
VALUES (
|
||||||
|
'FRE-HUB-ABOUT-PROPERTY',
|
||||||
|
CASE
|
||||||
|
WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0
|
||||||
|
THEN 'VISIVEL'
|
||||||
|
ELSE 'INVISIVEL'
|
||||||
|
END,
|
||||||
|
NULL, NULL, NULL
|
||||||
|
);
|
||||||
|
END;
|
||||||
|
''';
|
||||||
|
|
||||||
|
static String get dropUpdateDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;';
|
||||||
|
|
||||||
|
static String get insertDisplayTrigger => '''
|
||||||
|
CREATE TRIGGER insert_display_trigger
|
||||||
AFTER INSERT ON $tableLicense
|
AFTER INSERT ON $tableLicense
|
||||||
WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS')
|
WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS')
|
||||||
BEGIN
|
BEGIN
|
||||||
UPDATE $tableLicense
|
UPDATE $tableLicense
|
||||||
SET display =
|
SET display =
|
||||||
CASE
|
CASE
|
||||||
WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0
|
WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0
|
||||||
THEN 'VISIVEL'
|
THEN 'VISIVEL'
|
||||||
|
@ -41,17 +62,23 @@
|
||||||
END;
|
END;
|
||||||
''';
|
''';
|
||||||
|
|
||||||
String get dropDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;';
|
static String get dropInsertDisplayTrigger => 'DROP TRIGGER IF EXISTS insert_display_trigger;';
|
||||||
|
|
||||||
String get updatePeopleDisplayTrigger => '''
|
static String get updatePeopleDisplayTrigger => '''
|
||||||
CREATE TRIGGER update_people_display_trigger
|
CREATE TRIGGER update_people_display_trigger
|
||||||
AFTER UPDATE ON $tableLicense
|
AFTER UPDATE ON $tableLicense
|
||||||
WHEN NEW.key = 'FRE-HUB-ABOUT-PROPERTY' AND NEW.display = 'VISIVEL'
|
WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS')
|
||||||
BEGIN
|
BEGIN
|
||||||
UPDATE $tableLicense
|
UPDATE $tableLicense
|
||||||
SET display = 'INVISIVEL'
|
SET display =
|
||||||
WHERE key = 'FRE-HUB-PEOPLE';
|
CASE
|
||||||
END;
|
WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0
|
||||||
|
THEN 'VISIVEL'
|
||||||
|
ELSE 'INVISIVEL'
|
||||||
|
END
|
||||||
|
WHERE key = 'FRE-HUB-ABOUT-PROPERTY';
|
||||||
|
END;
|
||||||
''';
|
''';
|
||||||
|
|
||||||
String get dropPeopleDisplayTrigger => 'DROP TRIGGER IF EXISTS update_people_display_trigger;';
|
static String get dropPeopleDisplayTrigger => 'DROP TRIGGER IF EXISTS update_people_display_trigger;';
|
||||||
|
}
|
|
@ -34,7 +34,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
if (keys.isEmpty) return;
|
if (keys.isEmpty) return;
|
||||||
final validKeys = keys.where((key) => key.isNotEmpty).toList();
|
final validKeys = keys.where((key) => key.isNotEmpty).toList();
|
||||||
for (var key in validKeys) {
|
for (var key in validKeys) {
|
||||||
log('Setting display: $key : $display');
|
|
||||||
await set(key, {
|
await set(key, {
|
||||||
'display': display,
|
'display': display,
|
||||||
'expirationDate': '',
|
'expirationDate': '',
|
||||||
|
@ -58,7 +57,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('Getting StartDate: ${response.toString()}');
|
|
||||||
|
|
||||||
return response.toString();
|
return response.toString();
|
||||||
}
|
}
|
||||||
|
@ -68,19 +66,11 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
value as Map<String, dynamic>;
|
value as Map<String, dynamic>;
|
||||||
if (value.isEmpty) return;
|
if (value.isEmpty) return;
|
||||||
if (key == 'null') return;
|
if (key == 'null') return;
|
||||||
|
|
||||||
|
|
||||||
log('Setting: ${value['key']} : ${value['display']}');
|
await DatabaseStorage.database.rawInsert(
|
||||||
await DatabaseStorage.database.insert(
|
'INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity) VALUES (?, ?, ?, ?, ?)',
|
||||||
tableLicense,
|
[key, value['display'], value['expirationDate'], value['startDate'], value['quantity']],
|
||||||
{
|
);
|
||||||
'key': key,
|
|
||||||
'display': value['display'],
|
|
||||||
'expirationDate': value['expirationDate'],
|
|
||||||
'startDate': value['startDate'],
|
|
||||||
'quantity': value['quantity'],
|
|
||||||
},
|
|
||||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,5 +82,7 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
@override
|
@override
|
||||||
Future<void> clear() async {
|
Future<void> clear() async {
|
||||||
await DatabaseStorage.database.delete(tableLicense);
|
await DatabaseStorage.database.delete(tableLicense);
|
||||||
|
await DatabaseStorage.database.rawDelete(
|
||||||
|
'DELETE FROM sqlite_sequence WHERE name = "$tableLicense"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
LicenseRemoteDataSourceImpl._internal();
|
LicenseRemoteDataSourceImpl._internal();
|
||||||
|
|
||||||
|
|
||||||
final StreamController<void> completerController = StreamController<void>.broadcast();
|
|
||||||
Stream<void> get streamCompleterController => completerController.stream;
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -46,19 +45,16 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
.where((module) => module.display == ModuleStatus.inactive.key)
|
.where((module) => module.display == ModuleStatus.inactive.key)
|
||||||
.map((module) => module.key)
|
.map((module) => module.key)
|
||||||
.toList();
|
.toList();
|
||||||
log('Módulos inativos: $inactiveModuleKey');
|
|
||||||
|
|
||||||
final List<String> activeModuleKey = license.modules
|
final List<String> activeModuleKey = license.modules
|
||||||
.where((module) => module.display == ModuleStatus.active.key)
|
.where((module) => module.display == ModuleStatus.active.key)
|
||||||
.map((module) => module.key)
|
.map((module) => module.key)
|
||||||
.toList();
|
.toList();
|
||||||
log('Módulos ativos: $activeModuleKey');
|
|
||||||
|
|
||||||
final List<String> disabledModuleKey = license.modules
|
final List<String> disabledModuleKey = license.modules
|
||||||
.where((module) => module.display == ModuleStatus.disabled.key)
|
.where((module) => module.display == ModuleStatus.disabled.key)
|
||||||
.map((module) => module.key)
|
.map((module) => module.key)
|
||||||
.toList();
|
.toList();
|
||||||
log('Módulos desabilitados: $disabledModuleKey');
|
|
||||||
|
|
||||||
await LicenseLocalDataSourceImpl().setDisplayByKey(inactiveModuleKey, 'INVISIVEL');
|
await LicenseLocalDataSourceImpl().setDisplayByKey(inactiveModuleKey, 'INVISIVEL');
|
||||||
await LicenseLocalDataSourceImpl().setDisplayByKey(activeModuleKey, 'VISIVEL');
|
await LicenseLocalDataSourceImpl().setDisplayByKey(activeModuleKey, 'VISIVEL');
|
||||||
|
@ -95,18 +91,13 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
log('Valores: ${LicenseKeys.values.map((e) => e.value).toList()}');
|
|
||||||
List<Future<void>> saveOperations = [];
|
List<Future<void>> saveOperations = [];
|
||||||
for (var element in responseBody) {
|
for (var element in responseBody) {
|
||||||
log('Elemento: ${element['key']}');
|
|
||||||
if (licenseContainsKey(element['key'])) {
|
if (licenseContainsKey(element['key'])) {
|
||||||
log('Salvando licença: ${element['key']}');
|
|
||||||
saveOperations.add(_saveModule(element));
|
saveOperations.add(_saveModule(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Future.wait(saveOperations);
|
await Future.wait(saveOperations);
|
||||||
final String? v = await LicenseRepositoryImpl().getLicense(LicenseKeys.property.value);
|
|
||||||
log('Licenças obtidas: $v');
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
log('Erro ao obter licenças: $e', stackTrace: s);
|
log('Erro ao obter licenças: $e', stackTrace: s);
|
||||||
|
@ -120,13 +111,11 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool licenseContainsKey(final String key) {
|
static bool licenseContainsKey(final String key) {
|
||||||
log('licenseContainsKey: $key');
|
|
||||||
|
|
||||||
return LicenseKeys.values.map((e) => e.value).toList().contains(key);
|
return LicenseKeys.values.map((e) => e.value).toList().contains(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> _saveModule(final dynamic body) async {
|
static Future<void> _saveModule(final dynamic body) async {
|
||||||
log('Salvando módulo: ${body['key']}');
|
|
||||||
if (body is! Map<String, dynamic>) return;
|
if (body is! Map<String, dynamic>) return;
|
||||||
await LicenseRepositoryImpl().setLicense(body['key'], body);
|
await LicenseRepositoryImpl().setLicense(body['key'], body);
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ class License {
|
||||||
),
|
),
|
||||||
Module(
|
Module(
|
||||||
key: LicenseKeys.property.value,
|
key: LicenseKeys.property.value,
|
||||||
display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.inactive.key,
|
display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key,
|
||||||
expirationDate: '',
|
expirationDate: '',
|
||||||
startDate: '',
|
startDate: '',
|
||||||
quantity: 0,
|
quantity: 0,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const String tableKeychain = 'keychain';
|
const String tableKeychain = 'keychain';
|
||||||
|
|
||||||
String get createKeychainTable => '''
|
String get createKeychainTable => '''
|
||||||
CREATE TABLE $tableKeychain (
|
CREATE TABLE IF NOT EXISTS $tableKeychain (
|
||||||
key TEXT UNIQUE,
|
key TEXT UNIQUE,
|
||||||
value TEXT,
|
value TEXT,
|
||||||
type TEXT,
|
type TEXT,
|
||||||
|
|
|
@ -6,8 +6,8 @@ import 'package:path/path.dart';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
|
||||||
class DatabaseStorage {
|
class DatabaseStorage {
|
||||||
static final String _dbName = 'database.db';
|
static const String _dbName = 'database.db';
|
||||||
static final int _dbVersion = 2;
|
static const int _dbVersion = 2;
|
||||||
|
|
||||||
static final DatabaseStorage instance = DatabaseStorage._internal();
|
static final DatabaseStorage instance = DatabaseStorage._internal();
|
||||||
factory DatabaseStorage() => instance;
|
factory DatabaseStorage() => instance;
|
||||||
|
@ -21,49 +21,76 @@ class DatabaseStorage {
|
||||||
return _database!;
|
return _database!;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInitialized = false;
|
static bool isInitialized = false;
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
if (isInitialized) return;
|
if (isInitialized) return;
|
||||||
|
|
||||||
_database = await openDatabase(
|
_database = await openDatabase(
|
||||||
join(await getDatabasesPath(), _dbName),
|
join(await getDatabasesPath(), _dbName),
|
||||||
version: _dbVersion,
|
version: _dbVersion,
|
||||||
onCreate: _onCreate,
|
onCreate: _onCreate,
|
||||||
onUpgrade: _onUpgrade,
|
onUpgrade: _onUpgrade,
|
||||||
onDowngrade: _onDowngrade,
|
onDowngrade: _onDowngrade,
|
||||||
|
onOpen: _onOpen,
|
||||||
|
onConfigure: _onConfigure,
|
||||||
|
singleInstance: true,
|
||||||
);
|
);
|
||||||
await LicenseRepositoryImpl().updateLicense();
|
await LicenseRepositoryImpl().updateLicense();
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onConfigure(Database database) async {
|
||||||
|
print('Configuring database...');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onOpen(Database database) async {
|
||||||
|
print('Opening database...');
|
||||||
|
await _executePragmas(database);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _onCreate(Database database, int version) async {
|
Future<void> _onCreate(Database database, int version) async {
|
||||||
log('Creating database...');
|
print('Creating database...');
|
||||||
await database.execute(createKeychainTable);
|
await _createTables(database, version);
|
||||||
await database.execute(createLicenseTable);
|
|
||||||
if (version >= 2) {
|
|
||||||
await database.execute(updatePetsHistoryTrigger);
|
|
||||||
await database.execute(updatePeopleDisplayTrigger);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onUpgrade(Database database, int oldVersion, int newVersion) async {
|
Future<void> _onUpgrade(Database database, int oldVersion, int newVersion) async {
|
||||||
log('Upgrading database from version $oldVersion to $newVersion...');
|
print('Upgrading database from version $oldVersion to $newVersion...');
|
||||||
if (oldVersion < 2 && newVersion >= 2) {
|
if (oldVersion < 2 && newVersion >= 2) {
|
||||||
await database.execute(createLicenseTable);
|
await _createTables(database, newVersion);
|
||||||
await database.execute(updatePetsHistoryTrigger);
|
|
||||||
await database.execute(updatePeopleDisplayTrigger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onDowngrade(Database database, int oldVersion, int newVersion) async {
|
Future<void> _onDowngrade(Database database, int oldVersion, int newVersion) async {
|
||||||
log('Downgrading database from version $oldVersion to $newVersion...');
|
print('Downgrading database from version $oldVersion to $newVersion...');
|
||||||
if (oldVersion >= 2 && newVersion < 2) {
|
if (oldVersion >= 2 && newVersion < 2) {
|
||||||
await database.execute(deleteLicenseTable);
|
await _dropTables(database);
|
||||||
await database.execute(dropPeopleDisplayTrigger);
|
|
||||||
await database.execute(dropPetsHistoryTrigger);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _executePragmas(Database database) async {
|
||||||
|
// await database.execute('PRAGMA journal_mode = WAL;');
|
||||||
|
await database.execute('PRAGMA synchronous = NORMAL;');
|
||||||
|
await database.execute('PRAGMA temp_store = MEMORY;');
|
||||||
|
await database.execute('PRAGMA foreign_keys = ON;');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _createTables(Database database, int version) async {
|
||||||
|
await database.execute(createKeychainTable);
|
||||||
|
await database.execute(LicenseConstants.createLicenseTable);
|
||||||
|
if (version >= 2) {
|
||||||
|
await database.execute(LicenseConstants.updatePetsHistoryTrigger);
|
||||||
|
await database.execute(LicenseConstants.updateDisplayTrigger);
|
||||||
|
await database.execute(LicenseConstants.insertDisplayTrigger);
|
||||||
|
await database.execute(LicenseConstants.updatePeopleDisplayTrigger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _dropTables(Database database) async {
|
||||||
|
await database.execute(LicenseConstants.deleteLicenseTable);
|
||||||
|
await database.execute(LicenseConstants.dropPeopleDisplayTrigger);
|
||||||
|
await database.execute(LicenseConstants.dropInsertDisplayTrigger);
|
||||||
|
await database.execute(LicenseConstants.dropUpdateDisplayTrigger);
|
||||||
|
await database.execute(LicenseConstants.dropPetsHistoryTrigger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,9 @@ class KeychainHelper implements BaseStorage {
|
||||||
Future<void> clearAll() async {
|
Future<void> clearAll() async {
|
||||||
try {
|
try {
|
||||||
await DatabaseStorage.database.delete(tableKeychain);
|
await DatabaseStorage.database.delete(tableKeychain);
|
||||||
|
await DatabaseStorage.database.rawDelete(
|
||||||
|
'DELETE FROM sqlite_sequence WHERE name = "$tableKeychain"');
|
||||||
|
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
log('() => clearAll keychain: $e', stackTrace: s);
|
log('() => clearAll keychain: $e', stackTrace: s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
||||||
import 'package:hub/shared/helpers/storage/keychain_storage.dart';
|
import 'package:hub/shared/helpers/storage/keychain_storage.dart';
|
||||||
|
@ -25,6 +27,7 @@ class StorageHelper {
|
||||||
String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value);
|
String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value);
|
||||||
|
|
||||||
if (isFirstRun != 'false') {
|
if (isFirstRun != 'false') {
|
||||||
|
log('First run');
|
||||||
await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ import 'dart:developer';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hub/features/home/presentation/pages/home_page.dart';
|
import 'package:hub/features/home/presentation/pages/home_page.dart';
|
||||||
import 'package:hub/flutter_flow/nav/nav.dart';
|
import 'package:hub/flutter_flow/nav/nav.dart';
|
||||||
|
import 'package:hub/shared/components/molecules/modules/data/repositories/license_repository_impl.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/base_storage.dart';
|
||||||
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
import 'package:hub/shared/helpers/storage/storage_helper.dart';
|
||||||
|
|
||||||
|
@ -147,7 +149,9 @@ class AuthenticationService {
|
||||||
|
|
||||||
await StorageHelper().clean(Storage.databaseStorage);
|
await StorageHelper().clean(Storage.databaseStorage);
|
||||||
await StorageHelper().clean(Storage.secureStorage);
|
await StorageHelper().clean(Storage.secureStorage);
|
||||||
await StorageHelper().clean(Storage.databaseStorage);
|
await LicenseRepositoryImpl().cleanLicense();
|
||||||
|
DatabaseStorage.isInitialized = false;
|
||||||
|
await StorageHelper().init();
|
||||||
context.go('/welcomePage', extra: extra);
|
context.go('/welcomePage', extra: extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue