diff --git a/lib/components/atomic_components/shared_components_atoms/custom_input.dart b/lib/components/atomic_components/shared_components_atoms/custom_input.dart index d7b724d6..608f60af 100644 --- a/lib/components/atomic_components/shared_components_atoms/custom_input.dart +++ b/lib/components/atomic_components/shared_components_atoms/custom_input.dart @@ -60,11 +60,16 @@ class _CustomInputUtilState extends State { validator: widget.validator, autofocus: widget.autoFocus, focusNode: widget.focusNode, - onChanged: (_) => EasyDebounce.debounce( - '${widget.controller}', - const Duration(milliseconds: 500), - () => setState(() {}), - ), + onChanged: (value) { + EasyDebounce.debounce( + '${widget.controller}', + const Duration(milliseconds: 500), + () => setState(() {}), + ); + if (widget.onChanged != null) { + widget.onChanged!(value); // Chamar o callback + } + }, textInputAction: widget.textInputAction, obscureText: false, decoration: InputDecoration( diff --git a/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart b/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart index 719d4efb..7946e9b7 100644 --- a/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart +++ b/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart @@ -14,13 +14,13 @@ class MediaUploadButtonUtil extends StatefulWidget { final String labelText; FFUploadedFile? uploadedFiles; - MediaUploadButtonUtil( - {Key? key, - required this.onUploadComplete, - required this.isUploading, - required this.labelText, - this.uploadedFiles}) - : super(key: key); + MediaUploadButtonUtil({ + Key? key, + required this.onUploadComplete, + required this.isUploading, + required this.labelText, + this.uploadedFiles, + }) : super(key: key); @override State createState() => _MediaUploadButtonUtilState(); diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index 1a14c55b..42728b0e 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -47,7 +47,6 @@ class _HomePageWidgetState extends State { final errorMsg = response.jsonBody['error_msg']; if (error == false) { - log(response.jsonBody.toString()); AppState().whatsapp = response.jsonBody['whatsapp'] ?? false; AppState().provisional = response.jsonBody['provisional'] ?? false; AppState().pets = response.jsonBody['pet'] ?? false; diff --git a/lib/pages/pets_page/pets_history_screen.dart b/lib/pages/pets_page/pets_history_screen.dart index 5697f6b2..53660722 100644 --- a/lib/pages/pets_page/pets_history_screen.dart +++ b/lib/pages/pets_page/pets_history_screen.dart @@ -24,6 +24,7 @@ class _PetsHistoryScreenState extends State final int _pageSize = 10; bool _hasData = false; bool _loading = false; + int count = 0; late Future _petsFuture; List _petsWrap = []; @@ -61,7 +62,8 @@ class _PetsHistoryScreenState extends State page: _pageNumber, ); - final List pets = response.jsonBody['pets'] ?? []; + final List pets = response.jsonBody['pets']['list'] ?? []; + safeSetState(() => count = response.jsonBody['pets']['count'] ?? 0); if (pets != null && pets.isNotEmpty) { setState(() { @@ -95,6 +97,7 @@ class _PetsHistoryScreenState extends State void _loadMore() { if (_hasData == true) { _pageNumber++; + _petsFuture = _fetchVisits(); } } @@ -151,7 +154,7 @@ class _PetsHistoryScreenState extends State AppState().petAmountRegister == 0 ? FFLocalizations.of(context).getVariableText( ptText: "Ilimitado", enText: "Unlimited") - : "${FFLocalizations.of(context).getVariableText(ptText: "Quantidade de Pets: ", enText: "Amount of Pets: ")}${_petsWrap.length}/${AppState().petAmountRegister}", + : "${FFLocalizations.of(context).getVariableText(ptText: "Quantidade de Pets: ", enText: "Amount of Pets: ")}${count}/${AppState().petAmountRegister}", textAlign: TextAlign.right, ), ); @@ -256,7 +259,8 @@ class _PetsHistoryScreenState extends State safeSetState(() { _pageNumber = 1; _petsWrap = []; - _petsFuture = _fetchVisits(); + _petsFuture = + _fetchVisits().then((value) => value!.jsonBody['pets'] ?? []); }); }).catchError((e, s) { DialogUtil.errorDefault(context); diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index 2fb76a9c..11963e0e 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -12,6 +12,11 @@ import '/custom_code/actions/index.dart' as actions; class PetsPageModel extends FlutterFlowModel { late final TabController tabBarController; VoidCallback? onUpdatePet; + VoidCallback? onRegisterPet; + VoidCallback? safeSetState; + + final GlobalKey registerFormKey = GlobalKey(); + final GlobalKey updateFormKey = GlobalKey(); ApiCallResponse? petsResponse; int? petId; @@ -149,7 +154,7 @@ class PetsPageModel extends FlutterFlowModel { // Validador do formulário bool isFormValid(BuildContext context) { - if (uploadedLocalFile == null) { + if (uploadedLocalFile == null || uploadedLocalFile!.bytes!.isEmpty) { return false; } if (textControllerName.text.isEmpty || @@ -170,7 +175,9 @@ class PetsPageModel extends FlutterFlowModel { dropDownValue1 == '') { return false; } - if (dropDownValue2 == null) { + if (dropDownValue2 == null || + dropDownValue2!.isEmpty || + dropDownValue2 == '') { return false; } return true; @@ -196,7 +203,8 @@ class PetsPageModel extends FlutterFlowModel { size: dropDownValue2!, ) .then((response) { - if (response.jsonBody['error'] == true) { + if (response.jsonBody['error'] == true || + isFormValid(buildContext!) == false) { DialogUtil.error(buildContext!, jsonDecode(response.jsonBody['error_msg'])[0]['message']); } @@ -206,11 +214,8 @@ class PetsPageModel extends FlutterFlowModel { enText: 'Pet successfully updated', ptText: 'Pet atualizado com sucesso', )); - clearFields(); + onUpdatePet?.call(); switchTab(1); - }).catchError((error) { - log(error.toString()); - DialogUtil.errorDefault(buildContext!); }); } @@ -234,30 +239,42 @@ class PetsPageModel extends FlutterFlowModel { ) .then((response) { if (response.jsonBody['error'] == true) { - DialogUtil.error(buildContext!, - jsonDecode(response.jsonBody['error_msg'])[0]['message']); + 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', + ); + } + } + 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(); } - DialogUtil.success( - buildContext!, - FFLocalizations.of(buildContext!).getVariableText( - enText: 'Pet successfully registered', - ptText: 'Pet cadastrado com sucesso', - )); - clearFields(); - onUpdatePet?.call(); - }).catchError((error) { - DialogUtil.errorDefault(buildContext!); }); } void switchTab(int index) { tabBarController.animateTo(index); if (index == 1) handleEditingChanged(false); - onUpdatePet?.call(); } void handleUploadComplete(FFUploadedFile uploadedFile) { uploadedLocalFile = uploadedFile; + safeSetState?.call(); } void handleEditingChanged(bool editing) { @@ -267,13 +284,19 @@ class PetsPageModel extends FlutterFlowModel { void clearFields() { uploadedLocalFile = null; - textControllerName.text = ''; - textControllerSpecies.text = ''; - textControllerRace.text = ''; - textControllerColor.text = ''; - textControllerData.text = ''; - textControllerObservation.text = ''; - dropDownValueController1 = FormFieldController(''); - dropDownValueController2 = FormFieldController(''); + + textControllerName?.clear(); + textControllerName?.clear(); + textControllerSpecies?.clear(); + textControllerRace?.clear(); + textControllerColor?.clear(); + textControllerData?.clear(); + textControllerObservation?.clear(); + + dropDownValue1 = null; + dropDownValue2 = null; + + dropDownValueController1 = FormFieldController(null); + dropDownValueController2 = FormFieldController(null); } } diff --git a/lib/pages/pets_page/pets_page_widget.dart b/lib/pages/pets_page/pets_page_widget.dart index 007288cf..dc5df7df 100644 --- a/lib/pages/pets_page/pets_page_widget.dart +++ b/lib/pages/pets_page/pets_page_widget.dart @@ -51,7 +51,6 @@ class PetsPageWidget extends StatefulWidget { class _PetsPageWidgetState extends State with SingleTickerProviderStateMixin { late PetsPageModel _model; - final _formKey = GlobalKey(); @override void initState() { @@ -59,7 +58,17 @@ class _PetsPageWidgetState extends State _model = PetsPageModel(); _model.tabBarController = TabController(length: 2, vsync: this); _model.onUpdatePet = () { - setState(() {}); + safeSetState(() { + _model.clearFields(); + }); + }; + _model.onRegisterPet = () { + safeSetState(() { + _model.clearFields(); + }); + }; + _model.safeSetState = () { + safeSetState(() {}); }; widget.pet != null ? _model.isEditing = true : _model.isEditing = false; @@ -199,7 +208,7 @@ class _PetsPageWidgetState extends State ), ), Form( - key: _formKey, + key: _model.registerFormKey, autovalidateMode: AutovalidateMode.onUserInteraction, child: Column( mainAxisSize: MainAxisSize.max, @@ -227,6 +236,7 @@ class _PetsPageWidgetState extends State .getVariableText(ptText: 'Nome', enText: 'Name'), suffixIcon: Symbols.format_color_text, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 80, ), Padding( @@ -243,6 +253,7 @@ class _PetsPageWidgetState extends State enText: 'e.g. Dog, Cat, Parrot'), suffixIcon: Symbols.sound_detection_dog_barking, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 80, ), ), @@ -260,6 +271,7 @@ class _PetsPageWidgetState extends State enText: 'e.g. Labrador, Poodle, Siamese, Persian'), suffixIcon: Icons.pets_outlined, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 80, ), ), @@ -277,6 +289,7 @@ class _PetsPageWidgetState extends State enText: 'e.g. Black, Yellow, White'), suffixIcon: Symbols.palette, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 80, ), ), @@ -614,6 +627,7 @@ class _PetsPageWidgetState extends State enText: 'Write your observations here...'), suffixIcon: Icons.text_fields, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 250, ), Padding( @@ -657,7 +671,7 @@ class _PetsPageWidgetState extends State ), ), Form( - key: _formKey, + key: _model.updateFormKey, autovalidateMode: AutovalidateMode.onUserInteraction, child: Column( mainAxisSize: MainAxisSize.max, @@ -685,6 +699,7 @@ class _PetsPageWidgetState extends State .getVariableText(ptText: 'Nome', enText: 'Name'), suffixIcon: Symbols.format_color_text, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 80, ), Padding( @@ -701,6 +716,7 @@ class _PetsPageWidgetState extends State enText: 'e.g. Dog, Cat, Parrot'), suffixIcon: Symbols.sound_detection_dog_barking, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 80, ), ), @@ -718,6 +734,7 @@ class _PetsPageWidgetState extends State enText: 'e.g. Labrador, Poodle, Siamese, Persian'), suffixIcon: Icons.pets_outlined, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 80, ), ), @@ -735,6 +752,7 @@ class _PetsPageWidgetState extends State enText: 'e.g. Black, Yellow, White'), suffixIcon: Symbols.palette, haveMaxLength: true, + onChanged: (value) => setState(() {}), maxLength: 80, ), ), @@ -1075,6 +1093,7 @@ class _PetsPageWidgetState extends State suffixIcon: Icons.text_fields, haveMaxLength: true, maxLength: 250, + onChanged: (value) => setState(() {}), ), Padding( padding: const EdgeInsets.fromLTRB(70, 20, 70, 30), diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 795d5417..cf64f7c7 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -488,7 +488,6 @@ class PreferencesPageModel with ChangeNotifier { ); } }).catchError((err) { - log(err.toString()); context.pop(); ScaffoldMessenger.of(context).showSnackBar( SnackBar( diff --git a/lib/shared/utils/validator_util.dart b/lib/shared/utils/validator_util.dart index aaa09bd5..f1550827 100644 --- a/lib/shared/utils/validator_util.dart +++ b/lib/shared/utils/validator_util.dart @@ -20,7 +20,6 @@ class ValidatorUtil { } static String toISO8601(String format, String value) { - log('value: $value'); DateFormat dateFormat = DateFormat(format); DateTime dateTime = dateFormat.parse(value); @@ -28,7 +27,6 @@ class ValidatorUtil { } static String toISO8601USA(String format, String value) { - log('value: $value'); DateFormat dateFormat = DateFormat(format); DateTime dateTime = dateFormat.parse(value); String date = dateTime.toIso8601String() + 'Z'; @@ -45,7 +43,6 @@ class ValidatorUtil { } static String formatDateTimePicker(String dateTime) { - log('dateTime: $dateTime'); List parts = dateTime.split(' '); String datePart = parts[0]; List dateParts = datePart.split('-');