Merge branch 'main' into fix/fd-784

This commit is contained in:
J. A. Messias 2024-09-16 10:00:44 -03:00
commit 194db60045
8 changed files with 98 additions and 52 deletions

View File

@ -60,11 +60,16 @@ class _CustomInputUtilState extends State<CustomInputUtil> {
validator: widget.validator, validator: widget.validator,
autofocus: widget.autoFocus, autofocus: widget.autoFocus,
focusNode: widget.focusNode, focusNode: widget.focusNode,
onChanged: (_) => EasyDebounce.debounce( onChanged: (value) {
'${widget.controller}', EasyDebounce.debounce(
const Duration(milliseconds: 500), '${widget.controller}',
() => setState(() {}), const Duration(milliseconds: 500),
), () => setState(() {}),
);
if (widget.onChanged != null) {
widget.onChanged!(value); // Chamar o callback
}
},
textInputAction: widget.textInputAction, textInputAction: widget.textInputAction,
obscureText: false, obscureText: false,
decoration: InputDecoration( decoration: InputDecoration(

View File

@ -14,13 +14,13 @@ class MediaUploadButtonUtil extends StatefulWidget {
final String labelText; final String labelText;
FFUploadedFile? uploadedFiles; FFUploadedFile? uploadedFiles;
MediaUploadButtonUtil( MediaUploadButtonUtil({
{Key? key, Key? key,
required this.onUploadComplete, required this.onUploadComplete,
required this.isUploading, required this.isUploading,
required this.labelText, required this.labelText,
this.uploadedFiles}) this.uploadedFiles,
: super(key: key); }) : super(key: key);
@override @override
State<MediaUploadButtonUtil> createState() => _MediaUploadButtonUtilState(); State<MediaUploadButtonUtil> createState() => _MediaUploadButtonUtilState();

View File

@ -47,7 +47,6 @@ class _HomePageWidgetState extends State<HomePageWidget> {
final errorMsg = response.jsonBody['error_msg']; final errorMsg = response.jsonBody['error_msg'];
if (error == false) { if (error == false) {
log(response.jsonBody.toString());
AppState().whatsapp = response.jsonBody['whatsapp'] ?? false; AppState().whatsapp = response.jsonBody['whatsapp'] ?? false;
AppState().provisional = response.jsonBody['provisional'] ?? false; AppState().provisional = response.jsonBody['provisional'] ?? false;
AppState().pets = response.jsonBody['pet'] ?? false; AppState().pets = response.jsonBody['pet'] ?? false;

View File

@ -24,6 +24,7 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen>
final int _pageSize = 10; final int _pageSize = 10;
bool _hasData = false; bool _hasData = false;
bool _loading = false; bool _loading = false;
int count = 0;
late Future<void> _petsFuture; late Future<void> _petsFuture;
List<dynamic> _petsWrap = []; List<dynamic> _petsWrap = [];
@ -61,7 +62,8 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen>
page: _pageNumber, page: _pageNumber,
); );
final List<dynamic> pets = response.jsonBody['pets'] ?? []; final List<dynamic> pets = response.jsonBody['pets']['list'] ?? [];
safeSetState(() => count = response.jsonBody['pets']['count'] ?? 0);
if (pets != null && pets.isNotEmpty) { if (pets != null && pets.isNotEmpty) {
setState(() { setState(() {
@ -95,6 +97,7 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen>
void _loadMore() { void _loadMore() {
if (_hasData == true) { if (_hasData == true) {
_pageNumber++; _pageNumber++;
_petsFuture = _fetchVisits(); _petsFuture = _fetchVisits();
} }
} }
@ -151,7 +154,7 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen>
AppState().petAmountRegister == 0 AppState().petAmountRegister == 0
? FFLocalizations.of(context).getVariableText( ? FFLocalizations.of(context).getVariableText(
ptText: "Ilimitado", enText: "Unlimited") 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, textAlign: TextAlign.right,
), ),
); );
@ -256,7 +259,8 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen>
safeSetState(() { safeSetState(() {
_pageNumber = 1; _pageNumber = 1;
_petsWrap = []; _petsWrap = [];
_petsFuture = _fetchVisits(); _petsFuture =
_fetchVisits().then((value) => value!.jsonBody['pets'] ?? []);
}); });
}).catchError((e, s) { }).catchError((e, s) {
DialogUtil.errorDefault(context); DialogUtil.errorDefault(context);

View File

@ -12,6 +12,11 @@ import '/custom_code/actions/index.dart' as actions;
class PetsPageModel extends FlutterFlowModel<PetsPageWidget> { class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
late final TabController tabBarController; late final TabController tabBarController;
VoidCallback? onUpdatePet; VoidCallback? onUpdatePet;
VoidCallback? onRegisterPet;
VoidCallback? safeSetState;
final GlobalKey<FormState> registerFormKey = GlobalKey<FormState>();
final GlobalKey<FormState> updateFormKey = GlobalKey<FormState>();
ApiCallResponse? petsResponse; ApiCallResponse? petsResponse;
int? petId; int? petId;
@ -149,7 +154,7 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
// Validador do formulário // Validador do formulário
bool isFormValid(BuildContext context) { bool isFormValid(BuildContext context) {
if (uploadedLocalFile == null) { if (uploadedLocalFile == null || uploadedLocalFile!.bytes!.isEmpty) {
return false; return false;
} }
if (textControllerName.text.isEmpty || if (textControllerName.text.isEmpty ||
@ -170,7 +175,9 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
dropDownValue1 == '') { dropDownValue1 == '') {
return false; return false;
} }
if (dropDownValue2 == null) { if (dropDownValue2 == null ||
dropDownValue2!.isEmpty ||
dropDownValue2 == '') {
return false; return false;
} }
return true; return true;
@ -196,7 +203,8 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
size: dropDownValue2!, size: dropDownValue2!,
) )
.then((response) { .then((response) {
if (response.jsonBody['error'] == true) { if (response.jsonBody['error'] == true ||
isFormValid(buildContext!) == false) {
DialogUtil.error(buildContext!, DialogUtil.error(buildContext!,
jsonDecode(response.jsonBody['error_msg'])[0]['message']); jsonDecode(response.jsonBody['error_msg'])[0]['message']);
} }
@ -206,11 +214,8 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
enText: 'Pet successfully updated', enText: 'Pet successfully updated',
ptText: 'Pet atualizado com sucesso', ptText: 'Pet atualizado com sucesso',
)); ));
clearFields(); onUpdatePet?.call();
switchTab(1); switchTab(1);
}).catchError((error) {
log(error.toString());
DialogUtil.errorDefault(buildContext!);
}); });
} }
@ -234,30 +239,42 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
) )
.then((response) { .then((response) {
if (response.jsonBody['error'] == true) { if (response.jsonBody['error'] == true) {
DialogUtil.error(buildContext!, String errorMessage = '';
jsonDecode(response.jsonBody['error_msg'])[0]['message']); 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) { void switchTab(int index) {
tabBarController.animateTo(index); tabBarController.animateTo(index);
if (index == 1) handleEditingChanged(false); if (index == 1) handleEditingChanged(false);
onUpdatePet?.call();
} }
void handleUploadComplete(FFUploadedFile uploadedFile) { void handleUploadComplete(FFUploadedFile uploadedFile) {
uploadedLocalFile = uploadedFile; uploadedLocalFile = uploadedFile;
safeSetState?.call();
} }
void handleEditingChanged(bool editing) { void handleEditingChanged(bool editing) {
@ -267,13 +284,19 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
void clearFields() { void clearFields() {
uploadedLocalFile = null; uploadedLocalFile = null;
textControllerName.text = '';
textControllerSpecies.text = ''; textControllerName?.clear();
textControllerRace.text = ''; textControllerName?.clear();
textControllerColor.text = ''; textControllerSpecies?.clear();
textControllerData.text = ''; textControllerRace?.clear();
textControllerObservation.text = ''; textControllerColor?.clear();
dropDownValueController1 = FormFieldController<String>(''); textControllerData?.clear();
dropDownValueController2 = FormFieldController<String>(''); textControllerObservation?.clear();
dropDownValue1 = null;
dropDownValue2 = null;
dropDownValueController1 = FormFieldController<String>(null);
dropDownValueController2 = FormFieldController<String>(null);
} }
} }

View File

@ -51,7 +51,6 @@ class PetsPageWidget extends StatefulWidget {
class _PetsPageWidgetState extends State<PetsPageWidget> class _PetsPageWidgetState extends State<PetsPageWidget>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
late PetsPageModel _model; late PetsPageModel _model;
final _formKey = GlobalKey<FormState>();
@override @override
void initState() { void initState() {
@ -59,7 +58,17 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
_model = PetsPageModel(); _model = PetsPageModel();
_model.tabBarController = TabController(length: 2, vsync: this); _model.tabBarController = TabController(length: 2, vsync: this);
_model.onUpdatePet = () { _model.onUpdatePet = () {
setState(() {}); safeSetState(() {
_model.clearFields();
});
};
_model.onRegisterPet = () {
safeSetState(() {
_model.clearFields();
});
};
_model.safeSetState = () {
safeSetState(() {});
}; };
widget.pet != null ? _model.isEditing = true : _model.isEditing = false; widget.pet != null ? _model.isEditing = true : _model.isEditing = false;
@ -199,7 +208,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
), ),
), ),
Form( Form(
key: _formKey, key: _model.registerFormKey,
autovalidateMode: AutovalidateMode.onUserInteraction, autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column( child: Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
@ -227,6 +236,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
.getVariableText(ptText: 'Nome', enText: 'Name'), .getVariableText(ptText: 'Nome', enText: 'Name'),
suffixIcon: Symbols.format_color_text, suffixIcon: Symbols.format_color_text,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 80, maxLength: 80,
), ),
Padding( Padding(
@ -243,6 +253,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
enText: 'e.g. Dog, Cat, Parrot'), enText: 'e.g. Dog, Cat, Parrot'),
suffixIcon: Symbols.sound_detection_dog_barking, suffixIcon: Symbols.sound_detection_dog_barking,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 80, maxLength: 80,
), ),
), ),
@ -260,6 +271,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
enText: 'e.g. Labrador, Poodle, Siamese, Persian'), enText: 'e.g. Labrador, Poodle, Siamese, Persian'),
suffixIcon: Icons.pets_outlined, suffixIcon: Icons.pets_outlined,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 80, maxLength: 80,
), ),
), ),
@ -277,6 +289,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
enText: 'e.g. Black, Yellow, White'), enText: 'e.g. Black, Yellow, White'),
suffixIcon: Symbols.palette, suffixIcon: Symbols.palette,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 80, maxLength: 80,
), ),
), ),
@ -614,6 +627,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
enText: 'Write your observations here...'), enText: 'Write your observations here...'),
suffixIcon: Icons.text_fields, suffixIcon: Icons.text_fields,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 250, maxLength: 250,
), ),
Padding( Padding(
@ -657,7 +671,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
), ),
), ),
Form( Form(
key: _formKey, key: _model.updateFormKey,
autovalidateMode: AutovalidateMode.onUserInteraction, autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column( child: Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
@ -685,6 +699,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
.getVariableText(ptText: 'Nome', enText: 'Name'), .getVariableText(ptText: 'Nome', enText: 'Name'),
suffixIcon: Symbols.format_color_text, suffixIcon: Symbols.format_color_text,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 80, maxLength: 80,
), ),
Padding( Padding(
@ -701,6 +716,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
enText: 'e.g. Dog, Cat, Parrot'), enText: 'e.g. Dog, Cat, Parrot'),
suffixIcon: Symbols.sound_detection_dog_barking, suffixIcon: Symbols.sound_detection_dog_barking,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 80, maxLength: 80,
), ),
), ),
@ -718,6 +734,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
enText: 'e.g. Labrador, Poodle, Siamese, Persian'), enText: 'e.g. Labrador, Poodle, Siamese, Persian'),
suffixIcon: Icons.pets_outlined, suffixIcon: Icons.pets_outlined,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 80, maxLength: 80,
), ),
), ),
@ -735,6 +752,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
enText: 'e.g. Black, Yellow, White'), enText: 'e.g. Black, Yellow, White'),
suffixIcon: Symbols.palette, suffixIcon: Symbols.palette,
haveMaxLength: true, haveMaxLength: true,
onChanged: (value) => setState(() {}),
maxLength: 80, maxLength: 80,
), ),
), ),
@ -1075,6 +1093,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
suffixIcon: Icons.text_fields, suffixIcon: Icons.text_fields,
haveMaxLength: true, haveMaxLength: true,
maxLength: 250, maxLength: 250,
onChanged: (value) => setState(() {}),
), ),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(70, 20, 70, 30), padding: const EdgeInsets.fromLTRB(70, 20, 70, 30),

