Merge pull request #50 from FRE-Informatica/hotfix/lifecyclestate

Hotfix/lifecyclestate
This commit is contained in:
Ivan Antunes 2024-10-23 15:28:45 -03:00 committed by GitHub
commit 4497df1b04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 90 additions and 195 deletions

View File

@ -5,6 +5,9 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import 'package:hub/shared/utils/dialog_util.dart';
import 'package:hub/shared/utils/storage_util.dart';
import '../../../shared/extensions/dialog_extensions.dart';
import '../../../shared/services/localization/localization_service.dart';
class MenuButtonWidget extends MenuEntry {
const MenuButtonWidget({
@ -27,6 +30,8 @@ class MenuButtonWidget extends MenuEntry {
class _MenuButtonWidgetState extends State<MenuButtonWidget> {
get action => action;
bool _isProcessing = false;
@override
Widget build(BuildContext context) {
@ -35,14 +40,20 @@ class _MenuButtonWidgetState extends State<MenuButtonWidget> {
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () async {
final cliUUID = StorageUtil().cliUUID;
if (cliUUID.isEmpty) {
return DialogUtil.warningDefault(context);
} else {
await widget.action?.call();
}
onTap: _isProcessing ? null : () async {
setState(() {
_isProcessing = true;
});
await LocalizationService.processLocals(context).then((value) async {
if (value) {
await widget.action?.call();
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
setState(() {
_isProcessing = false;
});
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 0),

View File

@ -3,6 +3,9 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:hub/components/molecular_components/menu_item/menu_item.dart';
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import '../../../shared/extensions/dialog_extensions.dart';
import '../../../shared/services/localization/localization_service.dart';
class MenuCardItem extends MenuEntry {
const MenuCardItem({
super.key,
@ -24,6 +27,7 @@ class MenuCardItem extends MenuEntry {
class _MenuCardItemState extends State<MenuCardItem> {
get action => action;
bool _isProcessing = false;
@override
Widget build(BuildContext context) {
@ -32,8 +36,20 @@ class _MenuCardItemState extends State<MenuCardItem> {
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () async {
await widget.action?.call();
onTap: _isProcessing ? null : () async {
setState(() {
_isProcessing = true;
});
await LocalizationService.processLocals(context).then((value) async {
if (value) {
await widget.action?.call();
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
setState(() {
_isProcessing = false;
});
},
child: Card(
elevation: 0,

View File

@ -5,53 +5,34 @@ import 'package:hub/shared/extensions/dialog_extensions.dart';
import 'package:hub/shared/services/authentication/authentication_service.dart';
import 'package:hub/shared/utils/storage_util.dart';
import '../../../shared/services/localization/localization_service.dart';
import '/components/molecular_components/option_selection_modal/option_selection_modal_widget.dart';
import '/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart';
import '/flutter_flow/flutter_flow_util.dart';
import 'menu_component_widget.dart' show MenuComponentWidget;
class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
/// Local state fields for this component.
bool isGrid = false;
/// State fields for stateful widgets in this component.
// Model for menuListViewComponent.
late MenuListViewComponentModel menuListViewComponentModel;
// Model for menuStaggeredViewComponent.
late MenuStaggeredViewComponentModel menuStaggeredViewComponentModel;
@override
void initState(BuildContext context) {
@override void initState(BuildContext context) {
menuListViewComponentModel =
createModel(context, () => MenuListViewComponentModel());
menuStaggeredViewComponentModel =
createModel(context, () => MenuStaggeredViewComponentModel());
}
@override
void dispose() {
@override void dispose() {
menuListViewComponentModel.dispose();
menuStaggeredViewComponentModel.dispose();
}
/// Action blocks.
Future changeMenuStyle(BuildContext context) async {
isGrid = !isGrid;
}
Future<bool> isChecked() async {
return StorageUtil().cliUUID.isNotEmpty &&
StorageUtil().cliName.isNotEmpty &&
StorageUtil().devUUID.isNotEmpty &&
StorageUtil().userUUID.isNotEmpty;
}
Future openQRCodeScanner(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/qrCodePage',
extra: <String, dynamic>{
@ -62,36 +43,21 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openCompleteSchedule(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/scheduleCompleteVisitPage',
extra: <String, dynamic>{
kTransitionInfoKey: const TransitionInfo(
hasTransition: true,
transitionType: PageTransitionType.scale,
alignment: Alignment.bottomCenter,
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
context.push(
'/scheduleCompleteVisitPage',
extra: <String, dynamic>{
kTransitionInfoKey: const TransitionInfo(
hasTransition: true,
transitionType: PageTransitionType.scale,
alignment: Alignment.bottomCenter,
),
},
);
}
Future openDeliverySchedule(BuildContext context) async {
final bool isProvisional = StorageUtil().provisional;
isChecked().then((value) {
if (value) {
if (isProvisional == true) {
context.push(
'/deliverySchedule',
@ -106,17 +72,9 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
} else {
DialogUnavailable.unavailableFeature(context);
}
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
}
Future openProvisionalSchedule(BuildContext context) async {
final isProvisional = StorageUtil().provisional;
isChecked().then((value) {
if (value) {
if (isProvisional == true) {
context.push(
'/provisionalSchedule',
@ -131,17 +89,9 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
} else {
DialogUnavailable.unavailableFeature(context);
}
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openFastPassSchedule(BuildContext context) async {
final isWpp = StorageUtil().whatsapp;
isChecked().then((value) {
if (value) {
if (isWpp) {
context.push(
'/fastPassPage',
@ -156,12 +106,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
} else {
DialogUnavailable.unavailableFeature(context);
}
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future showSchedules(BuildContext context) async {
final routesListStr = <String>[
'scheduleProvisionalVisitPage',
@ -187,7 +132,6 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
enText: 'Complete\nSchedule',
),
];
await showAdaptiveDialog(
context: context,
builder: (context) {
@ -202,10 +146,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
},
);
}
Future openVisitorsRegister(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/registerVisitorPage',
extra: <String, dynamic>{
@ -216,15 +157,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openPoepleOnTheProperty(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/peopleOnThePropertyPage',
extra: <String, dynamic>{
@ -235,12 +169,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future<void> Logout(BuildContext context) async {
final String title = FFLocalizations.of(context).getVariableText(
ptText: 'Sair',
@ -256,10 +185,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
content,
() async => await AuthenticationService.signOut(context));
}
Future openPreferencesSettings(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/preferencesSettings',
extra: <String, dynamic>{
@ -270,17 +196,9 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openMyOrders(BuildContext context) async {
final isWpp = StorageUtil().whatsapp;
isChecked().then((value) {
if (value) {
if (isWpp) {
context.push(
'/packageOrder',
@ -295,17 +213,9 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
} else {
DialogUnavailable.unavailableFeature(context);
}
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openReservations(BuildContext context) async {
final isWpp = StorageUtil().whatsapp;
isChecked().then((value) {
if (value) {
if (isWpp) {
context.push(
'/reservation',
@ -320,12 +230,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
} else {
DialogUnavailable.unavailableFeature(context);
}
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future showHistories(BuildContext context) async {
await showAdaptiveDialog(
// isScrollControlled: true,
@ -371,10 +276,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
},
);
}
Future openLiberationsHistory(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/liberationHistory',
extra: <String, dynamic>{
@ -385,15 +287,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openAccessHistory(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/acessHistoryPage',
extra: <String, dynamic>{
@ -404,15 +299,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openVisitsHistory(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/scheduleCompleteVisitPage',
extra: <String, dynamic>{
@ -423,15 +311,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openMessagesHistory(BuildContext context) async {
isChecked().then((value) {
if (value) {
context.push(
'/messageHistoryPage',
extra: <String, dynamic>{
@ -442,17 +323,9 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
),
},
);
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
Future openPetsRegister(BuildContext context) async {
bool isPet = StorageUtil().pets;
isChecked().then((value) {
if (value) {
if (isPet) {
context.push(
'/petsPage',
@ -467,9 +340,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
} else {
DialogUnavailable.unavailableFeature(context);
}
} else {
DialogUnavailable.unavailableCredentials(context);
}
});
}
}

View File

@ -287,9 +287,8 @@ class _AppState extends State<App> with WidgetsBindingObserver {
}
@override void didChangeAppLifecycleState(AppLifecycleState state) async {
if (state == AppLifecycleState.resumed) await StorageUtil().ensureInitialization();
if (state == AppLifecycleState.resumed) LocalizationService.processLocals(context);
else LocalizationService.processData(context);
bool initialize = await StorageUtil().ensureInitialization();
if(initialize) await LocalizationService.processLocals(context);
}
@override Widget build(BuildContext context) {

View File

@ -45,6 +45,7 @@ class LocalizationService {
}
static Future<bool> processLocals(BuildContext context) async {
try {
await StorageUtil().ensureInitialization();
final GetLocalsCall callback = PhpGroup.getLocalsCall;
final ApiCallResponse response = await callback.call();
final bool isError = response.jsonBody['error'];
@ -85,10 +86,8 @@ class LocalizationService {
return await processData(context);
} else if (isAvailable) {
log('() => isAvailable');
await StorageUtil().ensureInitialization();
return await processData(context);
} else {
await StorageUtil().ensureInitialization();
if (!isUnique && !isActive) log('() => not unique and not active');
if (!isUnique && isInactived) log('() => not unique and inactived');
if (!isUnique && isPending) log('() => not unique and pending');
@ -99,27 +98,39 @@ class LocalizationService {
} catch (e, s) {
log('() => stack: $s');
log('() => catch: $e', stackTrace: s);
return await selectLocal(context);
// return await selectLocal(context);
final String errorMsg = FFLocalizations.of(context).getVariableText(
enText: 'Error getting locals, verify your connection',
ptText: 'Erro ao obter locais, verifique sua conexão',
);
DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context));
return false;
}
}
static Future<bool> processData(BuildContext context) async {
try {
await StorageUtil().ensureInitialization();
final GetDadosCall callback = PhpGroup.getDadosCall;
var response = await callback.call();
final error = response.jsonBody['error'];
final bool error = response.jsonBody['error'];
if (error == false) {
if (error == true || error == 'true') {
final String errorMsg = response.jsonBody['error_msg'];
DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context));
return false;
}
else {
_updateStorageUtil(response.jsonBody);
return true;
} else {
log('() => error in processData: $error');
DialogUtil.warningDefault(context).whenComplete(() => selectLocal(context));
return false;
}
} catch (e, s) {
log('() => stack processData: $s');
log('() => error processData: $e', stackTrace: s);
DialogUtil.warningDefault(context).whenComplete(() => selectLocal(context));
final String errorMsg = FFLocalizations.of(context).getVariableText(
enText: 'Error getting data, verify your connection',
ptText: 'Erro ao obter dados, verifique sua conexão',
);
DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context));
return false;
}
}
@ -195,6 +206,7 @@ class LocalizationService {
try {
StorageUtil().cliUUID = locals[0]['CLI_ID'];
StorageUtil().ownerUUID = locals[0]['CLU_OWNER_ID'];
StorageUtil().cliName = locals[0]['CLI_NOME'];
var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A');
if (response.jsonBody['error'] == true) {
StorageUtil().cliUUID = '';
@ -225,7 +237,6 @@ class LocalizationService {
log('() => CLU_STATUS: $status');
}
}
static bool _isActive(List<dynamic> locals) {
return locals.where((local) => local['CLU_STATUS'] == 'A').isNotEmpty;
}
@ -244,18 +255,12 @@ class LocalizationService {
static bool _isAvailable() {
return StorageUtil().cliUUID.isNotEmpty && StorageUtil().cliName.isNotEmpty;
}
static void _updateStorageUtil(Map<String, dynamic> jsonBody) {
final bool whatsapp = jsonBody['whatsapp'] ?? false;
final bool provisional = jsonBody['provisional'] ?? false;
final bool pets = jsonBody['pet'] ?? false;
final String petAmountRegister = jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString();
final String name = jsonBody['visitado']['VDO_NOME'];
StorageUtil().whatsapp = whatsapp;
StorageUtil().provisional = provisional;
StorageUtil().pets = pets;
StorageUtil().petAmountRegister = petAmountRegister;
StorageUtil().userName = name;
StorageUtil().whatsapp = jsonBody['whatsapp'] ?? false;
StorageUtil().provisional = jsonBody['provisional'] ?? false;
StorageUtil().pets = jsonBody['pet'] ?? false;
StorageUtil().petAmountRegister = jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString();
StorageUtil().userName = jsonBody['visitado']['VDO_NOME'];
}

View File

@ -119,20 +119,20 @@ class StorageUtil {
}
}
Future<void> ensureInitialization() async {
Future<bool> ensureInitialization() async {
try {
log('StorageUtil: Starting initialization');
if(!_initialized) return true;
await initSharedPreferences();
await initSecureStorage();
await initSQLiteStorage();
_initialized = false;
if(_initialized) _initialized = false;
if(_initialized) return true;
return false;
} catch (e, s) {
log('Error initializing storage: $e');
LogUtil.requestAPIFailed('$UniqueKey', '$UniqueKey', 'StorageUtil', e, s);
return false;
}
}
@ -218,14 +218,6 @@ class StorageUtil {
bool get isRecovered => _isRecovered;
set isRecovered(bool value) => _isRecovered = value;
String _tempMail = '';
String get tempMail => _tempMail;
set tempMail(String value) => _tempMail = value;
String _tempToken = '';
String get tempToken => _tempToken;
set tempToken(String value) => _tempToken = value;
bool _isFirstRun = true;
bool get isFirstRun => _isFirstRun;
set isFirstRun(bool value) {

View File

@ -3,7 +3,7 @@ description: A new Flutter project.
publish_to: "none"
version: 1.1.1+11
version: 1.1.2+13
environment:
sdk: ">=3.0.0 <4.0.0"