This commit is contained in:
J. A. Messias 2024-11-05 09:45:57 -03:00
parent 25c316ef79
commit 2d88a0b355
4 changed files with 47 additions and 51 deletions

View File

@ -56,9 +56,10 @@ class PreferencesPageModel with ChangeNotifier {
enText: 'Are you sure you want to change your notification?', enText: 'Are you sure you want to change your notification?',
ptText: 'Tem certeza que deseja alterar sua notificação?', ptText: 'Tem certeza que deseja alterar sua notificação?',
); );
onConfirm() async { onConfirm() async {
String content; String content;
isNotify = await StorageHelper.instance.get(SQLiteStorageKey.notify.value, Storage.SQLiteStorage) == 'true';
String value = !isNotify ? 'N' : 'S'; String value = !isNotify ? 'N' : 'S';
await PhpGroup.changeNotifica.call(notifica: value).then((value) async { await PhpGroup.changeNotifica.call(notifica: value).then((value) async {
if (value.jsonBody['error'] == false) { if (value.jsonBody['error'] == false) {
@ -83,7 +84,9 @@ class PreferencesPageModel with ChangeNotifier {
ptText: 'Erro ao alterar notificação', ptText: 'Erro ao alterar notificação',
); );
SnackBarUtil.showSnackBar(context, content, isError: true); SnackBarUtil.showSnackBar(context, content, isError: true);
}).whenComplete(() => notifyListeners()); })
.then((_) async => isNotify = await StorageHelper.instance.get(SQLiteStorageKey.notify.value, Storage.SQLiteStorage) == 'true')
.whenComplete(() => notifyListeners());
context.pop(); context.pop();
} }
@ -93,8 +96,6 @@ class PreferencesPageModel with ChangeNotifier {
Future<void> toggleAccess(BuildContext context) async { Future<void> toggleAccess(BuildContext context) async {
onChange(String key) async { onChange(String key) async {
await StorageHelper.instance.set(SecureStorageKey.accessPass.value, key, Storage.SecureStorage); await StorageHelper.instance.set(SecureStorageKey.accessPass.value, key, Storage.SecureStorage);
isAccess = await StorageHelper.instance.get(SQLiteStorageKey.access.value, Storage.SQLiteStorage) == 'true';
await PhpGroup.changePass.call(newSenha: key).then((value) async { await PhpGroup.changePass.call(newSenha: key).then((value) async {
final String content; final String content;
if (jsonDecode(value.jsonBody['error'].toString()) == false) { if (jsonDecode(value.jsonBody['error'].toString()) == false) {
@ -118,7 +119,9 @@ class PreferencesPageModel with ChangeNotifier {
enText: 'Error changing access pass', enText: 'Error changing access pass',
); );
SnackBarUtil.showSnackBar(context, content, isError: true); SnackBarUtil.showSnackBar(context, content, isError: true);
}).whenComplete(() => notifyListeners()); })
.then((_) async => isAccess = await StorageHelper.instance.get(SQLiteStorageKey.access.value, Storage.SQLiteStorage) == 'true')
.whenComplete(() => notifyListeners());
} }
_showPassKey(context, onChange); _showPassKey(context, onChange);
@ -127,7 +130,6 @@ class PreferencesPageModel with ChangeNotifier {
Future<void> togglePanic(BuildContext context) async { Future<void> togglePanic(BuildContext context) async {
onChange(String key) async { onChange(String key) async {
await StorageHelper.instance.set(SecureStorageKey.panicPass.value, key, Storage.SecureStorage); await StorageHelper.instance.set(SecureStorageKey.panicPass.value, key, Storage.SecureStorage);
isPanic = await StorageHelper.instance.get(SQLiteStorageKey.panic.value, Storage.SQLiteStorage) == 'true';
await PhpGroup.changePanic await PhpGroup.changePanic
.call(newSenhaPanico: key) .call(newSenhaPanico: key)
.then((value) async { .then((value) async {
@ -153,7 +155,9 @@ class PreferencesPageModel with ChangeNotifier {
enText: 'Error changing panic password', enText: 'Error changing panic password',
); );
SnackBarUtil.showSnackBar(context, content, isError: true); SnackBarUtil.showSnackBar(context, content, isError: true);
}).whenComplete(() => notifyListeners()); })
.then((_) async => isPanic = await StorageHelper.instance.get(SQLiteStorageKey.panic.value, Storage.SQLiteStorage) == 'true')
.whenComplete(() => notifyListeners());
} }
_showPassKey(context, onChange); _showPassKey(context, onChange);
@ -165,7 +169,6 @@ class PreferencesPageModel with ChangeNotifier {
ptText: 'Impressão digital alterada com sucesso', ptText: 'Impressão digital alterada com sucesso',
); );
isFingerprint = await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true';
onChange(String? key) async { onChange(String? key) async {
isFingerprint = !isFingerprint; isFingerprint = !isFingerprint;
@ -173,6 +176,8 @@ class PreferencesPageModel with ChangeNotifier {
await StorageHelper.instance.set(SQLiteStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false', Storage.SQLiteStorage); await StorageHelper.instance.set(SQLiteStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false', Storage.SQLiteStorage);
notifyListeners(); notifyListeners();
SnackBarUtil.showSnackBar(context, content); SnackBarUtil.showSnackBar(context, content);
isFingerprint = await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true';
} }
isFingerprint ? onChange(null) : _showPassKey(context, onChange); isFingerprint ? onChange(null) : _showPassKey(context, onChange);
@ -244,4 +249,7 @@ class PreferencesPageModel with ChangeNotifier {
SnackBarUtil.showSnackBar(context, content, isError: true); SnackBarUtil.showSnackBar(context, content, isError: true);
}).whenComplete(() => notifyListeners()); }).whenComplete(() => notifyListeners());
} }
} }

View File

@ -1,4 +1,3 @@
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
@ -7,8 +6,7 @@ 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/pages/preferences_settings_page/preferences_settings_model.dart'; import 'package:hub/pages/preferences_settings_page/preferences_settings_model.dart';
import 'package:hub/shared/helpers/base_storage.dart';
import 'package:hub/shared/helpers/storage_helper.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class PreferencesPageWidget extends StatefulWidget { class PreferencesPageWidget extends StatefulWidget {

View File

@ -11,13 +11,15 @@ import 'package:qr_flutter/qr_flutter.dart';
class QrCodePageModel extends FlutterFlowModel<QrCodePageWidget> { class QrCodePageModel extends FlutterFlowModel<QrCodePageWidget> {
/// Local state fields for this page. /// Local state fields for this page.
bool isAccess = false;
String? key; String? key;
DateTime? time; DateTime? time;
bool isAccess = false;
late final bool isFingerprint; late final bool isFingerprint;
late final String userDevUUID; late final String userDevUUID;
late final VoidCallback? safeSetState;
/// State fields for stateful widgets in this page. /// State fields for stateful widgets in this page.
@ -30,7 +32,8 @@ class QrCodePageModel extends FlutterFlowModel<QrCodePageWidget> {
Future<void> initVariable() async { Future<void> initVariable() async {
isFingerprint = await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; isFingerprint = await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true';
userDevUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage)) ?? ''; userDevUUID = await StorageHelper.instance.get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage) ?? '';
safeSetState?.call();
} }
@override @override

View File

