FIX: resolução do bug de unavailableFeature após lock do OS
This commit is contained in:
parent
6c71fd8f93
commit
6b4f2ffc3f
|
@ -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 {
|
||||
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),
|
||||
|
|
|
@ -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 {
|
||||
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,
|
||||
|
|
|
@ -12,49 +12,27 @@ 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(BuildContext context) async {
|
||||
await StorageUtil().ensureInitialization();
|
||||
await LocalizationService.processLocals(context);
|
||||
return StorageUtil().cliUUID.isNotEmpty &&
|
||||
StorageUtil().cliName.isNotEmpty &&
|
||||
StorageUtil().devUUID.isNotEmpty &&
|
||||
StorageUtil().userUUID.isNotEmpty;
|
||||
}
|
||||
|
||||
Future openQRCodeScanner(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/qrCodePage',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -65,15 +43,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future openCompleteSchedule(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/scheduleCompleteVisitPage',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -84,17 +55,9 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future openDeliverySchedule(BuildContext context) async {
|
||||
final bool isProvisional = StorageUtil().provisional;
|
||||
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
if (isProvisional == true) {
|
||||
context.push(
|
||||
'/deliverySchedule',
|
||||
|
@ -109,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(context).then((value) {
|
||||
if (value) {
|
||||
if (isProvisional == true) {
|
||||
context.push(
|
||||
'/provisionalSchedule',
|
||||
|
@ -134,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(context).then((value) {
|
||||
if (value) {
|
||||
if (isWpp) {
|
||||
context.push(
|
||||
'/fastPassPage',
|
||||
|
@ -159,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',
|
||||
|
@ -190,7 +132,6 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
enText: 'Complete\nSchedule',
|
||||
),
|
||||
];
|
||||
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
|
@ -205,10 +146,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future openVisitorsRegister(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/registerVisitorPage',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -219,15 +157,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future openPoepleOnTheProperty(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/peopleOnThePropertyPage',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -238,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',
|
||||
|
@ -259,10 +185,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
content,
|
||||
() async => await AuthenticationService.signOut(context));
|
||||
}
|
||||
|
||||
Future openPreferencesSettings(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/preferencesSettings',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -273,17 +196,9 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future openMyOrders(BuildContext context) async {
|
||||
final isWpp = StorageUtil().whatsapp;
|
||||
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
if (isWpp) {
|
||||
context.push(
|
||||
'/packageOrder',
|
||||
|
@ -298,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(context).then((value) {
|
||||
if (value) {
|
||||
if (isWpp) {
|
||||
context.push(
|
||||
'/reservation',
|
||||
|
@ -323,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,
|
||||
|
@ -374,10 +276,7 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future openLiberationsHistory(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/liberationHistory',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -388,15 +287,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future openAccessHistory(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/acessHistoryPage',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -407,15 +299,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future openVisitsHistory(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/scheduleCompleteVisitPage',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -426,15 +311,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future openMessagesHistory(BuildContext context) async {
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
context.push(
|
||||
'/messageHistoryPage',
|
||||
extra: <String, dynamic>{
|
||||
|
@ -445,17 +323,9 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future openPetsRegister(BuildContext context) async {
|
||||
bool isPet = StorageUtil().pets;
|
||||
|
||||
isChecked(context).then((value) {
|
||||
if (value) {
|
||||
if (isPet) {
|
||||
context.push(
|
||||
'/petsPage',
|
||||
|
@ -470,9 +340,8 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
|
|||
} else {
|
||||
DialogUnavailable.unavailableFeature(context);
|
||||
}
|
||||
} else {
|
||||
DialogUnavailable.unavailableCredentials(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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) await LocalizationService.processLocals(context);
|
||||
else LocalizationService.processData(context);
|
||||
bool initialize = await StorageUtil().ensureInitialization();
|
||||
if(initialize) await LocalizationService.processLocals(context);
|
||||
}
|
||||
|
||||
@override Widget build(BuildContext context) {
|
||||
|
|
|
@ -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');
|
||||
|
@ -110,17 +109,19 @@ class LocalizationService {
|
|||
}
|
||||
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');
|
||||
|
@ -205,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 = '';
|
||||
|
@ -254,16 +256,11 @@ class LocalizationService {
|
|||
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'];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue