190 lines
5.5 KiB
Dart
190 lines
5.5 KiB
Dart
import 'dart:developer';
|
|
import 'package:flutter/material.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/log_util.dart';
|
|
import '/custom_code/actions/index.dart' as actions;
|
|
|
|
class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
|
|
late final TabController tabBarController;
|
|
|
|
ApiCallResponse? petsResponse;
|
|
|
|
// Controller para o Upload de Arquivos
|
|
bool isDataUploading = false;
|
|
FFUploadedFile uploadedLocalFile =
|
|
FFUploadedFile(bytes: Uint8List.fromList([]));
|
|
String? imgBase64;
|
|
|
|
// Controller para o DropDown
|
|
String? dropDownValue1;
|
|
FormFieldController<String>? dropDownValueController1;
|
|
|
|
String? dropDownValue2;
|
|
FormFieldController<String>? dropDownValueController2;
|
|
|
|
// Controller para o TextField
|
|
FocusNode? textFieldFocusName;
|
|
TextEditingController? textControllerName;
|
|
String? textControllerNameValidator(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;
|
|
}
|
|
|
|
FocusNode? textFieldFocusSpecies;
|
|
TextEditingController? textControllerSpecies;
|
|
String? textControllerSpeciesValidator(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;
|
|
}
|
|
|
|
FocusNode? textFieldFocusRace;
|
|
TextEditingController? textControllerRace;
|
|
String? textControllerRaceValidator(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;
|
|
}
|
|
|
|
FocusNode? textFieldFocusColor;
|
|
TextEditingController? textControllerColor;
|
|
String? Function(BuildContext, String?)? textControllerColorValidator;
|
|
|
|
DateTime? selectedDate;
|
|
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;
|
|
}
|
|
|
|
FocusNode? textFieldFocusObservation;
|
|
TextEditingController? textControllerObservation;
|
|
String? Function(BuildContext, String?)? textControllerObservationValidator;
|
|
|
|
@override
|
|
void initState(BuildContext context) {
|
|
// Se liga! Esse é o controller do TabBar
|
|
tabBarController = TabController(
|
|
vsync: Navigator.of(context),
|
|
length: 2,
|
|
);
|
|
|
|
textFieldFocusName = FocusNode();
|
|
textControllerName = TextEditingController();
|
|
// textControllerNameValidator =
|
|
// (context, value) => _textControllerNameValidator(context, value);
|
|
|
|
textFieldFocusSpecies = FocusNode();
|
|
textControllerSpecies = TextEditingController();
|
|
|
|
textFieldFocusRace = FocusNode();
|
|
textControllerRace = TextEditingController();
|
|
|
|
textFieldFocusColor = FocusNode();
|
|
textControllerColor = TextEditingController();
|
|
|
|
textFieldFocusData = FocusNode();
|
|
textControllerData = TextEditingController(
|
|
text: dateTimeFormat(
|
|
'dd/MM/yyyy',
|
|
DateTime.now(),
|
|
));
|
|
|
|
textFieldFocusObservation = FocusNode();
|
|
textControllerObservation = TextEditingController();
|
|
|
|
dropDownValueController1 =
|
|
FormFieldController<String>(dropDownValue1 ??= 'Selecione uma opção');
|
|
|
|
dropDownValueController2 =
|
|
FormFieldController<String>(dropDownValue2 ??= 'Selecione uma opção');
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
tabBarController.dispose();
|
|
|
|
textFieldFocusName?.dispose();
|
|
textControllerName?.dispose();
|
|
|
|
textFieldFocusSpecies?.dispose();
|
|
textControllerSpecies?.dispose();
|
|
|
|
textFieldFocusRace?.dispose();
|
|
textControllerRace?.dispose();
|
|
|
|
textFieldFocusColor?.dispose();
|
|
textControllerColor?.dispose();
|
|
|
|
textFieldFocusData?.dispose();
|
|
textControllerData?.dispose();
|
|
|
|
textFieldFocusObservation?.dispose();
|
|
textControllerObservation?.dispose();
|
|
|
|
dropDownValueController1?.dispose();
|
|
dropDownValueController2?.dispose();
|
|
}
|
|
|
|
// Validador do formulário
|
|
bool isFormValid(BuildContext context) {
|
|
if (uploadedLocalFile.bytes?.isEmpty ?? true) {
|
|
return false;
|
|
}
|
|
if (textControllerName.text.isEmpty ||
|
|
textControllerName.text.length > 80 ||
|
|
textControllerName.text == '') {
|
|
return false;
|
|
}
|
|
if (textControllerSpecies.text.isEmpty ||
|
|
textControllerSpecies.text == '') {
|
|
return false;
|
|
}
|
|
if (textControllerRace.text.isEmpty || textControllerRace.text == '') {
|
|
return false;
|
|
}
|
|
if (textControllerData.text.isEmpty || textControllerData.text == '') {
|
|
return false;
|
|
}
|
|
if (dropDownValue1 == null ||
|
|
dropDownValue1!.isEmpty ||
|
|
dropDownValue1 == '') {
|
|
return false;
|
|
}
|
|
if (dropDownValue2 == null) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
Future<void> registerPet() async {
|
|
if (isFormValid == true) {
|
|
imgBase64 = await actions.convertImageFileToBase64(
|
|
uploadedLocalFile,
|
|
);
|
|
}
|
|
}
|
|
}
|