diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 5cef38f7..19540ca5 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -49,8 +49,214 @@ class PhpGroup { static DeleteAccount deleteAccount = DeleteAccount(); static CancelaVisita cancelaVisita = CancelaVisita(); static BuscaEnconcomendas buscaEnconcomendas = BuscaEnconcomendas(); + static RegisterPet registerPet = RegisterPet(); + static DeletePet deletePet = DeletePet(); + static UpdatePet updatePet = UpdatePet(); + static GetPets getPets = GetPets(); + static GetPetPhoto getPetPhoto = GetPetPhoto(); } +class DeletePet { + Future call({ + String? devUUID = '', + String? userUUID = '', + String? cliID = '', + String? petID = '', + }) async { + final baseUrl = PhpGroup.getBaseUrl(); + + return ApiManager.instance.makeApiCall( + callName: 'deletePet', + apiUrl: '$baseUrl/deletePet.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'devUUID': devUUID, + 'userUUID': userUUID, + 'cliID': cliID, + 'id': petID, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + isStreamingApi: false, + alwaysAllowBody: false, + ); + } +} + +class UpdatePet { + Future call({ + String? devUUID = '', + String? userUUID = '', + String? cliID = '', + String? petID = '', + String? image = '', + String? name = '', + String? species = '', + String? breed = '', + String? color = '', + String? birthdayDate = '', + String? gender = '', + String? size = '', + String? notes = '', + }) async { + final baseUrl = PhpGroup.getBaseUrl(); + + return ApiManager.instance.makeApiCall( + callName: 'updatePet', + apiUrl: '$baseUrl/updatePet.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'devUUID': devUUID, + 'userUUID': userUUID, + 'cliID': cliID, + 'id': petID, + 'image': image, + 'name': name, + 'species': species, + 'breed': breed, + 'color': color, + 'birthdayDate': birthdayDate, + 'gender': gender, + 'size': size, + 'notes': notes, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + isStreamingApi: false, + alwaysAllowBody: false, + ); + } +} + +class GetPets { + Future call({ + String? devUUID = '', + String? userUUID = '', + String? cliID = '', + String? page = '', + String? pageSize = '', + }) async { + final baseUrl = PhpGroup.getBaseUrl(); + + return ApiManager.instance.makeApiCall( + callName: 'getPets', + apiUrl: '$baseUrl/getPets.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'devUUID': devUUID, + 'userUUID': userUUID, + 'cliID': cliID, + 'page': page, + 'pageSize': pageSize, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + alwaysAllowBody: false, + ); + } +} + +class GetPetPhoto { + Future call({ + String? devUUID = '', + String? userUUID = '', + String? cliID = '', + String? petID = '', + }) async { + final baseUrl = PhpGroup.getBaseUrl(); + + return ApiManager.instance.makeApiCall( + callName: 'getPetPhoto', + apiUrl: '$baseUrl/getPetPhoto.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'devUUID': devUUID, + 'userUUID': userUUID, + 'cliID': cliID, + 'petId': petID, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + alwaysAllowBody: false, + ); + } +} + +class RegisterPet { + Future call({ + String? devUUID = '', + String? userUUID = '', + String? cliID = '', + String? atividade = 'cadastrarPet', + String? image = '', + String? name = '', + String? species = '', + String? breed = '', + String? color = '', + String? birthdayDate = '', + String? gender = '', + String? size = '', + String? notes = '', + }) async { + final baseUrl = PhpGroup.getBaseUrl(); + + return ApiManager.instance.makeApiCall( + callName: 'registerPet', + apiUrl: '$baseUrl/processRequest.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'devUUID': devUUID, + 'userUUID': userUUID, + 'cliID': cliID, + 'atividade': atividade, + 'image': image, + 'name': name, + 'species': species, + 'breed': breed, + if (color != '') 'color': color, + if (birthdayDate != '') + 'birthdayDate': ValidatorUtil.toISO8601('dd/MM/yyyy', birthdayDate!), + 'gender': gender, + 'size': size, + if (notes != '') 'notes': notes, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + isStreamingApi: false, + alwaysAllowBody: false, + ); + } +} class BuscaEnconcomendas { Future call({ @@ -58,7 +264,6 @@ class BuscaEnconcomendas { String? userUUID = '', String? cliID = '', String? atividade = '', - String? page = '', String? pageSize = '', String? adresseeType = '', @@ -78,7 +283,6 @@ class BuscaEnconcomendas { 'userUUID': userUUID, 'atividade': atividade, 'cliID': cliID, - 'page': page, 'pageSize': pageSize, 'adresseeType': adresseeType, @@ -94,9 +298,9 @@ class BuscaEnconcomendas { } bool? error(dynamic response) => castToType(getJsonField( - response, - r'''$.error''', - )); + response, + r'''$.error''', + )); } class CancelaVisita { diff --git a/lib/backend/api_requests/api_manager.dart b/lib/backend/api_requests/api_manager.dart index 7c474720..e9574b6b 100644 --- a/lib/backend/api_requests/api_manager.dart +++ b/lib/backend/api_requests/api_manager.dart @@ -513,8 +513,8 @@ class ApiManager { log('API Call: $callName'); log('URL: $apiUrl'); log('Headers: $headers'); - log('Params$params'); - log('Response${result.jsonBody}'); + log('Params: $params'); + log('Response: ${result.jsonBody}'); return result; } } 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 8d207744..d7b724d6 100644 --- a/lib/components/atomic_components/shared_components_atoms/custom_input.dart +++ b/lib/components/atomic_components/shared_components_atoms/custom_input.dart @@ -75,7 +75,8 @@ class _CustomInputUtilState extends State { color: FlutterFlowTheme.of(context).primaryText, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).labelMediumFamily), + FlutterFlowTheme.of(context).labelMediumFamily, + ), ), hintText: widget.hintText, hintStyle: FlutterFlowTheme.of(context).labelMedium.override( @@ -83,7 +84,8 @@ class _CustomInputUtilState extends State { color: FlutterFlowTheme.of(context).primaryText, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).labelMediumFamily), + FlutterFlowTheme.of(context).labelMediumFamily, + ), ), enabledBorder: OutlineInputBorder( borderSide: BorderSide( @@ -123,13 +125,14 @@ class _CustomInputUtilState extends State { color: FlutterFlowTheme.of(context).primaryText, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), + FlutterFlowTheme.of(context).bodyMediumFamily, + ), ), maxLines: null, maxLength: widget.haveMaxLength ? widget.maxLength : null, keyboardType: widget.keyboardType, inputFormatters: [ - LengthLimitingTextInputFormatter(widget.maxLength) + LengthLimitingTextInputFormatter(widget.maxLength), ], ), ], diff --git a/lib/components/atomic_components/shared_components_atoms/custom_select.dart b/lib/components/atomic_components/shared_components_atoms/custom_select.dart index a15f262c..89396d14 100644 --- a/lib/components/atomic_components/shared_components_atoms/custom_select.dart +++ b/lib/components/atomic_components/shared_components_atoms/custom_select.dart @@ -60,8 +60,7 @@ class _CustomSelectState extends State { height: 48.0, decoration: const BoxDecoration(), child: FlutterFlowDropDown( - fillColor: - FlutterFlowTheme.of(context).secondaryBackground, + fillColor: FlutterFlowTheme.of(context).primaryBackground, controller: widget.controller ??= FormFieldController( widget.dropDownValue ??= ''), 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 5be97e1b..c970dca3 100644 --- a/lib/components/atomic_components/shared_components_atoms/submit_button.dart +++ b/lib/components/atomic_components/shared_components_atoms/submit_button.dart @@ -7,7 +7,7 @@ import 'package:json_path/fun_sdk.dart'; class SubmitButtonUtil extends StatelessWidget { final String labelText; - Future Function()? onPressed; + Future Function()? onPressed; SubmitButtonUtil({ required this.labelText, diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index bdd7e0aa..3ecffee0 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -1,9 +1,11 @@ import 'dart:developer'; import 'package:flutter/material.dart'; +import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/form_field_controller.dart'; import 'package:hub/pages/pets_page/pets_page_widget.dart'; +import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; import '/custom_code/actions/index.dart' as actions; @@ -12,6 +14,8 @@ class PetsPageModel extends FlutterFlowModel { ApiCallResponse? petsResponse; + BuildContext? buildContext; + // Controller para o Upload de Arquivos bool isDataUploading = false; FFUploadedFile uploadedLocalFile = @@ -70,12 +74,6 @@ class PetsPageModel extends FlutterFlowModel { FocusNode? textFieldFocusData; TextEditingController? textControllerData; String? textControllerDataValidator(BuildContext context, String? val) { - if (val == null || val.isEmpty) { - return FFLocalizations.of(context).getVariableText( - enText: 'This field is required.', - ptText: 'Este campo é obrigatório.', - ); - } return null; } @@ -165,9 +163,7 @@ class PetsPageModel extends FlutterFlowModel { if (textControllerRace.text.isEmpty || textControllerRace.text == '') { return false; } - if (textControllerData.text.isEmpty || textControllerData.text == '') { - return false; - } + if (dropDownValue1 == null || dropDownValue1!.isEmpty || dropDownValue1 == '') { @@ -181,9 +177,32 @@ class PetsPageModel extends FlutterFlowModel { Future registerPet() async { if (isFormValid == true) { - imgBase64 = await actions.convertImageFileToBase64( - uploadedLocalFile, - ); + await PhpGroup.registerPet + .call( + cliID: AppState().cliUUID, + devUUID: AppState().devUUID, + userUUID: AppState().userUUID, + image: await actions.convertImageFileToBase64( + uploadedLocalFile, + ), + // birthdayDate: textControllerData!.text, + color: textControllerColor!.text, + breed: textControllerRace!.text, + species: textControllerSpecies!.text, + name: textControllerName!.text, + gender: dropDownValue1!, + size: dropDownValue2!, + notes: textControllerObservation!.text, + ) + .then((response) { + if (response.jsonBody['error'] == true) + log('Erro ao registrar pet: ${response.jsonBody}'); + return DialogUtil.errorDefault(buildContext!); + return true; + }).catchError((error) { + log(error.toString()); + return DialogUtil.errorDefault(buildContext!); + }); } } } diff --git a/lib/pages/pets_page/pets_page_widget.dart b/lib/pages/pets_page/pets_page_widget.dart index cee83bae..bf2069d5 100644 --- a/lib/pages/pets_page/pets_page_widget.dart +++ b/lib/pages/pets_page/pets_page_widget.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/appbar.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/custom_datepicker.dart'; @@ -24,7 +25,10 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/flutter_flow/upload_data.dart'; import 'package:hub/pages/pets_page/pets_page_model.dart'; +import 'package:hub/shared/utils/dialog_util.dart'; +import 'package:hub/shared/utils/validator_util.dart'; import 'package:sqflite/sqflite.dart'; +import '/custom_code/actions/index.dart' as actions; class PetsPageWidget extends StatefulWidget { PetsPageWidget({super.key}); @@ -38,6 +42,39 @@ class _PetsPageWidgetState extends State late PetsPageModel _model; final _formKey = GlobalKey(); + Future registerPet() async { + await PhpGroup.registerPet + .call( + cliID: AppState().cliUUID, + devUUID: AppState().devUUID, + userUUID: AppState().userUUID, + image: await actions.convertImageFileToBase64( + _model.uploadedLocalFile, + ), + birthdayDate: _model.textControllerData!.text, + color: _model.textControllerColor!.text, + breed: _model.textControllerRace!.text, + species: _model.textControllerSpecies!.text, + name: _model.textControllerName!.text, + gender: _model.dropDownValue1!, + size: _model.dropDownValue2!, + notes: _model.textControllerObservation!.text, + ) + .then((response) { + log('aqui é pá'); + if (response.jsonBody['error'] == true) { + DialogUtil.error( + context, jsonDecode(response.jsonBody['error_msg'])[0]['message']); + + log('aqui é trum'); + } + }).catchError((error) { + log('aqui é pum'); + + DialogUtil.errorDefault(context); + }); + } + @override void initState() { super.initState(); @@ -83,29 +120,30 @@ class _PetsPageWidgetState extends State @override Widget build(BuildContext context) { + _model.buildContext = context; return Scaffold( - appBar: appBarPets(context), + appBar: _buildAppBar(context), backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - body: tabViewPets(context)); + body: _buildTabView(context)); } - PreferredSizeWidget appBarPets(BuildContext context) { + PreferredSizeWidget _buildAppBar(BuildContext context) { return AppBarUtil(title: 'Pets', onBackButtonPressed: () => context.pop()); } - Widget tabViewPets(BuildContext context) { + Widget _buildTabView(BuildContext context) { return TabViewUtil( context: context, model: _model, labelTab1: 'Cadastrar', labelTab2: 'Consultar', controller: _model.tabBarController, - widget1: formAddPets(context), + widget1: _buildRegisterForm(context), widget2: const Center(child: Text('Consultar')), ); } - Widget formAddPets(BuildContext context) { + Widget _buildRegisterForm(BuildContext context) { return SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.max, @@ -550,9 +588,8 @@ class _PetsPageWidgetState extends State labelText: FFLocalizations.of(context) .getVariableText( ptText: 'Cadastrar', enText: 'Register'), - onPressed: _model.isFormValid(context) - ? _model.registerPet - : null), + onPressed: + _model.isFormValid(context) ? registerPet : null), ), ])), ], diff --git a/pubspec.lock b/pubspec.lock index 0f63eadd..7ed3b0b7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -825,18 +825,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: @@ -913,10 +913,10 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" material_symbols_icons: dependency: "direct main" description: @@ -937,10 +937,10 @@ packages: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" mime: dependency: transitive description: @@ -1358,10 +1358,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.2" timeago: dependency: "direct main" description: @@ -1526,10 +1526,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.5" web: dependency: transitive description: