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 {
|
class PreferencesPageModel with ChangeNotifier {
|
||||||
final unfocusNode = FocusNode();
|
final unfocusNode = FocusNode();
|
||||||
bool fingerprint = false;
|
|
||||||
bool person = false;
|
|
||||||
bool notify = false;
|
|
||||||
bool access = false;
|
|
||||||
bool panic = false;
|
|
||||||
|
|
||||||
PreferencesPageModel() {
|
PreferencesPageModel() {
|
||||||
initVariables();
|
initVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> initVariables() async {
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> enablePerson(BuildContext context) async {
|
Future<void> enablePerson(BuildContext context) async {
|
||||||
final String userDevUUID = StorageUtil().userDevUUID;
|
final String userDevUUID = StorageUtil().userDevUUID;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -53,7 +52,7 @@ class PreferencesPageModel with ChangeNotifier {
|
||||||
);
|
);
|
||||||
context.pop();
|
context.pop();
|
||||||
SnackBarUtil.showSnackBar(context, content);
|
SnackBarUtil.showSnackBar(context, content);
|
||||||
notify = await _toggleBoolInDb('notify');
|
StorageUtil().notify = !StorageUtil().notify;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
content = FFLocalizations.of(context).getVariableText(
|
content = FFLocalizations.of(context).getVariableText(
|
||||||
|
@ -78,7 +77,7 @@ class PreferencesPageModel with ChangeNotifier {
|
||||||
.then((value) async {
|
.then((value) async {
|
||||||
final String content;
|
final String content;
|
||||||
if (jsonDecode(value.jsonBody['error'].toString()) == false) {
|
if (jsonDecode(value.jsonBody['error'].toString()) == false) {
|
||||||
if (!access) access = await _toggleBoolInDb('access');
|
if (!StorageUtil().access) StorageUtil().access = !StorageUtil().access;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
content = FFLocalizations.of(context).getVariableText(
|
content = FFLocalizations.of(context).getVariableText(
|
||||||
enText: 'Access pass changed successfully',
|
enText: 'Access pass changed successfully',
|
||||||
|
@ -114,7 +113,7 @@ class PreferencesPageModel with ChangeNotifier {
|
||||||
.then((value) async {
|
.then((value) async {
|
||||||
final String content;
|
final String content;
|
||||||
if (jsonDecode(value.jsonBody['error'].toString()) == false) {
|
if (jsonDecode(value.jsonBody['error'].toString()) == false) {
|
||||||
if (!panic) panic = await _toggleBoolInDb('panic');
|
if (!StorageUtil().panic) StorageUtil().panic = !StorageUtil().panic;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
content = FFLocalizations.of(context).getVariableText(
|
content = FFLocalizations.of(context).getVariableText(
|
||||||
enText: 'Panic password changed successfully',
|
enText: 'Panic password changed successfully',
|
||||||
|
@ -147,16 +146,16 @@ class PreferencesPageModel with ChangeNotifier {
|
||||||
);
|
);
|
||||||
|
|
||||||
onChange(String? key) async {
|
onChange(String? key) async {
|
||||||
if (!fingerprint) StorageUtil().fingerprintPass = key ?? '';
|
StorageUtil().fingerprint = !StorageUtil().fingerprint;
|
||||||
if (fingerprint) SecureStorageHelper().delete('fingerprintPass');
|
if (!StorageUtil().fingerprint) StorageUtil().fingerprintPass = key ?? '';
|
||||||
|
if (StorageUtil().fingerprint) StorageUtil().fingerprintPass = '';
|
||||||
|
|
||||||
fingerprint = await _toggleBoolInDb('fingerprint');
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
SnackBarUtil.showSnackBar(context, content);
|
SnackBarUtil.showSnackBar(context, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
fingerprint ? onChange(null) : _showPassKey(context, onChange);
|
StorageUtil().fingerprint ? onChange(null) : _showPassKey(context, onChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteAccount(BuildContext context) async {
|
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:
|
case 0:
|
||||||
icon = Icons.fingerprint;
|
icon = Icons.fingerprint;
|
||||||
onPressed = () => model.toggleFingerprint(context);
|
onPressed = () => model.toggleFingerprint(context);
|
||||||
isEnabled = model.fingerprint;
|
isEnabled = StorageUtil().fingerprint;
|
||||||
content = FFLocalizations.of(context).getVariableText(
|
content = FFLocalizations.of(context).getVariableText(
|
||||||
ptText:
|
ptText:
|
||||||
'Ative a autenticação por impressão digital para login seguro.',
|
'Ative a autenticação por impressão digital para login seguro.',
|
||||||
|
@ -112,7 +112,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
||||||
case 1:
|
case 1:
|
||||||
icon = Icons.person;
|
icon = Icons.person;
|
||||||
onPressed = () => model.enablePerson(context);
|
onPressed = () => model.enablePerson(context);
|
||||||
isEnabled = model.person;
|
isEnabled = StorageUtil().person;
|
||||||
content = FFLocalizations.of(context).getVariableText(
|
content = FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'Compartilhe o código de identificação remota',
|
ptText: 'Compartilhe o código de identificação remota',
|
||||||
enText: 'Share the remote identification code',
|
enText: 'Share the remote identification code',
|
||||||
|
@ -121,7 +121,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
||||||
case 2:
|
case 2:
|
||||||
icon = Icons.notifications;
|
icon = Icons.notifications;
|
||||||
onPressed = () => model.toggleNotify(context);
|
onPressed = () => model.toggleNotify(context);
|
||||||
isEnabled = model.notify;
|
isEnabled = StorageUtil().notify;
|
||||||
content = FFLocalizations.of(context).getVariableText(
|
content = FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'Ative para receber sua notificação de acesso',
|
ptText: 'Ative para receber sua notificação de acesso',
|
||||||
enText: 'Enable to receive your access notification',
|
enText: 'Enable to receive your access notification',
|
||||||
|
@ -130,7 +130,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
||||||
case 3:
|
case 3:
|
||||||
icon = Icons.lock;
|
icon = Icons.lock;
|
||||||
onPressed = () => model.toggleAccess(context);
|
onPressed = () => model.toggleAccess(context);
|
||||||
isEnabled = model.access;
|
isEnabled = StorageUtil().access;
|
||||||
content = FFLocalizations.of(context).getVariableText(
|
content = FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'Ative para inserir uma credencial de acesso para o QRCode',
|
ptText: 'Ative para inserir uma credencial de acesso para o QRCode',
|
||||||
enText: 'Enable to enter an access credential for the QRCode',
|
enText: 'Enable to enter an access credential for the QRCode',
|
||||||
|
@ -139,7 +139,7 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
||||||
case 4:
|
case 4:
|
||||||
icon = Icons.lock_clock_sharp;
|
icon = Icons.lock_clock_sharp;
|
||||||
onPressed = () => model.togglePanic(context);
|
onPressed = () => model.togglePanic(context);
|
||||||
isEnabled = model.panic;
|
isEnabled = StorageUtil().panic;
|
||||||
content = FFLocalizations.of(context).getVariableText(
|
content = FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'Ative para inserir uma credencial de pânico para o QRCode',
|
ptText: 'Ative para inserir uma credencial de pânico para o QRCode',
|
||||||
enText: 'Enable to enter a panic credential for the QRCode',
|
enText: 'Enable to enter a panic credential for the QRCode',
|
||||||
|
|
Loading…
Reference in New Issue