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