@ -1,4 +1,7 @@
// ignore_for_file: use_build_context_synchronously
import 'dart:async'; import 'dart:async';
import 'dart:developer';
import 'package:barcode_widget/barcode_widget.dart'; import 'package:barcode_widget/barcode_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -40,8 +43,8 @@ class _QrCodePageWidgetState extends State<QrCodePageWidget> with TickerProvider
void initState() { void initState() {
super.initState(); super.initState();
_model = createModel(context, () => QrCodePageModel()); _model = createModel(context, () => QrCodePageModel());
_model.safeSetState = () => safeSetState(() {});
// On page load action.
SchedulerBinding.instance.addPostFrameCallback((_) async { SchedulerBinding.instance.addPostFrameCallback((_) async {
if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) {
animationsMap['barcodeOnActionTriggerAnimation']!.controller.fling(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.fling();
@ -69,13 +72,6 @@ class _QrCodePageWidgetState extends State<QrCodePageWidget> with TickerProvider
this, this,
); );
// // Adicionando um ouvinte de status à animação para reiniciá-la após a conclusão
// animationsMap['barcodeOnActionTriggerAnimation']?.controller.addStatusListener((status) {
// if (status == AnimationStatus.completed) {
// animationsMap['barcodeOnActionTriggerAnimation']!.controller.reset();
// animationsMap['barcodeOnActionTriggerAnimation']!.controller.forward();
// }
// });
} }
@override @override
@ -131,10 +127,8 @@ class _QrCodePageWidgetState extends State<QrCodePageWidget> with TickerProvider
alignment: const AlignmentDirectional(0.0, 0.0), alignment: const AlignmentDirectional(0.0, 0.0),
child: InkWell( child: InkWell(
onTap: () async { onTap: () async {
safeSetState(() async {
_resetAnimationAndToggleAccess(); _resetAnimationAndToggleAccess();
}); log('isFingerprint: ${_model.isFingerprint}');
_model.isFingerprint ? await _showBiometricsAuth(context) : await _showQrCodeBottomSheet(context); _model.isFingerprint ? await _showBiometricsAuth(context) : await _showQrCodeBottomSheet(context);
}, },
child: _model.buildQrCode( child: _model.buildQrCode(
@ -188,6 +182,7 @@ class _QrCodePageWidgetState extends State<QrCodePageWidget> with TickerProvider
alignment: const AlignmentDirectional(0.0, 0.0), alignment: const AlignmentDirectional(0.0, 0.0),
child: FFButtonWidget( child: FFButtonWidget(
onPressed: () async { onPressed: () async {
log('isFingerprint: ${_model.isFingerprint}');
_model.isFingerprint _model.isFingerprint
? await _showBiometricsAuth(context) ? await _showBiometricsAuth(context)
: await _showQrCodeBottomSheet(context); : await _showQrCodeBottomSheet(context);
@ -262,7 +257,6 @@ class _QrCodePageWidgetState extends State<QrCodePageWidget> with TickerProvider
FFLocalizations.of(context).getVariableText( FFLocalizations.of(context).getVariableText(
ptText: 'Expirando QR code em', ptText: 'Expirando QR code em',
enText: 'Expiring QR code in', enText: 'Expiring QR code in',
// 'wkjkxd2e' /* Trocando QR code em */,
), ),
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: FlutterFlowTheme.of(context).bodyMedium.override( style: FlutterFlowTheme.of(context).bodyMedium.override(
@ -329,20 +323,22 @@ class _QrCodePageWidgetState extends State<QrCodePageWidget> with TickerProvider
} }
Future<void> _showBiometricsAuth(BuildContext context) async { Future<void> _showBiometricsAuth(BuildContext context) async {
BiometricHelper.checkBiometrics() await BiometricHelper.checkBiometrics()
.then((value) => BiometricHelper.authenticateBiometric().then((value) { .then((value) async => await BiometricHelper.authenticateBiometric().then((value) async {
safeSetState(() async { final key = await StorageHelper.instance.get(SecureStorageKey.fingerprintPass.value, Storage.SecureStorage) ?? '';
if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { safeSetState(() {
animationsMap['barcodeOnActionTriggerAnimation']!.controller.stop(); if (animationsMap['barcodeOnActionTriggerAnimation'] != null) {
animationsMap['barcodeOnActionTriggerAnimation']!.controller.reverse(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.stop();
} animationsMap['barcodeOnActionTriggerAnimation']!.controller.reverse();
_model.isAccess = !_model.isAccess; }
_model.key = (await StorageHelper.instance.get(SecureStorageKey.fingerprintPass.value, Storage.SecureStorage)) ?? ''; _model.isAccess = !_model.isAccess;
}); _model.key = key;
});
})) }))
.onError((error, StackTrace) { .onError((error, stackTrace) {
_showQrCodeBottomSheet(context); log('Error', error: error, stackTrace: stackTrace);
}); if (mounted) _showQrCodeBottomSheet(context);
});
} }
Future<void> _showQrCodeBottomSheet(BuildContext context) async { Future<void> _showQrCodeBottomSheet(BuildContext context) async {
@ -373,26 +369,19 @@ class _QrCodePageWidgetState extends State<QrCodePageWidget> with TickerProvider
), ),
); );
}, },
).catchError((error) => safeSetState(() { ).catchError((error) => safeSetState(() => _resetAnimationAndToggleAccess()));
_resetAnimationAndToggleAccess();
}));
unawaited( unawaited(
() async { () async {
await _model.qrCodeEncoder( await _model.qrCodeEncoder(context, key: _model.key);
context, safeSetState(() {});
key: _model.key,
);
setState(() {});
}(), }(),
); );
} }
void _resetAnimationAndToggleAccess() { void _resetAnimationAndToggleAccess() {
safeSetState(() { safeSetState(() {
// Reinicia a animação
animationsMap['barcodeOnActionTriggerAnimation']!.controller.reset(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.reset();
animationsMap['barcodeOnActionTriggerAnimation']!.controller.forward(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.forward();
// Alterna o estado de acesso
_model.isAccess = !_model.isAccess; _model.isAccess = !_model.isAccess;
_model.key = null; _model.key = null;
}); });
@ -417,9 +406,7 @@ class _QrCodePageWidgetState extends State<QrCodePageWidget> with TickerProvider
}, },
), ),
title: Text( title: Text(
FFLocalizations.of(context).getText( FFLocalizations.of(context).getText('ku7jqe53'),
'ku7jqe53' /* QR Code de Acesso */,
),
style: FlutterFlowTheme.of(context).headlineMedium.override( style: FlutterFlowTheme.of(context).headlineMedium.override(
fontFamily: FlutterFlowTheme.of(context).headlineMediumFamily, fontFamily: FlutterFlowTheme.of(context).headlineMediumFamily,
color: FlutterFlowTheme.of(context).primaryText, color: FlutterFlowTheme.of(context).primaryText,