357 lines
9.7 KiB
Dart
357 lines
9.7 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hub/flutter_flow/internationalization.dart';
|
|
import 'package:hub/flutter_flow/nav/nav.dart';
|
|
import 'package:hub/shared/helpers/database/database_helper.dart';
|
|
import 'package:sqflite/sqflite.dart';
|
|
|
|
enum InactiveModuleKey {
|
|
residents,
|
|
vehicles,
|
|
openedVisits,
|
|
}
|
|
|
|
enum ActiveModuleKey {
|
|
messages,
|
|
liberations,
|
|
reservations,
|
|
access,
|
|
orders,
|
|
completeSchedule,
|
|
providerSchedule,
|
|
deliverySchedule,
|
|
fastPass,
|
|
qrCode,
|
|
}
|
|
|
|
extension InactiveModuleKeyExtension on InactiveModuleKey {
|
|
String get value {
|
|
switch (this) {
|
|
case InactiveModuleKey.residents:
|
|
return 'FRE-HUB-RESIDENTS';
|
|
case InactiveModuleKey.vehicles:
|
|
return 'FRE-HUB-VEHICLES';
|
|
case InactiveModuleKey.openedVisits:
|
|
return 'FRE-HUB-OPENED-VISITS';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
extension ActiveModuleKeyExtension on ActiveModuleKey {
|
|
String get value {
|
|
switch (this) {
|
|
case ActiveModuleKey.messages:
|
|
return 'FRE-HUB-MESSAGES';
|
|
case ActiveModuleKey.liberations:
|
|
return 'FRE-HUB-LIBERATIONS';
|
|
case ActiveModuleKey.reservations:
|
|
return 'FRE-HUB-RESERVATIONS';
|
|
case ActiveModuleKey.access:
|
|
return 'FRE-HUB-ACCESS';
|
|
case ActiveModuleKey.orders:
|
|
return 'FRE-HUB-ORDERS';
|
|
case ActiveModuleKey.completeSchedule:
|
|
return 'FRE-HUB-COMPLETE-SCHEDULE';
|
|
case ActiveModuleKey.providerSchedule:
|
|
return 'FRE-HUB-AGE-PROV-PRESTADOR';
|
|
case ActiveModuleKey.deliverySchedule:
|
|
return 'FRE-HUB-AGE-PROV-DELIVERY';
|
|
case ActiveModuleKey.fastPass:
|
|
return 'FRE-HUB-FASTPASS';
|
|
case ActiveModuleKey.qrCode:
|
|
return 'FRE-HUB-QRCODE';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
enum Module {
|
|
messages,
|
|
liberations,
|
|
reservations,
|
|
access,
|
|
openedVisits,
|
|
vehicles,
|
|
residents,
|
|
pets,
|
|
orders,
|
|
completeSchedule,
|
|
providerSchedule,
|
|
deliverySchedule,
|
|
fastPass,
|
|
qrCode,
|
|
settings,
|
|
logout,
|
|
}
|
|
|
|
extension LicenseKeyExtension on Module {
|
|
String get value {
|
|
switch (this) {
|
|
case Module.messages:
|
|
return 'FRE-HUB-MESSAGES';
|
|
case Module.liberations:
|
|
return 'FRE-HUB-LIBERATIONS';
|
|
case Module.reservations:
|
|
return 'FRE-HUB-RESERVATIONS';
|
|
case Module.access:
|
|
return 'FRE-HUB-ACCESS';
|
|
case Module.openedVisits:
|
|
return 'FRE-HUB-OPENED-VISITS';
|
|
case Module.vehicles:
|
|
return 'FRE-HUB-VEHICLES';
|
|
case Module.residents:
|
|
return 'FRE-HUB-RESIDENTS';
|
|
case Module.pets:
|
|
return 'FRE-HUB-PETS';
|
|
case Module.orders:
|
|
return 'FRE-HUB-ORDERS';
|
|
case Module.completeSchedule:
|
|
return 'FRE-HUB-COMPLETE-SCHEDULE';
|
|
case Module.providerSchedule:
|
|
return 'FRE-HUB-AGE-PROV-PRESTADOR';
|
|
case Module.deliverySchedule:
|
|
return 'FRE-HUB-AGE-PROV-DELIVERY';
|
|
case Module.fastPass:
|
|
return 'FRE-HUB-FASTPASS';
|
|
case Module.qrCode:
|
|
return 'FRE-HUB-QRCODE';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
String get name {
|
|
switch (this) {
|
|
case Module.messages:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Mensagens',
|
|
enText: 'Messages',
|
|
);
|
|
case Module.liberations:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Liberar',
|
|
enText: 'Liberations',
|
|
);
|
|
case Module.reservations:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Reservas',
|
|
enText: 'Reservations',
|
|
);
|
|
case Module.access:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Acessos',
|
|
enText: 'Access',
|
|
);
|
|
case Module.openedVisits:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Visitas Abertas',
|
|
enText: 'Opened Visits',
|
|
);
|
|
case Module.vehicles:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Veículos',
|
|
enText: 'Vehicles',
|
|
);
|
|
case Module.residents:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Moradores',
|
|
enText: 'Residents',
|
|
);
|
|
case Module.pets:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Pets',
|
|
enText: 'Pets',
|
|
);
|
|
case Module.orders:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Encomendas',
|
|
enText: 'Orders',
|
|
);
|
|
case Module.completeSchedule:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Agenda Completa',
|
|
enText: 'Complete Schedule',
|
|
);
|
|
case Module.providerSchedule:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Agendar Prestadores',
|
|
enText: 'Schedule Providers',
|
|
);
|
|
case Module.deliverySchedule:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Agendar Delivery',
|
|
enText: 'Schedule Delivery',
|
|
);
|
|
case Module.fastPass:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Fast Pass',
|
|
enText: 'Fast Pass',
|
|
);
|
|
case Module.qrCode:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'QR Code',
|
|
enText: 'QR Code',
|
|
);
|
|
case Module.settings:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Configurações',
|
|
enText: 'Settings',
|
|
);
|
|
case Module.logout:
|
|
return FFLocalizations.of(key.currentContext!).getVariableText(
|
|
ptText: 'Sair',
|
|
enText: 'Logout',
|
|
);
|
|
}
|
|
}
|
|
|
|
IconData get icon {
|
|
switch (this) {
|
|
case Module.messages:
|
|
return Icons.message;
|
|
case Module.liberations:
|
|
return Icons.lock_open;
|
|
case Module.reservations:
|
|
return Icons.calendar_today;
|
|
case Module.access:
|
|
return Icons.access_time;
|
|
case Module.openedVisits:
|
|
return Icons.people;
|
|
case Module.vehicles:
|
|
return Icons.directions_car;
|
|
case Module.residents:
|
|
return Icons.person;
|
|
case Module.pets:
|
|
return Icons.pets;
|
|
case Module.orders:
|
|
return Icons.shopping_cart;
|
|
case Module.completeSchedule:
|
|
return Icons.schedule;
|
|
case Module.providerSchedule:
|
|
return Icons.engineering_outlined;
|
|
case Module.deliverySchedule:
|
|
return Icons.delivery_dining;
|
|
case Module.fastPass:
|
|
return Icons.fastfood;
|
|
case Module.qrCode:
|
|
return Icons.qr_code;
|
|
case Module.settings:
|
|
return Icons.settings;
|
|
case Module.logout:
|
|
return Icons.logout;
|
|
}
|
|
}
|
|
|
|
String get route {
|
|
switch (this) {
|
|
case Module.messages:
|
|
return '/messageHistoryPage';
|
|
case Module.liberations:
|
|
return '/liberationHistory';
|
|
case Module.reservations:
|
|
return '/reservation';
|
|
case Module.access:
|
|
return '/acessHistoryPage';
|
|
case Module.openedVisits:
|
|
return '/visitsOnTheProperty';
|
|
case Module.vehicles:
|
|
return '/vehiclesOnThePropertyPage';
|
|
case Module.residents:
|
|
return '/peopleOnThePropertyPage';
|
|
case Module.pets:
|
|
return '/petsPage';
|
|
case Module.orders:
|
|
return '/packageOrder';
|
|
case Module.completeSchedule:
|
|
return '/scheduleCompleteVisitPage';
|
|
case Module.providerSchedule:
|
|
return '/provisionalSchedule';
|
|
case Module.deliverySchedule:
|
|
return '/deliverySchedule';
|
|
case Module.fastPass:
|
|
return '/fastPassPage';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
class LicenseHelper {
|
|
static final LicenseHelper _instance = LicenseHelper._internal();
|
|
|
|
factory LicenseHelper() => _instance;
|
|
|
|
LicenseHelper._internal();
|
|
|
|
static const String tableLicense = 'license';
|
|
|
|
static String get createTableQuery => '''
|
|
CREATE TABLE $tableLicense (
|
|
key TEXT UNIQUE,
|
|
display TEXT,
|
|
expirationDate TEXT,
|
|
startDate TEXT,
|
|
quantity TEXT
|
|
);
|
|
''';
|
|
|
|
Future<void> init() async {
|
|
await DatabaseStorage.instance.init();
|
|
}
|
|
|
|
static Future<void> insertLicenseFoo(
|
|
final List<String> key, final String display) async {
|
|
for (var element in key) {
|
|
DatabaseStorage.database.insert(
|
|
tableLicense,
|
|
{
|
|
'key': element,
|
|
'display': display,
|
|
'expirationDate': '',
|
|
'startDate': '',
|
|
'quantity': '',
|
|
},
|
|
conflictAlgorithm: ConflictAlgorithm.ignore,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<String?> g(String key) async {
|
|
var response = await DatabaseStorage.database.query(tableLicense,
|
|
where: 'key = ?', whereArgs: [key], columns: ['display']);
|
|
if (response.isEmpty) {
|
|
return null;
|
|
}
|
|
return response.first['display'].toString();
|
|
}
|
|
|
|
Future<void> s<T>(String key, T value) async {
|
|
log('setLicense($key, $value)');
|
|
value as Map<String, dynamic>;
|
|
|
|
await DatabaseStorage.database.insert(
|
|
tableLicense,
|
|
{
|
|
'key': key,
|
|
'display': value['display'],
|
|
'expirationDate': value['expirationDate'],
|
|
'startDate': value['startDate'],
|
|
'quantity': value['quantity'],
|
|
},
|
|
conflictAlgorithm: ConflictAlgorithm.replace);
|
|
}
|
|
|
|
Future<void> d(String key) async {
|
|
await DatabaseStorage.database
|
|
.delete(tableLicense, where: 'key = ?', whereArgs: [key]);
|
|
}
|
|
|
|
Future<void> c() async {
|
|
await DatabaseStorage.database.delete(tableLicense);
|
|
}
|
|
}
|