This commit is contained in:
J. A. Messias 2024-09-16 08:42:56 -03:00
parent 624f00cc1f
commit 68fc17890d
2 changed files with 23 additions and 6 deletions

View File

@ -13,6 +13,8 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
late final TabController tabBarController;
VoidCallback? onUpdatePet;
VoidCallback? onRegisterPet;
final GlobalKey<FormState> registerFormKey = GlobalKey<FormState>();
final GlobalKey<FormState> updateFormKey = GlobalKey<FormState>();
ApiCallResponse? petsResponse;
int? petId;
@ -234,8 +236,22 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
)
.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!,
@ -265,6 +281,7 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
void clearFields() {
uploadedLocalFile = null;
textControllerName?.clear();
textControllerName?.clear();
textControllerSpecies?.clear();
textControllerRace?.clear();

View File

@ -51,7 +51,6 @@ class PetsPageWidget extends StatefulWidget {
class _PetsPageWidgetState extends State<PetsPageWidget>
with SingleTickerProviderStateMixin {
late PetsPageModel _model;
final _formKey = GlobalKey<FormState>();
@override
void initState() {
@ -61,12 +60,13 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
_model.onUpdatePet = () {
safeSetState(() {
_model.clearFields();
// _formKey.currentState?.reset();
_model.updateFormKey.currentState?.reset();
});
};
_model.onRegisterPet = () {
safeSetState(() {
_model.clearFields();
_model.registerFormKey.currentState?.reset();
});
};
@ -207,7 +207,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
),
),
Form(
key: _formKey,
key: _model.registerFormKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(
mainAxisSize: MainAxisSize.max,
@ -665,7 +665,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget>
),
),
Form(
key: _formKey,
key: _model.updateFormKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(
mainAxisSize: MainAxisSize.max,