fix: late initialization in pets and selection local bug

This commit is contained in:
J. A. Messias 2024-11-12 12:55:51 -03:00
parent b2fcc1cfca
commit ce6e0b4950
5 changed files with 33 additions and 43 deletions

View File

@ -14,8 +14,8 @@ import '/backend/api_requests/api_calls.dart';
import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_theme.dart';
class BottomArrowLinkedLocalsComponentWidget extends StatefulWidget { class BottomArrowLinkedLocalsComponentWidget extends StatefulWidget {
const BottomArrowLinkedLocalsComponentWidget({super.key, required this.response}); BottomArrowLinkedLocalsComponentWidget({super.key, required this.response});
final ApiCallResponse? response; ApiCallResponse? response;
@override @override
State<BottomArrowLinkedLocalsComponentWidget> createState() => _BottomArrowLinkedLocalsComponentWidgetState(); State<BottomArrowLinkedLocalsComponentWidget> createState() => _BottomArrowLinkedLocalsComponentWidgetState();
@ -72,6 +72,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State<BottomArrowLink
Future<ApiCallResponse?> _fetchLocals() async { Future<ApiCallResponse?> _fetchLocals() async {
try { try {
setState(() => _loading = true); setState(() => _loading = true);
widget.response = await PhpGroup.getLocalsCall.call();
final bool isError = widget.response?.jsonBody['error']; final bool isError = widget.response?.jsonBody['error'];
if (isError) { if (isError) {
@ -198,7 +199,8 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State<BottomArrowLink
await StorageHelper().set(SQLiteStorageKey.clientName.value, local['CLI_NOME'], Storage.SQLiteStorage); await StorageHelper().set(SQLiteStorageKey.clientName.value, local['CLI_NOME'], Storage.SQLiteStorage);
await StorageHelper().set(SQLiteStorageKey.ownerUUID.value, local['CLU_OWNER_ID'], Storage.SQLiteStorage); await StorageHelper().set(SQLiteStorageKey.ownerUUID.value, local['CLU_OWNER_ID'], Storage.SQLiteStorage);
context.pop(); context.pop(true);
return true;
} else if (local['CLU_STATUS'] == 'B') { } else if (local['CLU_STATUS'] == 'B') {
String message = FFLocalizations.of(context).getVariableText( String message = FFLocalizations.of(context).getVariableText(
ptText: 'Local Bloqueado para Acesso, Entre em Contato com Administração', ptText: 'Local Bloqueado para Acesso, Entre em Contato com Administração',

View File

@ -12,7 +12,6 @@ import 'package:hub/shared/utils/log_util.dart';
class PetsHistoryScreen extends StatefulWidget { class PetsHistoryScreen extends StatefulWidget {
const PetsHistoryScreen({super.key, required this.model}); const PetsHistoryScreen({super.key, required this.model});
final PetsPageModel model; final PetsPageModel model;
@override @override
@ -34,9 +33,7 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen> with TickerProvid
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_petsFuture = _fetch();
_petsFuture = _fetchVisits();
_scrollController = ScrollController() _scrollController = ScrollController()
..addListener(() { ..addListener(() {
if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) { if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) {
@ -51,7 +48,7 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen> with TickerProvid
super.dispose(); super.dispose();
} }
Future<ApiCallResponse?> _fetchVisits() async { Future<ApiCallResponse?> _fetch() async {
try { try {
setState(() => _loading = true); setState(() => _loading = true);
@ -96,7 +93,7 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen> with TickerProvid
if (_hasData == true) { if (_hasData == true) {
_pageNumber++; _pageNumber++;
_petsFuture = _fetchVisits(); _petsFuture = _fetch();
} }
} }
@ -152,27 +149,10 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen> with TickerProvid
shrinkWrap: true, shrinkWrap: true,
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
controller: _scrollController, controller: _scrollController,
itemCount: _petsWrap.length + 1, itemCount: _petsWrap.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
if (index == 0) { final item = _petsWrap[index];
// Add your item here return _item(context, item);
return Padding(
padding: const EdgeInsets.only(right: 30, top: 10),
child: Text(
widget.model.petAmountRegister == '0'
? FFLocalizations.of(context).getVariableText(ptText: "Ilimitado", enText: "Unlimited")
: "${FFLocalizations.of(context).getVariableText(ptText: "Quantidade de Pets: ", enText: "Amount of Pets: ")}$count/${widget.model.petAmountRegister}",
textAlign: TextAlign.right,
style: TextStyle(
fontFamily: 'Nunito',
fontSize: limitedBodyTextSize,
),
),
);
} else {
final item = _petsWrap[index - 1];
return _item(context, item);
}
}); });
}, },
)), )),
@ -274,7 +254,7 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen> with TickerProvid
safeSetState(() { safeSetState(() {
_pageNumber = 1; _pageNumber = 1;
_petsWrap = []; _petsWrap = [];
_petsFuture = _fetchVisits().then((value) => value!.jsonBody['pets'] ?? []); _petsFuture = _fetch().then((value) => value!.jsonBody['pets'] ?? []);
}); });
}).catchError((e, s) { }).catchError((e, s) {
DialogUtil.errorDefault(context); DialogUtil.errorDefault(context);

View File

@ -20,10 +20,10 @@ import 'package:hub/shared/utils/limited_text_size.dart';
import 'package:hub/shared/utils/validator_util.dart'; import 'package:hub/shared/utils/validator_util.dart';
class PetsPageModel extends FlutterFlowModel<PetsPageWidget> { class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
late final String devUUID; late String devUUID = '';
late final String userUUID; late String userUUID = '';
late final String cliUUID; late String cliUUID = '';
late final String petAmountRegister; late String petAmountRegister = '0';
dynamic item; dynamic item;
late final TabController tabBarController; late final TabController tabBarController;
@ -111,13 +111,17 @@ class PetsPageModel extends FlutterFlowModel<PetsPageWidget> {
); );
dropDownValueController1 = FormFieldController<String>(dropDownValue1 ??= defaultDropDownText); dropDownValueController1 = FormFieldController<String>(dropDownValue1 ??= defaultDropDownText);
dropDownValueController2 = FormFieldController<String>(dropDownValue2 ??= defaultDropDownText); dropDownValueController2 = FormFieldController<String>(dropDownValue2 ??= defaultDropDownText);
log('() => ): $devUUID');
devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; WidgetsBinding.instance.addPostFrameCallback((_) async {
userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; devUUID = await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage) ?? '';
cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; userUUID = await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage) ?? '';
petAmountRegister = (await StorageHelper().get(SQLiteStorageKey.petAmount.value, Storage.SQLiteStorage)) ?? ''; cliUUID = await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage) ?? '';
petAmountRegister = await StorageHelper().get(SQLiteStorageKey.petAmount.value, Storage.SQLiteStorage) ?? '';
});
safeSetState?.call(); safeSetState?.call();
log('() => ): $devUUID');
} }
@override @override

View File

@ -35,6 +35,7 @@ class _PetsPageWidgetState extends State<PetsPageWidget> with SingleTickerProvid
void initState() { void initState() {
super.initState(); super.initState();
_model = createModel(context, () => PetsPageModel()); _model = createModel(context, () => PetsPageModel());
_model.updateOnChange = true; _model.updateOnChange = true;
_model.onUpdatePet = () { _model.onUpdatePet = () {

View File

@ -131,19 +131,23 @@ class LocalizationService {
static Future<bool> processData(BuildContext context) async { static Future<bool> processData(BuildContext context) async {
try { try {
final GetDadosCall callback = PhpGroup.getDadosCall; final GetDadosCall callback = PhpGroup.getDadosCall;
var response = await callback.call(); ApiCallResponse? response = await callback.call();
final bool? isError = response.jsonBody['error']; final bool? isError = response.jsonBody['error'];
if (isError == true || isError == 'true') { if (isError == true) {
final GetLocalsCall callback = PhpGroup.getLocalsCall;
response = await callback.call();
final String errorMsg = response.jsonBody['error_msg']; final String errorMsg = response.jsonBody['error_msg'];
DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response));
return false; return false;
} else if (response.jsonBody == null) { } else if (response.jsonBody == null) {
final GetLocalsCall callback = PhpGroup.getLocalsCall;
response = await callback.call();
final String errorMsg = FFLocalizations.of(context).getVariableText( final String errorMsg = FFLocalizations.of(context).getVariableText(
enText: 'Verify your connection', enText: 'Verify your connection',
ptText: 'Verifique sua conexão', ptText: 'Verifique sua conexão',
); );
DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response));
return false; return false;
} else { } else {
await _updateStorageUtil(response.jsonBody); await _updateStorageUtil(response.jsonBody);
@ -337,4 +341,3 @@ class LocalizationService {
await StorageHelper().set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage); await StorageHelper().set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage);
} }
} }