erro ao auto-validar local
This commit is contained in:
parent
114e0151cf
commit
41a2744b4a
|
@ -24,8 +24,7 @@ abstract class LocalsRemoteDataSource {
|
|||
}
|
||||
|
||||
class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
||||
static final LocalsRemoteDataSourceImpl _instance =
|
||||
LocalsRemoteDataSourceImpl._internal();
|
||||
static final LocalsRemoteDataSourceImpl _instance = LocalsRemoteDataSourceImpl._internal();
|
||||
factory LocalsRemoteDataSourceImpl() => _instance;
|
||||
LocalsRemoteDataSourceImpl._internal();
|
||||
|
||||
|
@ -51,8 +50,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
|
||||
final List<dynamic> locals = response.jsonBody['locais'] ?? [];
|
||||
final bool isEmpty = locals.isEmpty;
|
||||
final bool isActive =
|
||||
locals.where((local) => local['CLU_STATUS'] != 'B').isNotEmpty;
|
||||
final bool isActive = locals.where((local) => local['CLU_STATUS'] != 'B').isNotEmpty;
|
||||
final bool isEnable = !isEmpty && isActive;
|
||||
|
||||
if (isEnable) {
|
||||
|
@ -97,8 +95,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
final bool isInactived = await LocalUtil.isInactived(locals);
|
||||
final bool isPending = LocalUtil.isPending(locals);
|
||||
final bool isUnique = locals.length == 1;
|
||||
final bool isBlocked =
|
||||
locals.where((local) => local['CLU_STATUS'] == 'B').isNotEmpty;
|
||||
final bool isBlocked = locals.where((local) => local['CLU_STATUS'] == 'B').isNotEmpty;
|
||||
final bool isEnabled = isUnique && isActive;
|
||||
final bool isDisabled = isUnique && isBlocked;
|
||||
final bool isUnselected = await LocalUtil.isUnselected();
|
||||
|
@ -151,11 +148,11 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
|
||||
@override
|
||||
Future<bool> checkLocals(BuildContext context) async {
|
||||
String cliUUID =
|
||||
(await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
|
||||
String cliName =
|
||||
(await StorageHelper().get(ProfileStorageKey.clientName.key)) ?? '';
|
||||
return cliUUID.isEmpty && cliName.isEmpty;
|
||||
final String? cliUUID = await StorageHelper().get(ProfileStorageKey.clientUUID.key);
|
||||
final String? cliName = await StorageHelper().get(ProfileStorageKey.clientName.key);
|
||||
final haveCli = cliUUID != null && cliUUID.isNotEmpty;
|
||||
final haveName = cliName != null && cliName.isNotEmpty;
|
||||
return haveCli && haveName;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -178,8 +175,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
if (isError == true) {
|
||||
final GetLocalsCall callback = PhpGroup.getLocalsCall;
|
||||
response = await callback.call();
|
||||
final String errorMsg =
|
||||
response.jsonBody['error_msg'] ?? 'Local indisponível';
|
||||
final String errorMsg = response.jsonBody['error_msg'] ?? 'Local indisponível';
|
||||
// await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response));
|
||||
return false;
|
||||
} else {
|
||||
|
@ -198,8 +194,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<bool> selectLocal(
|
||||
BuildContext context, ApiCallResponse? response) async {
|
||||
Future<bool> selectLocal(BuildContext context, ApiCallResponse? response) async {
|
||||
return await showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
|
@ -229,15 +224,13 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
enText: 'Device unlinked successfully',
|
||||
ptText: 'Dispositivo desvinculado com sucesso',
|
||||
);
|
||||
final bool status =
|
||||
await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async {
|
||||
final bool status = await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async {
|
||||
if (value.jsonBody['error'] == false) {
|
||||
await StorageHelper().set(ProfileStorageKey.clientName.key, '');
|
||||
await StorageHelper().set(ProfileStorageKey.ownerName.key, '');
|
||||
await StorageHelper().set(ProfileStorageKey.clientUUID.key, '');
|
||||
context.pop();
|
||||
context.go('/homePage',
|
||||
extra: {'update': LocalsRepositoryImpl().update});
|
||||
context.go('/homePage', extra: {'update': LocalsRepositoryImpl().update});
|
||||
SnackBarUtil.showSnackBar(context, content);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -49,13 +49,12 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
|||
}
|
||||
|
||||
Future<void> check(BuildContext context) async {
|
||||
final String? cliUUID =
|
||||
await StorageHelper().get(ProfileStorageKey.clientUUID.key);
|
||||
final String? ownerUUID =
|
||||
await StorageHelper().get(ProfileStorageKey.ownerUUID.key);
|
||||
final String? cliUUID = await StorageHelper().get(ProfileStorageKey.clientUUID.key);
|
||||
final String? ownerUUID = await StorageHelper().get(ProfileStorageKey.ownerUUID.key);
|
||||
final bool haveCli = cliUUID != null && cliUUID.isNotEmpty;
|
||||
final bool haveOwner = ownerUUID != null && ownerUUID.isNotEmpty;
|
||||
if (!haveCli && !haveOwner) {
|
||||
log('No client or owner selected');
|
||||
await update(context);
|
||||
await FirebaseMessagingService().updateDeviceToken();
|
||||
}
|
||||
|
@ -64,7 +63,8 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
|||
Future<bool> _handleLocal(BuildContext context) async {
|
||||
bool response = false;
|
||||
final bool isUnselected = await remoteDataSource.checkLocals(context);
|
||||
if (isUnselected) {
|
||||
if (!isUnselected) {
|
||||
log('_handleLocal -> No local selected');
|
||||
while (!response) {
|
||||
try {
|
||||
response = await remoteDataSource.processLocals(context);
|
||||
|
@ -77,6 +77,8 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
log('_handleLocal -> Local selected');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,8 +54,7 @@ class App extends StatefulWidget {
|
|||
@override
|
||||
State<App> createState() => _AppState();
|
||||
|
||||
static _AppState of(BuildContext context) =>
|
||||
context.findAncestorStateOfType<_AppState>()!;
|
||||
static _AppState of(BuildContext context) => context.findAncestorStateOfType<_AppState>()!;
|
||||
}
|
||||
|
||||
class _AppState extends State<App> {
|
||||
|
@ -97,8 +96,7 @@ class _AppState extends State<App> {
|
|||
}),
|
||||
),
|
||||
);
|
||||
final Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates =
|
||||
const [
|
||||
final Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates = const [
|
||||
FFLocalizationsDelegate(),
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
|
@ -140,8 +138,7 @@ class _AppState extends State<App> {
|
|||
await StorageHelper().set(SecureStorageKey.haveLocal.value, true);
|
||||
log('onMessageOpenedApp');
|
||||
} else {
|
||||
onMessageReceived(message.data, message.notification!.body,
|
||||
message.data['click_action']);
|
||||
onMessageReceived(message.data, message.notification!.body, message.data['click_action']);
|
||||
}
|
||||
});
|
||||
FirebaseMessaging.instance.getInitialMessage().then((message) async {
|
||||
|
@ -175,9 +172,7 @@ class _AppState extends State<App> {
|
|||
_router = createRouter(_appStateNotifier);
|
||||
Future.delayed(
|
||||
const Duration(milliseconds: 1000),
|
||||
() => mounted
|
||||
? setState(() => _appStateNotifier.stopShowingSplashImage())
|
||||
: null,
|
||||
() => mounted ? setState(() => _appStateNotifier.stopShowingSplashImage()) : null,
|
||||
);
|
||||
|
||||
_setupFirebaseMessaging();
|
||||
|
|
Loading…
Reference in New Issue