Merge pull request #39 from FRE-Informatica/fix/fd-784

Fix/fd 784
This commit is contained in:
Ivan Antunes 2024-09-19 10:04:55 -03:00 committed by GitHub
commit dd11427e66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import UIKit import UIKit
import Flutter import Flutter
import flutter_secure_storage
@main @main
@objc class AppDelegate: FlutterAppDelegate { @objc class AppDelegate: FlutterAppDelegate {
@ -9,6 +9,11 @@ import Flutter
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool { ) -> Bool {
GeneratedPluginRegistrant.register(with: self) GeneratedPluginRegistrant.register(with: self)
// Configurar o Keychain para remover dados quando o app for desinstalado
let secureStorage = FlutterSecureStoragePlugin()
secureStorage.setAccessibility(.whenPasscodeSetThisDeviceOnly)
return super.application(application, didFinishLaunchingWithOptions: launchOptions) return super.application(application, didFinishLaunchingWithOptions: launchOptions)
} }
} }

View File

@ -4,6 +4,7 @@ import 'package:csv/csv.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:local_auth/local_auth.dart'; import 'package:local_auth/local_auth.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:synchronized/synchronized.dart'; import 'package:synchronized/synchronized.dart';
class AppState extends ChangeNotifier { class AppState extends ChangeNotifier {
@ -71,6 +72,7 @@ class AppState extends ChangeNotifier {
Future initializePersistedState() async { Future initializePersistedState() async {
secureStorage = const FlutterSecureStorage(); secureStorage = const FlutterSecureStorage();
await _safeInitAsync(() async { await _safeInitAsync(() async {
_cliUUID = await secureStorage.getString('ff_cliUUID') ?? _cliUUID; _cliUUID = await secureStorage.getString('ff_cliUUID') ?? _cliUUID;
}); });
@ -177,6 +179,7 @@ class AppState extends ChangeNotifier {
await secureStorage.getBool('ff_request_os_notification') ?? await secureStorage.getBool('ff_request_os_notification') ??
_isRequestOSNotification; _isRequestOSNotification;
}); });
await loadFirstRun();
} }
void update(VoidCallback callback) { void update(VoidCallback callback) {
@ -186,6 +189,29 @@ class AppState extends ChangeNotifier {
late FlutterSecureStorage secureStorage; late FlutterSecureStorage secureStorage;
bool _firstRun = true;
bool get firstRun => _firstRun;
Future<void> loadFirstRun() async {
final prefs = await SharedPreferences.getInstance();
_firstRun = prefs.getBool('first_run') ?? true;
notifyListeners();
}
Future<void> setFirstRun(bool value) async {
final prefs = await SharedPreferences.getInstance();
_firstRun = value;
await prefs.setBool('first_run', value);
notifyListeners();
}
Future<void> deleteFirstRun() async {
final prefs = await SharedPreferences.getInstance();
_firstRun = true;
await prefs.remove('first_run');
notifyListeners();
}
int _petAmountRegister = 0; int _petAmountRegister = 0;
int get petAmountRegister => _petAmountRegister; int get petAmountRegister => _petAmountRegister;
set petAmountRegister(int value) { set petAmountRegister(int value) {
@ -586,7 +612,11 @@ class AppState extends ChangeNotifier {
AppState().deleteRemoteId(); AppState().deleteRemoteId();
AppState().deleteSerialNumber(); AppState().deleteSerialNumber();
secureStorage.deleteAll(); secureStorage.deleteAll();
AppState().isLogged = false; AppState().isLogged = false;
AppState().setFirstRun(false);
AppState().update(() {});
} }
} }

View File

@ -28,6 +28,10 @@ Future<void> initializeApp() async {
final appState = AppState(); final appState = AppState();
await appState.initializePersistedState(); await appState.initializePersistedState();
if (AppState().firstRun == true) {
AppState().deleteAll();
}
await Firebase.initializeApp(); await Firebase.initializeApp();
await NotificationService.initialize(); await NotificationService.initialize();