View File

@ -488,7 +488,6 @@ class PreferencesPageModel with ChangeNotifier {
); );
} }
}).catchError((err) { }).catchError((err) {
log(err.toString());
context.pop(); context.pop();
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(

View File

@ -20,7 +20,6 @@ class ValidatorUtil {
} }
static String toISO8601(String format, String value) { static String toISO8601(String format, String value) {
log('value: $value');
DateFormat dateFormat = DateFormat(format); DateFormat dateFormat = DateFormat(format);
DateTime dateTime = dateFormat.parse(value); DateTime dateTime = dateFormat.parse(value);
@ -28,7 +27,6 @@ class ValidatorUtil {
} }
static String toISO8601USA(String format, String value) { static String toISO8601USA(String format, String value) {
log('value: $value');
DateFormat dateFormat = DateFormat(format); DateFormat dateFormat = DateFormat(format);
DateTime dateTime = dateFormat.parse(value); DateTime dateTime = dateFormat.parse(value);
String date = dateTime.toIso8601String() + 'Z'; String date = dateTime.toIso8601String() + 'Z';
@ -45,7 +43,6 @@ class ValidatorUtil {
} }
static String formatDateTimePicker(String dateTime) { static String formatDateTimePicker(String dateTime) {
log('dateTime: $dateTime');
List<String> parts = dateTime.split(' '); List<String> parts = dateTime.split(' ');
String datePart = parts[0]; String datePart = parts[0];
List<String> dateParts = datePart.split('-'); List<String> dateParts = datePart.split('-');