From 580be6d71385d912fb98a96df8023d405bc90d80 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 13 Sep 2024 14:31:37 -0300 Subject: [PATCH 1/5] fix not in ios --- ios/Runner/AppDelegate.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index e15ab6cf..5dbf2dbf 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -1,6 +1,6 @@ import UIKit - import Flutter +import flutter_secure_storage @main @objc class AppDelegate: FlutterAppDelegate { @@ -9,6 +9,11 @@ import Flutter didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { 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) } -} +} \ No newline at end of file From 999215fe5eb52561780745bfd85e788cd8df0776 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 17 Sep 2024 13:53:43 -0300 Subject: [PATCH 2/5] WIP --- lib/backend/api_requests/api_calls.dart | 8 +- .../card_item_template_component_widget.dart | 10 +- .../details_component_widget.dart | 2 +- lib/pages/pets_page/pets_page_model.dart | 113 ++++++++++-------- 4 files changed, 78 insertions(+), 55 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index ce44250f..e636ccc0 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -157,11 +157,13 @@ class UpdatePet { 'name': name, 'species': species, 'breed': breed, - 'color': color, - 'birthdayDate': ValidatorUtil.toISO8601USA('dd/MM/yyyy', birthdayDate!), + if (color != '') 'color': color, + if (birthdayDate != '') + 'birthdayDate': + ValidatorUtil.toISO8601USA('dd/MM/yyyy', birthdayDate!), 'gender': gender, 'size': size, - 'notes': notes, + if (notes != '') 'notes': notes, }, bodyType: BodyType.X_WWW_FORM_URL_ENCODED, returnBody: true, diff --git a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart index fb19fd44..7dfc1d7f 100644 --- a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart +++ b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart @@ -98,13 +98,21 @@ class _CardItemTemplateComponentWidgetState } Widget _generateImage() { - CachedNetworkImage.evictFromCache(widget.imagePath ?? ''); + // CachedNetworkImage.evictFromCache(widget.imagePath ?? ''); return ClipRRect( borderRadius: BorderRadius.circular(20), child: CachedNetworkImage( fadeInDuration: const Duration(milliseconds: 500), fadeOutDuration: const Duration(milliseconds: 500), imageUrl: widget.imagePath ?? '', + placeholder: (context, url) => const Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + Color(0xFF1AAB5F), + ), + ), + ), + errorWidget: (context, url, error) => const Icon(Icons.error), fit: BoxFit.cover, width: 90, height: 90, diff --git a/lib/components/templates_components/details_component/details_component_widget.dart b/lib/components/templates_components/details_component/details_component_widget.dart index 6aefc08a..48bf6691 100644 --- a/lib/components/templates_components/details_component/details_component_widget.dart +++ b/lib/components/templates_components/details_component/details_component_widget.dart @@ -65,7 +65,7 @@ class _DetailsComponentWidgetState extends State { @override Widget build(BuildContext context) { context.watch(); - CachedNetworkImage.evictFromCache(widget.imagePath ?? ''); + // CachedNetworkImage.evictFromCache(widget.imagePath ?? ''); return Container( constraints: BoxConstraints( diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index 11963e0e..adbb487a 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -1,4 +1,5 @@ import 'dart:developer'; +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; @@ -184,15 +185,17 @@ class PetsPageModel extends FlutterFlowModel { } Future updatePet() async { - var img = await actions.convertImageFileToBase64(uploadedLocalFile!); - img = "base64;jpeg,$img"; - await PhpGroup.updatePet - .call( + final img = await actions.convertImageFileToBase64(uploadedLocalFile!); + final imgBase64 = "base64;jpeg,$img"; + final url = + 'https://freaccess.com.br/freaccess/getImage.php?devUUID=${AppState().devUUID}&userUUID=${AppState().userUUID}&cliID=${AppState().cliUUID}&atividade=consultaFotoPet&petId=$petId'; + + final response = await PhpGroup.updatePet.call( cliID: AppState().cliUUID, devUUID: AppState().devUUID, userUUID: AppState().userUUID, petID: petId, - image: img, + image: imgBase64, birthdayDate: textControllerData!.text, color: textControllerColor!.text, breed: textControllerRace!.text, @@ -201,33 +204,44 @@ class PetsPageModel extends FlutterFlowModel { gender: dropDownValue1!, notes: textControllerObservation!.text, size: dropDownValue2!, - ) - .then((response) { - if (response.jsonBody['error'] == true || - isFormValid(buildContext!) == false) { - DialogUtil.error(buildContext!, - jsonDecode(response.jsonBody['error_msg'])[0]['message']); - } + ); + + if (response.jsonBody['error'] == false) { DialogUtil.success( - buildContext!, - FFLocalizations.of(buildContext!).getVariableText( - enText: 'Pet successfully updated', - ptText: 'Pet atualizado com sucesso', - )); + buildContext!, + FFLocalizations.of(buildContext!).getVariableText( + enText: 'Pet successfully updated', + ptText: 'Pet atualizado com sucesso', + ), + ); + + CachedNetworkImage.evictFromCache(url); onUpdatePet?.call(); switchTab(1); - }); + } else { + String errorMessage; + try { + errorMessage = + jsonDecode(response.jsonBody['error_msg'])[0]['message'].toString(); + } catch (e) { + errorMessage = FFLocalizations.of(buildContext!).getVariableText( + enText: 'Failed to update pet', + ptText: 'Falha ao atualizar o pet', + ); + } + DialogUtil.error(buildContext!, errorMessage); + } } Future registerPet() async { - var img = await actions.convertImageFileToBase64(uploadedLocalFile!); - img = "base64;jpeg,$img"; - await PhpGroup.registerPet - .call( + final img = await actions.convertImageFileToBase64(uploadedLocalFile!); + final imgBase64 = "base64;jpeg,$img"; + + final response = await PhpGroup.registerPet.call( cliID: AppState().cliUUID, devUUID: AppState().devUUID, userUUID: AppState().userUUID, - image: img, + image: imgBase64, birthdayDate: textControllerData!.text, color: textControllerColor!.text, breed: textControllerRace!.text, @@ -236,35 +250,34 @@ class PetsPageModel extends FlutterFlowModel { gender: dropDownValue1!, size: dropDownValue2!, notes: textControllerObservation!.text, - ) - .then((response) { - if (response.jsonBody['error'] == true) { - String errorMessage = ''; - try { - errorMessage = jsonDecode(response.jsonBody['error_msg'])[0] - ['message'] - .toString(); - } catch (e) { - errorMessage = 'An error occurred.'; - if (response.jsonBody['error_msg'] == - "Limite de Cadastro de Pet Atingido.") { - errorMessage = FFLocalizations.of(buildContext!).getVariableText( - enText: 'Pet registration limit reached', - ptText: 'Limite de cadastro de pets atingido', - ); - } + ); + + if (response.jsonBody['error'] == false) { + DialogUtil.success( + buildContext!, + FFLocalizations.of(buildContext!).getVariableText( + enText: 'Pet successfully registered', + ptText: 'Pet cadastrado com sucesso', + ), + ); + onRegisterPet?.call(); + } else { + String errorMessage; + try { + errorMessage = + jsonDecode(response.jsonBody['error_msg'])[0]['message'].toString(); + } catch (e) { + if (response.jsonBody['error_msg'] == + "Limite de Cadastro de Pet Atingido.") { + errorMessage = FFLocalizations.of(buildContext!).getVariableText( + enText: 'Pet registration limit reached', + ptText: 'Limite de cadastro de pets atingido', + ); + } else { + DialogUtil.errorDefault(buildContext!); } - DialogUtil.error(buildContext!, errorMessage); - } else if (response.jsonBody['error'] == false) { - DialogUtil.success( - buildContext!, - FFLocalizations.of(buildContext!).getVariableText( - enText: 'Pet successfully registered', - ptText: 'Pet cadastrado com sucesso', - )); - onRegisterPet?.call(); } - }); + } } void switchTab(int index) { From ed1f6b22e9ded50138a5ef7464ff45a88f86a617 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 17 Sep 2024 13:55:13 -0300 Subject: [PATCH 3/5] WIP --- .../shared_components_atoms/submit_button.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/atomic_components/shared_components_atoms/submit_button.dart b/lib/components/atomic_components/shared_components_atoms/submit_button.dart index c970dca3..1ca6c5d2 100644 --- a/lib/components/atomic_components/shared_components_atoms/submit_button.dart +++ b/lib/components/atomic_components/shared_components_atoms/submit_button.dart @@ -23,7 +23,7 @@ class SubmitButtonUtil extends StatelessWidget { width: 250.0, height: 36.0, disabledColor: FlutterFlowTheme.of(context).customColor5, - padding: const EdgeInsetsDirectional.fromSTEB(80.0, 0.0, 80.0, 0.0), + padding: const EdgeInsetsDirectional.fromSTEB(0.0, 0.0, 0.0, 0.0), iconPadding: const EdgeInsetsDirectional.fromSTEB(0.0, 0.0, 0.0, 0.0), color: FlutterFlowTheme.of(context).primary, textStyle: FlutterFlowTheme.of(context).titleSmall.override( From 48e8a1a5cb7ac0839049e95eb1067dc53cef2ee8 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 17 Sep 2024 14:42:48 -0300 Subject: [PATCH 4/5] WIP --- lib/app_state.dart | 26 ++++++++++++++++++++++++++ lib/main.dart | 2 ++ 2 files changed, 28 insertions(+) diff --git a/lib/app_state.dart b/lib/app_state.dart index 49aef2fb..27078ab5 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -4,6 +4,7 @@ import 'package:csv/csv.dart'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:local_auth/local_auth.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'package:synchronized/synchronized.dart'; class AppState extends ChangeNotifier { @@ -71,6 +72,7 @@ class AppState extends ChangeNotifier { Future initializePersistedState() async { secureStorage = const FlutterSecureStorage(); + await _safeInitAsync(() async { _cliUUID = await secureStorage.getString('ff_cliUUID') ?? _cliUUID; }); @@ -177,6 +179,7 @@ class AppState extends ChangeNotifier { await secureStorage.getBool('ff_request_os_notification') ?? _isRequestOSNotification; }); + await loadFirstRun(); } void update(VoidCallback callback) { @@ -186,6 +189,29 @@ class AppState extends ChangeNotifier { late FlutterSecureStorage secureStorage; + bool _firstRun = true; + bool get firstRun => _firstRun; + + Future loadFirstRun() async { + final prefs = await SharedPreferences.getInstance(); + _firstRun = prefs.getBool('first_run') ?? true; + notifyListeners(); + } + + Future setFirstRun(bool value) async { + final prefs = await SharedPreferences.getInstance(); + _firstRun = value; + await prefs.setBool('first_run', value); + notifyListeners(); + } + + Future deleteFirstRun() async { + final prefs = await SharedPreferences.getInstance(); + _firstRun = true; + await prefs.remove('first_run'); + notifyListeners(); + } + int _petAmountRegister = 0; int get petAmountRegister => _petAmountRegister; set petAmountRegister(int value) { diff --git a/lib/main.dart b/lib/main.dart index 73e07a1c..94242383 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -28,6 +28,8 @@ Future initializeApp() async { final appState = AppState(); await appState.initializePersistedState(); + if (AppState().firstRun == true) AppState().setFirstRun(false); + await Firebase.initializeApp(); await NotificationService.initialize(); From 26e56d07d325b6ccb8d0da9668099406b8cb1699 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 17 Sep 2024 15:09:01 -0300 Subject: [PATCH 5/5] WIP --- lib/app_state.dart | 4 ++++ lib/main.dart | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/app_state.dart b/lib/app_state.dart index 27078ab5..64237884 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -612,7 +612,11 @@ class AppState extends ChangeNotifier { AppState().deleteRemoteId(); AppState().deleteSerialNumber(); secureStorage.deleteAll(); + AppState().isLogged = false; + AppState().setFirstRun(false); + + AppState().update(() {}); } } diff --git a/lib/main.dart b/lib/main.dart index 94242383..ee055ff2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -28,7 +28,9 @@ Future initializeApp() async { final appState = AppState(); await appState.initializePersistedState(); - if (AppState().firstRun == true) AppState().setFirstRun(false); + if (AppState().firstRun == true) { + AppState().deleteAll(); + } await Firebase.initializeApp(); await NotificationService.initialize();