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