This commit is contained in:
J. A. Messias 2024-09-13 18:04:35 -03:00
parent ac26e0ddac
commit 624f00cc1f
3 changed files with 28 additions and 37 deletions

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

@ -209,12 +209,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(); onUpdatePet?.call();
switchTab(1); switchTab(1);
}).onError((error, stack) {
log(error.toString());
DialogUtil.errorDefault(buildContext!);
}); });
} }
@ -240,17 +236,15 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
if (response.jsonBody['error'] == true) { if (response.jsonBody['error'] == true) {
DialogUtil.error(buildContext!, DialogUtil.error(buildContext!,
jsonDecode(response.jsonBody['error_msg'])[0]['message']); jsonDecode(response.jsonBody['error_msg'])[0]['message']);
} 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();
onRegisterPet?.call();
}).onError((error, stack) {
DialogUtil.errorDefault(buildContext!);
}); });
} }
@ -270,23 +264,13 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
void clearFields() { void clearFields() {
uploadedLocalFile = null; uploadedLocalFile = null;
textControllerName!.clear();
textControllerName!.clearComposing();
textControllerSpecies!.clear(); textControllerName?.clear();
textControllerSpecies!.clearComposing(); textControllerSpecies?.clear();
textControllerRace?.clear();
textControllerRace!.clear(); textControllerColor?.clear();
textControllerRace!.clearComposing(); textControllerData?.clear();
textControllerObservation?.clear();
textControllerColor!.clear();
textControllerColor!.clearComposing();
textControllerData!.clear();
textControllerData!.clearComposing();
textControllerObservation!.clear();
textControllerObservation!.clearComposing();
dropDownValue1 = null; dropDownValue1 = null;
dropDownValue2 = null; dropDownValue2 = null;

View File

@ -59,12 +59,15 @@ 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(() {
Form.of(context).reset(); _model.clearFields();
// _formKey.currentState?.reset();
});
}; };
_model.onRegisterPet = () { _model.onRegisterPet = () {
setState(() {}); safeSetState(() {
Form.of(context).reset(); _model.clearFields();
});
}; };
widget.pet != null ? _model.isEditing = true : _model.isEditing = false; widget.pet != null ? _model.isEditing = true : _model.isEditing = false;