diff --git a/lib/features/local/data/data_sources/locals_remote_data_source.dart b/lib/features/local/data/data_sources/locals_remote_data_source.dart index fd91b648..0babde3a 100644 --- a/lib/features/local/data/data_sources/locals_remote_data_source.dart +++ b/lib/features/local/data/data_sources/locals_remote_data_source.dart @@ -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 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 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 selectLocal( - BuildContext context, ApiCallResponse? response) async { + Future 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; } diff --git a/lib/features/local/data/repositories/locals_repository_impl.dart b/lib/features/local/data/repositories/locals_repository_impl.dart index 232e511e..bfd8e159 100644 --- a/lib/features/local/data/repositories/locals_repository_impl.dart +++ b/lib/features/local/data/repositories/locals_repository_impl.dart @@ -49,13 +49,12 @@ class LocalsRepositoryImpl implements LocalsRepository { } Future 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 _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; } diff --git a/lib/main.dart b/lib/main.dart index 03c6b70d..8db0f7c8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -54,8 +54,7 @@ class App extends StatefulWidget { @override State createState() => _AppState(); - static _AppState of(BuildContext context) => - context.findAncestorStateOfType<_AppState>()!; + static _AppState of(BuildContext context) => context.findAncestorStateOfType<_AppState>()!; } class _AppState extends State { @@ -97,8 +96,7 @@ class _AppState extends State { }), ), ); - final Iterable>? localizationsDelegates = - const [ + final Iterable>? localizationsDelegates = const [ FFLocalizationsDelegate(), GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, @@ -140,8 +138,7 @@ class _AppState extends State { 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 { _router = createRouter(_appStateNotifier); Future.delayed( const Duration(milliseconds: 1000), - () => mounted - ? setState(() => _appStateNotifier.stopShowingSplashImage()) - : null, + () => mounted ? setState(() => _appStateNotifier.stopShowingSplashImage()) : null, ); _setupFirebaseMessaging();