FIX: correção do tratamento de cache na tela de Configurações do Sistema
This commit is contained in:
parent
220d48e80b
commit
43ff7cf5c8
|
@ -14,16 +14,15 @@ import '../../shared/utils/snackbar_util.dart';
|
|||
|
||||
class PreferencesPageModel with ChangeNotifier {
|
||||
final unfocusNode = FocusNode();
|
||||
bool fingerprint = false;
|
||||
bool person = false;
|
||||
bool notify = false;
|
||||
bool access = false;
|
||||
bool panic = false;
|
||||
|
||||
PreferencesPageModel() {
|
||||
initVariables();
|
||||
}
|
||||
|
||||
Future<void> initVariables() async {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> enablePerson(BuildContext context) async {
|
||||
final String userDevUUID = StorageUtil().userDevUUID;
|
||||
notifyListeners();
|
||||
|
@ -53,7 +52,7 @@ class PreferencesPageModel with ChangeNotifier {
|
|||
);
|
||||
context.pop();
|
||||
SnackBarUtil.showSnackBar(context, content);
|
||||
notify = await _toggleBoolInDb('notify');
|
||||
StorageUtil().notify = !StorageUtil().notify;
|
||||
notifyListeners();
|
||||
} catch (err) {
|
||||
content = FFLocalizations.of(context).getVariableText(
|
||||
|
@ -78,7 +77,7 @@ class PreferencesPageModel with ChangeNotifier {
|
|||
.then((value) async {
|
||||
final String content;
|
||||
if (jsonDecode(value.jsonBody['error'].toString()) == false) {
|
||||
if (!access) access = await _toggleBoolInDb('access');
|
||||
if (!StorageUtil().access) StorageUtil().access = !StorageUtil().access;
|
||||
notifyListeners();
|
||||
content = FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Access pass changed successfully',
|
||||
|
@ -114,7 +113,7 @@ class PreferencesPageModel with ChangeNotifier {
|
|||
.then((value) async {
|
||||
final String content;
|
||||
if (jsonDecode(value.jsonBody['error'].toString()) == false) {
|
||||
if (!panic) panic = await _toggleBoolInDb('panic');
|
||||
if (!StorageUtil().panic) StorageUtil().panic = !StorageUtil().panic;
|
||||
notifyListeners();
|
||||
content = FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Panic password changed successfully',
|
||||
|
@ -147,16 +146,16 @@ class PreferencesPageModel with ChangeNotifier {
|
|||
);
|
||||
|
||||
onChange(String? key) async {
|
||||
if (!fingerprint) StorageUtil().fingerprintPass = key ?? '';
|
||||
if (fingerprint) SecureStorageHelper().delete('fingerprintPass');
|
||||
StorageUtil().fingerprint = !StorageUtil().fingerprint;
|
||||
if (!StorageUtil().fingerprint) StorageUtil().fingerprintPass = key ?? '';
|
||||
if (StorageUtil().fingerprint) StorageUtil().fingerprintPass = '';
|
||||
|
||||
fingerprint = await _toggleBoolInDb('fingerprint');
|
||||
notifyListeners();
|
||||
|
||||
SnackBarUtil.showSnackBar(context, content);
|
||||
}
|
||||
|
||||
fingerprint ? onChange(null) : _showPassKey(context, onChange);
|
||||
StorageUtil().fingerprint ? onChange(null) : _showPassKey(context, onChange);
|
||||
}
|
||||
|
||||
Future<void> deleteAccount(BuildContext context) async {
|
||||
|
@ -202,27 +201,7 @@ class PreferencesPageModel with ChangeNotifier {
|
|||
}
|
||||
|
||||
|
||||
Future<void> initVariables() async {
|
||||
fingerprint = await _getBoolFromDb('fingerprint');
|
||||
person = await _getBoolFromDb('person');
|
||||
notify = await _getBoolFromDb('notify');
|
||||
access = await _getBoolFromDb('pass');
|
||||
panic = await _getBoolFromDb('panic');
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> _getBoolFromDb(String key) async {
|
||||
final value = SQLiteStorageHelper().get(key);
|
||||
return value.toString() == 'true';
|
||||
}
|
||||
|
||||
Future<bool> _toggleBoolInDb(String key) async {
|
||||
final currentValue = await _getBoolFromDb(key);
|
||||
final newValue = !currentValue;
|
||||
await SQLiteStorageHelper().set(key, newValue.toString(), (v) {});
|
||||
|
||||
return newValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
|||
case 0:
|
||||
icon = Icons.fingerprint;
|
||||
onPressed = () => model.toggleFingerprint(context);
|
||||
isEnabled = model.fingerprint;
|
||||
isEnabled = StorageUtil().fingerprint;
|
||||
content = FFLocalizations.of(context).getVariableText(
|
||||
ptText:
|
||||
'Ative a autenticação por impressão digital para login seguro.',
|
||||
|
@ -112,7 +112,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
|||
case 1:
|
||||
icon = Icons.person;
|
||||
onPressed = () => model.enablePerson(context);
|
||||
isEnabled = model.person;
|
||||
isEnabled = StorageUtil().person;
|
||||
content = FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Compartilhe o código de identificação remota',
|
||||
enText: 'Share the remote identification code',
|
||||
|
@ -121,7 +121,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
|||
case 2:
|
||||
icon = Icons.notifications;
|
||||
onPressed = () => model.toggleNotify(context);
|
||||
isEnabled = model.notify;
|
||||
isEnabled = StorageUtil().notify;
|
||||
content = FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Ative para receber sua notificação de acesso',
|
||||
enText: 'Enable to receive your access notification',
|
||||
|
@ -130,7 +130,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
|||
case 3:
|
||||
icon = Icons.lock;
|
||||
onPressed = () => model.toggleAccess(context);
|
||||
isEnabled = model.access;
|
||||
isEnabled = StorageUtil().access;
|
||||
content = FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Ative para inserir uma credencial de acesso para o QRCode',
|
||||
enText: 'Enable to enter an access credential for the QRCode',
|
||||
|
@ -139,7 +139,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
|||
case 4:
|
||||
icon = Icons.lock_clock_sharp;
|
||||
onPressed = () => model.togglePanic(context);
|
||||
isEnabled = model.panic;
|
||||
isEnabled = StorageUtil().panic;
|
||||
content = FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Ative para inserir uma credencial de pânico para o QRCode',
|
||||
enText: 'Enable to enter a panic credential for the QRCode',
|
||||
|
|
Loading…
Reference in New Issue