diff --git a/lib/app_state.dart b/lib/app_state.dart index 0b79b097..0faaaeca 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -43,13 +43,16 @@ class FFAppState extends ChangeNotifier { if (authenticated) { _isBiometricAuthenticated = true; notifyListeners(); + return Future.value(); // Salvar o estado de autenticação biométrica, se necessário } } catch (e) { print(e); debugPrint('Error authenticating: $e'); clearBiometricAuthentication(); + return Future.error(e); } + return Future.error(''); // Add this line to ensure a value is always returned } // Função para limpar o estado de autenticação biométrica @@ -145,6 +148,9 @@ class FFAppState extends ChangeNotifier { await _safeInitAsync(() async { _panicPass = await secureStorage.getString('panicPass') ?? _panicPass; }); + await _safeInitAsync(() async { + _fingerprintPass = await secureStorage.getString('fingerprintPass') ?? _fingerprintPass; + }); } @@ -155,6 +161,17 @@ class FFAppState extends ChangeNotifier { late FlutterSecureStorage secureStorage; + String _fingerprintPass = ''; + String get fingerprintPass => _fingerprintPass; + set fingerprintPass(String value) { + _fingerprintPass = value; + secureStorage.setString('fingerprintPass', value); + } + + void deleteFingerprintPass() { + secureStorage.delete(key: 'fingerprintPass'); + } + String _accessPass = ''; String get accessPass => _accessPass; set accessPass(String value) { diff --git a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart index 16bd3be8..5c19dfb3 100644 --- a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart +++ b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart @@ -125,8 +125,8 @@ class _PassKeyTemplateWidgetState padding: const EdgeInsetsDirectional.fromSTEB(16.0, 0.0, 0.0, 0.0), child: Text( FFLocalizations.of(context).getVariableText( - enText: FFAppState().accessPass != '' ? 'CHANGE PASSWORD' : 'INSERT PASSWORD', - ptText: FFAppState().accessPass != '' ? 'ALTERAR SENHA' : 'ADICIONAR SENHA', + enText: 'INSERT PASSWORD', + ptText: 'ADICIONAR SENHA', ), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Outfit', @@ -161,249 +161,134 @@ class _PassKeyTemplateWidgetState autovalidateMode: AutovalidateMode.always, child: Column( children: [ - if (FFAppState().accessPass.isNotEmpty) Padding( padding: const EdgeInsetsDirectional.fromSTEB(16.0, 12.0, 16.0, 0.0), child: SizedBox( width: double.infinity, child: TextFormField( - controller: _model.keyTextFieldTextController1, - - focusNode: _model.keyTextFieldFocusNode1, - onChanged: (_) => EasyDebounce.debounce( - '_model.keyTextFieldTextController', - const Duration(milliseconds: 2000), - () => setState(() {}), + controller: _model.keyTextFieldTextController1, + focusNode: _model.keyTextFieldFocusNode1, + onChanged: (_) => EasyDebounce.debounce( + '_model.keyTextFieldTextController', + const Duration(milliseconds: 2000), + () { + if (mounted) setState(() {}); + }, + ), + autofillHints: const [AutofillHints.password], + textCapitalization: TextCapitalization.none, + textInputAction: TextInputAction.done, + obscureText: !_model.keyTextFieldVisibility1, + decoration: InputDecoration( + isDense: true, + labelText: FFLocalizations.of(context).getVariableText( + ptText: 'Senha', + enText: 'Password', ), - autofillHints: const [AutofillHints.password], - textCapitalization: TextCapitalization.none, - textInputAction: TextInputAction.done, - obscureText: !_model.keyTextFieldVisibility1, - decoration: InputDecoration( - isDense: true, - labelText: FFLocalizations.of(context).getVariableText( - ptText: 'Senha Antiga', - enText: 'Old Password', - ), - labelStyle: - FlutterFlowTheme.of(context).labelMedium.override( - fontFamily: 'Plus Jakarta Sans', - color: FlutterFlowTheme.of(context).primary, - fontSize: 14.0, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap() - .containsKey('Plus Jakarta Sans'), - ), - hintText: FFLocalizations.of(context).getVariableText( - ptText: 'Digite a sua senha antiga.....', - enText: 'Enter your old password.....', - ), - hintStyle: - FlutterFlowTheme.of(context).labelMedium.override( - fontFamily: 'Plus Jakarta Sans', - color: FlutterFlowTheme.of(context).primaryText, - fontSize: 14.0, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap() - .containsKey('Plus Jakarta Sans'), - ), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).accent1, - width: 2.0, - ), - borderRadius: BorderRadius.circular(12.0), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).accent3, - width: 2.0, - ), - borderRadius: BorderRadius.circular(12.0), - ), - errorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).error, - width: 2.0, - ), - borderRadius: BorderRadius.circular(12.0), - ), - focusedErrorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).error, - width: 2.0, - ), - borderRadius: BorderRadius.circular(12.0), - ), - filled: true, - fillColor: FlutterFlowTheme.of(context).primaryBackground, - contentPadding: const EdgeInsetsDirectional.fromSTEB( - 24.0, 24.0, 20.0, 24.0), - suffixIcon: InkWell( - onTap: () => setState( - () => _model.keyTextFieldVisibility1 = - !_model.keyTextFieldVisibility1, - ), - focusNode: FocusNode(skipTraversal: true), - child: Icon( - _model.keyTextFieldVisibility1 - ? Icons.visibility_outlined - : Icons.visibility_off_outlined, - color: FlutterFlowTheme.of(context).accent1, - size: 22.0, - ), - ), + labelStyle: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: 'Plus Jakarta Sans', + color: FlutterFlowTheme.of(context).primary, + fontSize: 14.0, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap() + .containsKey('Plus Jakarta Sans'), ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: 'Plus Jakarta Sans', - color: FlutterFlowTheme.of(context).primaryText, - fontSize: 14.0, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap() - .containsKey('Plus Jakarta Sans'), - ), - maxLength: 4, - maxLengthEnforcement: MaxLengthEnforcement.none, - buildCounter: (context, - {required currentLength, - required isFocused, - maxLength}) => - null, - keyboardType: TextInputType.number, - cursorColor: FlutterFlowTheme.of(context).primary, - validator: _model.keyTextFieldTextControllerValidator1 - .asValidator(context), - inputFormatters: [ - FilteringTextInputFormatter.allow(RegExp('[0-9]')) - ], + hintText: FFLocalizations.of(context).getVariableText( + ptText: 'Digite a sua senha.....', + enText: 'Enter your password.....', + ), + hintStyle: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: 'Plus Jakarta Sans', + color: FlutterFlowTheme.of(context).primaryText, + fontSize: 14.0, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap() + .containsKey('Plus Jakarta Sans'), + ), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).accent1, + width: 2.0, + ), + borderRadius: BorderRadius.circular(12.0), + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).accent3, + width: 2.0, + ), + borderRadius: BorderRadius.circular(12.0), + ), + errorBorder: OutlineInputBorder( + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).error, + width: 2.0, + ), + borderRadius: BorderRadius.circular(12.0), + ), + focusedErrorBorder: OutlineInputBorder( + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).error, + width: 2.0, + ), + borderRadius: BorderRadius.circular(12.0), + ), + filled: true, + fillColor: + FlutterFlowTheme.of(context).primaryBackground, + contentPadding: + const EdgeInsetsDirectional.fromSTEB( + 24.0, 24.0, 20.0, 24.0), + suffixIcon: InkWell( + onTap: () => setState( + () => _model.keyTextFieldVisibility1 = + !_model.keyTextFieldVisibility1, + ), + focusNode: FocusNode(skipTraversal: true), + child: Icon( + _model.keyTextFieldVisibility1 + ? Icons.visibility_outlined + : Icons.visibility_off_outlined, + color: FlutterFlowTheme.of(context).accent1, + size: 22.0, + ), + ), + ), + style: FlutterFlowTheme.of(context).bodyMedium.override( + fontFamily: 'Plus Jakarta Sans', + color: FlutterFlowTheme.of(context).primaryText, + fontSize: 14.0, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap() + .containsKey('Plus Jakarta Sans'), + ), + maxLength: 4, + maxLengthEnforcement: MaxLengthEnforcement.enforced, + buildCounter: (context, + {required currentLength, + required isFocused, + maxLength}) => + null, + keyboardType: TextInputType.number, + cursorColor: FlutterFlowTheme.of(context).primary, + validator: _model.keyTextFieldTextControllerValidator1 + .asValidator(context), + inputFormatters: [ + FilteringTextInputFormatter.allow(RegExp('[0-9]')), + ], ), ), - ), - Padding( - padding: const EdgeInsetsDirectional.fromSTEB(16.0, 12.0, 16.0, 0.0), - child: SizedBox( - width: double.infinity, - child: TextFormField( - controller: _model.keyTextFieldTextController2, - - focusNode: _model.keyTextFieldFocusNode2, - onChanged: (_) => EasyDebounce.debounce( - '_model.keyTextFieldTextController', - const Duration(milliseconds: 2000), - () => setState(() {}), - ), - autofillHints: const [AutofillHints.password], - textCapitalization: TextCapitalization.none, - textInputAction: TextInputAction.done, - obscureText: !_model.keyTextFieldVisibility2, - decoration: InputDecoration( - isDense: true, - labelText: FFLocalizations.of(context).getVariableText( - ptText: FFAppState().accessPass != '' ? 'Nova Senha' : 'Senha', - enText: FFAppState().accessPass != '' ? 'New Password' : 'Password', - ), - labelStyle: - FlutterFlowTheme.of(context).labelMedium.override( - fontFamily: 'Plus Jakarta Sans', - color: FlutterFlowTheme.of(context).primary, - fontSize: 14.0, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap() - .containsKey('Plus Jakarta Sans'), - ), - hintText: FFLocalizations.of(context).getVariableText( - enText: FFAppState().accessPass != null ? 'Enter your new password.....' : 'Enter your password.....', - ptText: FFAppState().accessPass != null ? 'Digite a sua nova senha.....' : 'Digite a sua senha.....', - ), - hintStyle: - FlutterFlowTheme.of(context).labelMedium.override( - fontFamily: 'Plus Jakarta Sans', - color: FlutterFlowTheme.of(context).primaryText, - fontSize: 14.0, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap() - .containsKey('Plus Jakarta Sans'), - ), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).accent1, - width: 2.0, - ), - borderRadius: BorderRadius.circular(12.0), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).accent3, - width: 2.0, - ), - borderRadius: BorderRadius.circular(12.0), - ), - errorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).error, - width: 2.0, - ), - borderRadius: BorderRadius.circular(12.0), - ), - focusedErrorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).error, - width: 2.0, - ), - borderRadius: BorderRadius.circular(12.0), - ), - filled: true, - fillColor: FlutterFlowTheme.of(context).primaryBackground, - contentPadding: const EdgeInsetsDirectional.fromSTEB( - 24.0, 24.0, 20.0, 24.0), - suffixIcon: InkWell( - onTap: () => setState( - () => _model.keyTextFieldVisibility1 = - !_model.keyTextFieldVisibility1, - ), - focusNode: FocusNode(skipTraversal: true), - child: Icon( - _model.keyTextFieldVisibility1 - ? Icons.visibility_outlined - : Icons.visibility_off_outlined, - color: FlutterFlowTheme.of(context).accent1, - size: 22.0, - ), - ), - ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: 'Plus Jakarta Sans', - color: FlutterFlowTheme.of(context).primaryText, - fontSize: 14.0, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap() - .containsKey('Plus Jakarta Sans'), - ), - maxLength: 4, - maxLengthEnforcement: MaxLengthEnforcement.none, - buildCounter: (context, - {required currentLength, - required isFocused, - maxLength}) => - null, - keyboardType: TextInputType.number, - cursorColor: FlutterFlowTheme.of(context).primary, - validator: _model.keyTextFieldTextControllerValidator2 - .asValidator(context), - inputFormatters: [ - FilteringTextInputFormatter.allow(RegExp('[0-9]')) - ], - ), ), - ), ], ), + ), Align( alignment: const AlignmentDirectional(0.0, 0.0), @@ -418,7 +303,7 @@ class _PassKeyTemplateWidgetState await widget.toggleActionStatus?.call( _model.keyTextFieldTextController1.text.isEmpty ? _model.keyTextFieldTextController2.text : _model.keyTextFieldTextController1.text, ); - Navigator.pop(context); + Navigator.pop(context, true); }, text: FFLocalizations.of(context).getVariableText( ptText: FFAppState().accessPass != '' ? 'Alterar' : 'Adicionar', diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 164d8677..bc06c770 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -1,21 +1,52 @@ +import 'dart:developer'; + import 'package:f_r_e_hub/backend/api_requests/api_calls.dart'; import 'package:f_r_e_hub/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart'; import 'package:f_r_e_hub/flutter_flow/flutter_flow_theme.dart'; import 'package:f_r_e_hub/flutter_flow/flutter_flow_util.dart'; import 'package:flutter/material.dart'; -import 'package:local_auth/local_auth.dart'; class PreferencesPageModel with ChangeNotifier { final unfocusNode = FocusNode(); - final LocalAuthentication auth = LocalAuthentication(); + Future toggleFingerprint(BuildContext context) async { - Future toggleFingerprint() async { - - FFAppState().checkBiometrics().then((value) => FFAppState().authenticateBiometric().then( (value) => FFAppState().fingerprint = !FFAppState().fingerprint).whenComplete(() => notifyListeners())); + // FFAppState().checkBiometrics() + // .then((value) => FFAppState().authenticateBiometric() + // .then( (value) { + // FFAppState().fingerprint = !FFAppState().fingerprint; + + // }) + // .whenComplete(() => notifyListeners())); + if(FFAppState().fingerprint) { + FFAppState().fingerprint = false; + FFAppState().deleteFingerprintPass(); + notifyListeners(); + } else { + await showModalBottomSheet( + isScrollControlled: true, + backgroundColor: Colors.transparent, + useSafeArea: true, + context: context, + builder: (context) { + return Padding( + padding: + MediaQuery.viewInsetsOf(context), + child: + PassKeyTemplateWidget( + toggleActionStatus: (key) async { + log(key); + FFAppState().fingerprintPass = key; + FFAppState().fingerprint = true; + }, + ), + ); + }, + ).whenComplete(() => notifyListeners()); + } } @@ -74,8 +105,12 @@ class PreferencesPageModel with ChangeNotifier { Future togglePass(BuildContext context) async { - FFAppState().pass = true; - notifyListeners(); + debugPrint('pass: ${FFAppState().pass}'); + if(FFAppState().pass) { + FFAppState().pass = false; + FFAppState().deleteAccessPass(); + notifyListeners(); + } else { await showModalBottomSheet( isScrollControlled: true, backgroundColor: Colors.transparent, @@ -91,20 +126,35 @@ class PreferencesPageModel with ChangeNotifier { FFAppState().accessPass = key; notifyListeners(); debugPrint('key: $key'); - // PhpGroup.changePass.call( - // userUUID: FFAppState().userUUID, - // devUUID: FFAppState().devUUID, - // cliID: FFAppState().cliUUID, - // atividade: 'updVisitado', - // newSenha: FFAppState().accessPass, - // ); + await PhpGroup.changePass.call( + userUUID: FFAppState().userUUID, + devUUID: FFAppState().devUUID, + cliID: FFAppState().cliUUID, + atividade: 'updVisitado', + newSenha: FFAppState().accessPass, + ) + .then((value) { + FFAppState().pass = true; + var error = jsonDecode(value.jsonBody['error'].toString()); + log('${jsonDecode(value.jsonBody['error'].toString())}'); + if(jsonDecode(value.jsonBody['error'].toString()) == false) { + FFAppState().pass = true; + } else { + FFAppState().pass = false; + } + }) + .onError((error, StackTrace) { + FFAppState().pass = false; + log(error.toString()); + log(StackTrace.toString()); + }) + .whenComplete(() => notifyListeners()); }, ), ); }, ); - FFAppState().pass = false; - notifyListeners(); + } } @override diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index c8955d1a..9e803f27 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -94,7 +94,7 @@ class PreferencesPageWidget extends StatelessWidget { switch (index) { case 0: icon = Icons.fingerprint; - onPressed = model.toggleFingerprint; // Desabilita se fingerprint for false + onPressed = () => model.toggleFingerprint(context); // Desabilita se fingerprint for false isEnabled = FFAppState().fingerprint; break; case 1: diff --git a/lib/pages/qr_code_page/qr_code_page_model.dart b/lib/pages/qr_code_page/qr_code_page_model.dart index 1c96dd84..7770c77e 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -8,7 +8,7 @@ class QrCodePageModel extends FlutterFlowModel { bool isAccess = false; - String? key; + String? key = null; DateTime? time; diff --git a/lib/pages/qr_code_page/qr_code_page_widget.dart b/lib/pages/qr_code_page/qr_code_page_widget.dart index 64e110ba..b165965a 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -125,7 +125,7 @@ void dispose() { mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - if (_model.isAccess == true) + if (_model.isAccess == true && _model.key != null) Text( FFLocalizations.of(context).getVariableText( ptText: 'Use esse QR Code para acesso', @@ -143,7 +143,7 @@ void dispose() { ), Stack( children: [ - if (_model.isAccess == true) + if (_model.isAccess == true && _model.key != null) Align( alignment: const AlignmentDirectional(0.0, 0.0), child: InkWell( @@ -161,7 +161,7 @@ void dispose() { ), ), ), - if(_model.isAccess == false) + if(_model.isAccess == false && _model.key == null) Align( alignment: const AlignmentDirectional(0, 0), child: BarcodeWidget( @@ -180,7 +180,7 @@ void dispose() { animationsMap['barcodeOnActionTriggerAnimation']!, ), ), - if (_model.isAccess == false) + if (_model.isAccess == false && _model.key == null) Align( alignment: const AlignmentDirectional(0.0, 0.0), child: InkWell( @@ -203,8 +203,10 @@ void dispose() { alignment: const AlignmentDirectional(0.0, 0.0), child: FFButtonWidget( onPressed: () async { - await _showQrCodeBottomSheet(context); - _toggleQrCodeAccess(); + await _showQrCodeBottomSheet(context).then((value) => _toggleQrCodeAccess()).onError((error, stackTrace) => safeSetState((){ + _resetAnimationAndToggleAccess(); + })); + }, text: FFLocalizations.of(context).getVariableText( ptText: 'Gerar QR Code', @@ -243,7 +245,7 @@ void dispose() { ), ], ), - if (_model.isAccess == true) + if (_model.isAccess == true && _model.key != null) Container( width: 300.0, decoration: const BoxDecoration(), @@ -265,7 +267,7 @@ void dispose() { ), ), ), - if (_model.isAccess == true) + if (_model.isAccess == true && _model.key != null) Container( width: 250.0, height: 80.0, @@ -367,7 +369,11 @@ void dispose() { } Future _showQrCodeBottomSheet(BuildContext context) async { - await showModalBottomSheet( + if(FFAppState().fingerprint) { + FFAppState().checkBiometrics().then((value) => FFAppState().authenticateBiometric().then( (value) => safeSetState(() {_model.key = FFAppState().accessPass;}) )).catchError((error) => safeSetState((){_resetAnimationAndToggleAccess();})); + + } else { + await showModalBottomSheet( isScrollControlled: true, backgroundColor: Colors.transparent, useSafeArea: true, @@ -393,6 +399,9 @@ void dispose() { ); }, ).then((value) => safeSetState(() {})); + }; + + unawaited( () async { @@ -412,6 +421,7 @@ void dispose() { animationsMap['barcodeOnActionTriggerAnimation']!.controller.forward(); // Alterna o estado de acesso _model.isAccess = !_model.isAccess; + _model.key = null; }); }