FIX: purge() do secureStorage após logout e auto-navegação para homePage da tela de recepção quando o status do local estava pendente
This commit is contained in:
parent
c12dbdae90
commit
94775efee4
|
@ -79,13 +79,14 @@ class _LocalProfileComponentWidgetState
|
|||
safeSetState(() {});
|
||||
return;
|
||||
} else if (error == true) {
|
||||
log('() => error: $error');
|
||||
DialogUtil.warningDefault(context).whenComplete(() => processLocals());
|
||||
safeSetState(() {});
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (e) {
|
||||
log('() => error: $e'); // Add this line to log the error
|
||||
log('() => error: $e');
|
||||
DialogUtil.warningDefault(context).whenComplete(() => processLocals());
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ class _LocalProfileComponentWidgetState
|
|||
.isNotEmpty;
|
||||
final bool isUnique = locals.length == 1;
|
||||
final bool isBlocked = locals[0]['CLU_STATUS'] == 'B';
|
||||
final bool isEnable = isUnique && isActive;
|
||||
final bool isEnabled = isUnique && isActive;
|
||||
final bool isDisabled = isUnique && isBlocked;
|
||||
final bool isSelected =
|
||||
StorageUtil().cliUUID.isEmpty && StorageUtil().cliName.isEmpty;
|
||||
|
@ -113,14 +114,17 @@ class _LocalProfileComponentWidgetState
|
|||
|
||||
if (isDisabled) {
|
||||
if (mounted) context.go('/welcomePage');
|
||||
} else if (isEnable) {
|
||||
await showModalSelectLocal();
|
||||
} else if (isEnabled) {
|
||||
StorageUtil().cliName = locals[0]['CLI_NOME'];
|
||||
StorageUtil().cliUUID = locals[0]['CLI_ID'];
|
||||
StorageUtil().ownerUUID = locals[0]['CLU_OWNER_ID'];
|
||||
} else if (isSelected) {
|
||||
await showModalSelectLocal();
|
||||
} else {
|
||||
await processData();
|
||||
}
|
||||
} catch (e) {
|
||||
log('() => error: $e');
|
||||
if (mounted) await showModalSelectLocal();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
|
|||
final List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
||||
final bool isEmpty = locals.isEmpty;
|
||||
final bool isActive = locals
|
||||
.where((local) => local['CLU_STATUS'] == 'A')
|
||||
.where((local) => local['CLU_STATUS'] != 'B')
|
||||
.toList()
|
||||
.isNotEmpty;
|
||||
final bool isEnable = !isEmpty && isActive;
|
||||
|
@ -68,7 +68,6 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
|
|||
await WidgetsBinding.instance.endOfFrame;
|
||||
dispose();
|
||||
StorageUtil().context?.go('/homePage');
|
||||
await showModalSelectLocal();
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
|
@ -145,6 +144,7 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
|
|||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
log('() => state: $state');
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
setState(() {
|
||||
processLocals();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:hub/backend/api_requests/api_calls.dart';
|
||||
import 'package:hub/backend/api_requests/api_manager.dart';
|
||||
import 'package:hub/components/templates_components/details_component/details_component_widget.dart';
|
||||
|
@ -79,37 +81,46 @@ class ScheduleCompleteVisitPageModel
|
|||
visitorJsonList[index] = updateFn(visitorJsonList[index]);
|
||||
|
||||
bool isValid() {
|
||||
if ((textController1!.text != '') &&
|
||||
(textController2!.text != '') &&
|
||||
(dropDownValue1 != null && dropDownValue1 != '') &&
|
||||
(dropDownValue2 != null && dropDownValue2 != '') &&
|
||||
(visitorStrList.isNotEmpty)) {
|
||||
DateTime selectedDateTime;
|
||||
DateTime currentDateTime = DateTime.now().subtract(Duration(minutes: 10));
|
||||
try {
|
||||
selectedDateTime =
|
||||
DateFormat('dd/MM/yyyy HH:mm:ss').parse(textController1.text);
|
||||
if (selectedDateTime.isBefore(currentDateTime)) {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedDateTime =
|
||||
DateFormat('dd/MM/yyyy HH:mm:ss').parse(textController2.text);
|
||||
if (selectedDateTime.isBefore(currentDateTime)) {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (textController1!.text.isEmpty ||
|
||||
textController2!.text.isEmpty ||
|
||||
dropDownValue1 == null ||
|
||||
dropDownValue1!.isEmpty ||
|
||||
dropDownValue2 == null ||
|
||||
dropDownValue2!.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (textController1.text.isEmpty) return false;
|
||||
if (textController2.text.isEmpty) return false;
|
||||
if (dropDownValue1 == null || dropDownValue1!.isEmpty) return false;
|
||||
if (dropDownValue2 == null || dropDownValue2!.isEmpty) return false;
|
||||
|
||||
if (visitorStrList == '[]' || visitorJsonList.isEmpty) return false;
|
||||
|
||||
DateTime selectedDateTime1;
|
||||
DateTime selectedDateTime2;
|
||||
DateTime currentDateTime =
|
||||
DateTime.now().subtract(const Duration(minutes: 10));
|
||||
|
||||
try {
|
||||
selectedDateTime1 =
|
||||
DateFormat('dd/MM/yyyy HH:mm:ss').parse(textController1.text);
|
||||
selectedDateTime2 =
|
||||
DateFormat('dd/MM/yyyy HH:mm:ss').parse(textController2.text);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (selectedDateTime1.isBefore(currentDateTime) ||
|
||||
selectedDateTime2.isBefore(currentDateTime)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (selectedDateTime1.isAfter(selectedDateTime2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
final unfocusNode = FocusNode();
|
||||
|
|
|
@ -17,11 +17,6 @@ class SharedPreferencesStorageHelper implements Storage {
|
|||
|
||||
static SharedPreferencesStorageHelper get instance => _instance;
|
||||
|
||||
bool _isFirstRun = true;
|
||||
bool get isFirstRun => _isFirstRun;
|
||||
set isFirstRun(bool value) =>
|
||||
_setAndCacheBool('milestone', value, (v) => _isFirstRun = v);
|
||||
|
||||
Future<void> _setAndCache<T>(String key, T value, Function(T) cacheSetter,
|
||||
Future<void> Function(String, T) setFunc) async {
|
||||
log('setAndCache value for key: $key to $value');
|
||||
|
@ -64,6 +59,7 @@ class SharedPreferencesStorageHelper implements Storage {
|
|||
Future<void> set(
|
||||
String key, dynamic value, Function(dynamic) cacheSetter) async {
|
||||
if (value is bool) {
|
||||
log('() => setAndCacheBool $key to $value');
|
||||
await _prefs?.setBool(key, value);
|
||||
} else if (value is String) {
|
||||
await _prefs?.setString(key, value);
|
||||
|
|
|
@ -109,8 +109,8 @@ class StorageUtil {
|
|||
|
||||
static Future<void> purge() async {
|
||||
try {
|
||||
await SecureStorageHelper().purge();
|
||||
await SharedPreferencesStorageHelper().purge();
|
||||
// await SecureStorageHelper().purge();
|
||||
// await SharedPreferencesStorageHelper().purge();
|
||||
await SQLiteStorageHelper().purge();
|
||||
} catch (e) {
|
||||
log('Error purging data: $e');
|
||||
|
@ -125,8 +125,9 @@ class StorageUtil {
|
|||
|
||||
Future<void> initSharedPreferences() async {
|
||||
_sharedPreferences.prefs ??= await SharedPreferences.getInstance();
|
||||
isFirstRun = _sharedPreferences.prefs?.getBool('milestone') ?? true;
|
||||
if (isFirstRun) {
|
||||
final bool milestone =
|
||||
_sharedPreferences.prefs?.getBool('milestone') ?? true;
|
||||
if (milestone) {
|
||||
isFirstRun = false;
|
||||
await _sharedPreferences.prefs?.setBool('milestone', false);
|
||||
_secureStorage.purge();
|
||||
|
|
Loading…
Reference in New Issue