This commit is contained in:
J. A. Messias 2024-09-10 18:02:59 -03:00
parent 5c59989316
commit 2a9f58f9e6
8 changed files with 309 additions and 47 deletions

View File

@ -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<ApiCallResponse> 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<ApiCallResponse> 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<ApiCallResponse> 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<ApiCallResponse> 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<ApiCallResponse> 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<ApiCallResponse> 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,

View File

@ -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;
}
}

View File

@ -75,7 +75,8 @@ class _CustomInputUtilState extends State<CustomInputUtil> {
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<CustomInputUtil> {
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<CustomInputUtil> {
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),
],
),
],

View File

@ -60,8 +60,7 @@ class _CustomSelectState extends State<CustomSelect> {
height: 48.0,
decoration: const BoxDecoration(),
child: FlutterFlowDropDown<String>(
fillColor:
FlutterFlowTheme.of(context).secondaryBackground,
fillColor: FlutterFlowTheme.of(context).primaryBackground,
controller: widget.controller ??=
FormFieldController<String>(
widget.dropDownValue ??= ''),

View File

@ -7,7 +7,7 @@ import 'package:json_path/fun_sdk.dart';
class SubmitButtonUtil extends StatelessWidget {
final String labelText;
Future<void> Function()? onPressed;
Future Function()? onPressed;
SubmitButtonUtil({
required this.labelText,

View File

@ -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<PetsPageWidget> {
ApiCallResponse? petsResponse;
BuildContext? buildContext;
// Controller para o Upload de Arquivos
bool isDataUploading = false;
FFUploadedFile uploadedLocalFile =
@ -70,12 +74,6 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
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<PetsPageWidget> {
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<PetsPageWidget> {
Future<void> registerPet() async {
if (isFormValid == true) {
imgBase64 = await actions.convertImageFileToBase64(
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!);
});
}
}
}

View File

@ -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<PetsPageWidget>
late PetsPageModel _model;
final _formKey = GlobalKey<FormState>();
Future<void> 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<PetsPageWidget>
@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<PetsPageWidget>
labelText: FFLocalizations.of(context)
.getVariableText(
ptText: 'Cadastrar', enText: 'Register'),
onPressed: _model.isFormValid(context)
? _model.registerPet
: null),
onPressed:
_model.isFormValid(context) ? registerPet : null),
),
])),
],

View File

@ -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: