From a68c44b96fd4fbbb3d2cec85fa63635bcbda49f6 Mon Sep 17 00:00:00 2001 From: BreX900 Date: Fri, 2 Aug 2024 16:24:59 +0200 Subject: [PATCH] chore: Failure implement Exception chore: upgraded mek_lints package --- .gitignore | 2 + kuama_core/lib/src/failures/failure.dart | 2 +- kuama_core/pubspec.yaml | 4 +- kuama_permissions/build.yaml | 3 + .../lib/src/blocs/_permissions_event.dart | 1 + .../lib/src/blocs/_permissions_state.dart | 86 +++++++------------ .../lib/src/blocs/permissions_bloc.b.dart | 1 + .../lib/src/blocs/permissions_bloc.b.g.dart | 4 +- .../permissions_status_entity.b.g.dart | 2 + .../app_lifecycle_state_repository.dart | 5 +- .../permissions_manger_repository.dart | 2 +- .../lib/src/services/permissions_service.dart | 2 +- kuama_permissions/pubspec.yaml | 6 +- .../test/blocs/permissions_bloc_test.dart | 12 +-- .../services/permissions_service_test.dart | 4 +- kuama_permissions/test/t_utils.dart | 1 + .../lib/src/blocs/_position_event.dart | 2 +- .../lib/src/blocs/_position_state.dart | 14 +-- .../lib/src/blocs/position_bloc.dart | 5 +- .../position_repository_impl.dart | 2 - kuama_position/pubspec.yaml | 8 +- kuama_position/test/position_bloc_test.dart | 2 +- 22 files changed, 80 insertions(+), 90 deletions(-) diff --git a/.gitignore b/.gitignore index aa81699..c7f5e9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +**/.DS_Store + # IntelliJ related *.iml *.ipr diff --git a/kuama_core/lib/src/failures/failure.dart b/kuama_core/lib/src/failures/failure.dart index 95ca2f8..dd436a0 100644 --- a/kuama_core/lib/src/failures/failure.dart +++ b/kuama_core/lib/src/failures/failure.dart @@ -9,7 +9,7 @@ class ExceptionCaught { } /// Maintainers: Keep same structure as [Error]/[Exception] -abstract class Failure { +abstract class Failure implements Exception { final ExceptionCaught? exceptionCaught; Failure({required this.exceptionCaught}); diff --git a/kuama_core/pubspec.yaml b/kuama_core/pubspec.yaml index 1186a76..cd51906 100644 --- a/kuama_core/pubspec.yaml +++ b/kuama_core/pubspec.yaml @@ -1,7 +1,7 @@ name: kuama_core description: A starting point for Dart libraries or applications. publish_to: 'none' -version: 1.3.0 +version: 1.3.1 environment: sdk: '>=3.0.0 <4.0.0' @@ -15,7 +15,7 @@ dependencies: rxdart: '>=0.27.0 <0.29.0' dev_dependencies: - mek_lints: ^1.0.0 + mek_lints: ^4.0.0 test: ^1.21.1 diff --git a/kuama_permissions/build.yaml b/kuama_permissions/build.yaml index 0e28494..e2cfd98 100644 --- a/kuama_permissions/build.yaml +++ b/kuama_permissions/build.yaml @@ -2,6 +2,9 @@ targets: $default: builders: source_gen:combining_builder: + options: + ignore_for_file: + - unnecessary_parenthesis generate_for: exclude: - test diff --git a/kuama_permissions/lib/src/blocs/_permissions_event.dart b/kuama_permissions/lib/src/blocs/_permissions_event.dart index f943dda..149c280 100644 --- a/kuama_permissions/lib/src/blocs/_permissions_event.dart +++ b/kuama_permissions/lib/src/blocs/_permissions_event.dart @@ -70,6 +70,7 @@ class _AskPermissionsEvent extends _PermissionsBlocEvent with _$_AskPermissionsE class _ConfirmAskPermissionsEvent extends _PermissionsBlocEvent with _$_ConfirmAskPermissionsEvent { final bool? canRequest; + // ignore: avoid_positional_boolean_parameters _ConfirmAskPermissionsEvent(this.canRequest); @override diff --git a/kuama_permissions/lib/src/blocs/_permissions_state.dart b/kuama_permissions/lib/src/blocs/_permissions_state.dart index 6127f37..2a60166 100644 --- a/kuama_permissions/lib/src/blocs/_permissions_state.dart +++ b/kuama_permissions/lib/src/blocs/_permissions_state.dart @@ -49,7 +49,7 @@ abstract class PermissionsBlocState with _$PermissionsBlocState { final isAllEnabled = permissions .map((e) => e.toService()) .whereNotNull() - .every((element) => servicesStatus[element] == true); + .every((element) => servicesStatus[element] ?? false); if (!isAllEnabled) return true; return permissions.any((permission) { return permissionsStatus[permission] != PermissionStatus.granted; @@ -235,15 +235,11 @@ class CheckingPermissionState extends PermissionsBlocState with _$CheckingPermis final Set payload; const CheckingPermissionState({ - required bool isRefreshing, - required Map permissionsStatus, - required Map servicesStatus, + required super.isRefreshing, + required super.permissionsStatus, + required super.servicesStatus, required this.payload, - }) : super( - isRefreshing: isRefreshing, - permissionsStatus: permissionsStatus, - servicesStatus: servicesStatus, - ); + }); @override bool get isLoading => true; @@ -267,15 +263,11 @@ class CheckedPermissionState extends PermissionsBlocState with _$CheckedPermissi final Set payload; const CheckedPermissionState({ - required bool isRefreshing, - required Map permissionsStatus, - required Map servicesStatus, + required super.isRefreshing, + required super.permissionsStatus, + required super.servicesStatus, required this.payload, - }) : super( - isRefreshing: isRefreshing, - permissionsStatus: permissionsStatus, - servicesStatus: servicesStatus, - ); + }); @override bool get isLoading => false; @@ -299,15 +291,11 @@ class RequestingPermissionsState extends PermissionsBlocState with _$RequestingP final Set payload; const RequestingPermissionsState({ - required bool isRefreshing, - required Map permissionsStatus, - required Map servicesStatus, + required super.isRefreshing, + required super.permissionsStatus, + required super.servicesStatus, required this.payload, - }) : super( - isRefreshing: isRefreshing, - permissionsStatus: permissionsStatus, - servicesStatus: servicesStatus, - ); + }); @override bool get isLoading => true; @@ -334,16 +322,12 @@ class RequestedPermissionsState extends PermissionsBlocState with _$RequestedPer final bool isRequested; const RequestedPermissionsState({ - required bool isRefreshing, - required Map permissionsStatus, - required Map servicesStatus, + required super.isRefreshing, + required super.permissionsStatus, + required super.servicesStatus, required this.payload, required this.isRequested, - }) : super( - isRefreshing: isRefreshing, - permissionsStatus: permissionsStatus, - servicesStatus: servicesStatus, - ); + }); @override bool get isLoading => false; @@ -367,15 +351,11 @@ class AskingPermissionsState extends PermissionsBlocState with _$AskingPermissio final Set payload; const AskingPermissionsState({ - required bool isRefreshing, - required Map permissionsStatus, - required Map servicesStatus, + required super.isRefreshing, + required super.permissionsStatus, + required super.servicesStatus, required this.payload, - }) : super( - isRefreshing: isRefreshing, - permissionsStatus: permissionsStatus, - servicesStatus: servicesStatus, - ); + }); @override bool get isLoading => true; @@ -403,16 +383,12 @@ class ConfirmableAskPermissionsState extends PermissionsBlocState final bool isRestored; const ConfirmableAskPermissionsState({ - required bool isRefreshing, - required Map permissionsStatus, - required Map servicesStatus, + required super.isRefreshing, + required super.permissionsStatus, + required super.servicesStatus, required this.payload, required this.isRestored, - }) : super( - isRefreshing: isRefreshing, - permissionsStatus: permissionsStatus, - servicesStatus: servicesStatus, - ); + }); @override bool get isLoading => false; @@ -441,17 +417,13 @@ class AskedPermissionsState extends PermissionsBlocState with _$AskedPermissions final bool isRequested; const AskedPermissionsState({ - required bool isRefreshing, - required Map permissionsStatus, - required Map servicesStatus, + required super.isRefreshing, + required super.permissionsStatus, + required super.servicesStatus, required this.payload, required this.isCancelled, required this.isRequested, - }) : super( - isRefreshing: isRefreshing, - permissionsStatus: permissionsStatus, - servicesStatus: servicesStatus, - ); + }); @override bool get isLoading => false; diff --git a/kuama_permissions/lib/src/blocs/permissions_bloc.b.dart b/kuama_permissions/lib/src/blocs/permissions_bloc.b.dart index dfe7752..d96b491 100644 --- a/kuama_permissions/lib/src/blocs/permissions_bloc.b.dart +++ b/kuama_permissions/lib/src/blocs/permissions_bloc.b.dart @@ -88,6 +88,7 @@ class PermissionsBloc extends Bloc<_PermissionsBlocEvent, PermissionsBlocState> /// If `null`, the request is discarded. /// /// Note: The confirmation may be completed after a refresh. See [PermissionsBlocState.isRefreshing]. + // ignore: avoid_positional_boolean_parameters void confirmAsk(bool? canRequest) => add(_ConfirmAskPermissionsEvent(canRequest)); Future _onEvent(_PermissionsBlocEvent event, Emitter emit) async { diff --git a/kuama_permissions/lib/src/blocs/permissions_bloc.b.g.dart b/kuama_permissions/lib/src/blocs/permissions_bloc.b.g.dart index f333916..b07757a 100644 --- a/kuama_permissions/lib/src/blocs/permissions_bloc.b.g.dart +++ b/kuama_permissions/lib/src/blocs/permissions_bloc.b.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unnecessary_parenthesis + part of 'permissions_bloc.b.dart'; // ************************************************************************** @@ -41,7 +43,7 @@ mixin _$_ConfirmAskPermissionsEvent { mixin _$_RefreshPermissionsEvent { @override - String toString() => (ClassToString('_RefreshPermissionsEvent')).toString(); + String toString() => ClassToString('_RefreshPermissionsEvent').toString(); } mixin _$PermissionsBlocState { diff --git a/kuama_permissions/lib/src/entities/permissions_status_entity.b.g.dart b/kuama_permissions/lib/src/entities/permissions_status_entity.b.g.dart index 5dc893a..5c87b51 100644 --- a/kuama_permissions/lib/src/entities/permissions_status_entity.b.g.dart +++ b/kuama_permissions/lib/src/entities/permissions_status_entity.b.g.dart @@ -1,5 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unnecessary_parenthesis + part of 'permissions_status_entity.b.dart'; // ************************************************************************** diff --git a/kuama_permissions/lib/src/repositories/app_lifecycle_state_repository.dart b/kuama_permissions/lib/src/repositories/app_lifecycle_state_repository.dart index b9349c2..541848a 100644 --- a/kuama_permissions/lib/src/repositories/app_lifecycle_state_repository.dart +++ b/kuama_permissions/lib/src/repositories/app_lifecycle_state_repository.dart @@ -9,13 +9,14 @@ class AppLifecycleStateRepository { WidgetsBindingObserver? _observer; static AppLifecycleStateRepository? _instance; - AppLifecycleStateRepository._(); /// It is a singleton because only one observer should exist factory AppLifecycleStateRepository() { return _instance ??= AppLifecycleStateRepository._(); } + AppLifecycleStateRepository._(); + Stream get onChanges { _subject ??= StreamController.broadcast( sync: true, @@ -29,6 +30,8 @@ class AppLifecycleStateRepository { return _subject!.stream; } + + void dispose() => unawaited(_subject?.close()); } class _Observer extends WidgetsBindingObserver { diff --git a/kuama_permissions/lib/src/repositories/permissions_manger_repository.dart b/kuama_permissions/lib/src/repositories/permissions_manger_repository.dart index f93a5e9..d416fbe 100644 --- a/kuama_permissions/lib/src/repositories/permissions_manger_repository.dart +++ b/kuama_permissions/lib/src/repositories/permissions_manger_repository.dart @@ -5,7 +5,7 @@ import 'package:permission_handler_platform_interface/permission_handler_platfor class PermissionsManagerRepository { PermissionHandlerPlatform get _handler => GetIt.I(); - /// Returns [true] if the app settings page could be opened, otherwise [false]. + /// Returns `true` if the app settings page could be opened, otherwise `false`. Future openAppSettings() async { return await _handler.openAppSettings(); } diff --git a/kuama_permissions/lib/src/services/permissions_service.dart b/kuama_permissions/lib/src/services/permissions_service.dart index 2b4856e..0787579 100644 --- a/kuama_permissions/lib/src/services/permissions_service.dart +++ b/kuama_permissions/lib/src/services/permissions_service.dart @@ -83,7 +83,7 @@ class PermissionsService { } Stream get onRequiredPermissionsRefresh async* { - AppLifecycleState prevState = AppLifecycleState.paused; + var prevState = AppLifecycleState.paused; await for (final state in _appLifecycleState.onChanges) { if (prevState != AppLifecycleState.resumed && prevState != AppLifecycleState.inactive && diff --git a/kuama_permissions/pubspec.yaml b/kuama_permissions/pubspec.yaml index 893ef52..f6d217f 100644 --- a/kuama_permissions/pubspec.yaml +++ b/kuama_permissions/pubspec.yaml @@ -1,7 +1,7 @@ name: kuama_permissions description: A starting point for Dart libraries or applications. publish_to: 'none' -version: 1.3.0 +version: 1.3.1 environment: sdk: '>=3.0.0 <4.0.0' @@ -20,7 +20,7 @@ dependencies: git: url: https://github.com/Kuama-IT/kuama_dart.git path: kuama_core - ref: 1.3.0 + ref: 1.3.1 permission_handler_platform_interface: ^4.2.1 permission_handler: ^11.3.1 @@ -36,7 +36,7 @@ dependencies: mek_data_class: ^1.4.0 dev_dependencies: - mek_lints: ^1.0.0 + mek_lints: ^4.0.0 flutter_test: { sdk: flutter } diff --git a/kuama_permissions/test/blocs/permissions_bloc_test.dart b/kuama_permissions/test/blocs/permissions_bloc_test.dart index afbdce8..6d9b229 100644 --- a/kuama_permissions/test/blocs/permissions_bloc_test.dart +++ b/kuama_permissions/test/blocs/permissions_bloc_test.dart @@ -38,9 +38,9 @@ void main() { bloc = PermissionsBloc(); }); - tearDown(GetIt.instance.reset); + tearDown(() async => Future.wait([GetIt.instance.reset(), onRequiredPermissionsRefresh.close()])); - group("PermissionsBloc", () { + group('PermissionsBloc', () { const tPermission1 = Permission.storage; const tPermission2 = Permission.camera; const tPermissionService = Permission.location; @@ -49,7 +49,7 @@ void main() { group('PermissionsBloc.check', () { test('cant check because cant operate', () { bloc.emit(mockState); - var state = bloc.state; + final state = bloc.state; when(() => mockState.checkCanCheck(any())).thenReturn(false); @@ -123,7 +123,7 @@ void main() { group('PermissionsBloc.request', () { test('cant request because cant operate', () { bloc.emit(mockState); - var state = bloc.state; + final state = bloc.state; when(() => mockState.checkCanRequest(any())).thenReturn(false); @@ -207,7 +207,7 @@ void main() { group('PermissionsBloc.confirmAsk', () { test('cant confirm ask because cant operate', () { bloc.emit(mockState); - var state = bloc.state; + final state = bloc.state; when(() => mockState.checkCanConfirmAsk(any())).thenReturn(false); @@ -305,7 +305,7 @@ void main() { group('PermissionsBloc.ask', () { test('cant ask because cant operate', () { bloc.emit(mockState); - var state = bloc.state; + final state = bloc.state; when(() => mockState.checkCanAsk(any())).thenReturn(false); diff --git a/kuama_permissions/test/services/permissions_service_test.dart b/kuama_permissions/test/services/permissions_service_test.dart index 639cece..0ef3b43 100644 --- a/kuama_permissions/test/services/permissions_service_test.dart +++ b/kuama_permissions/test/services/permissions_service_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid_implementing_value_types + import 'package:flutter_test/flutter_test.dart'; import 'package:get_it/get_it.dart'; import 'package:kuama_permissions/src/entities/permissions_status_entity.b.dart'; @@ -35,7 +37,7 @@ void main() { tearDown(GetIt.instance.reset); - group("PermissionsService", () { + group('PermissionsService', () { const tPermission1 = Permission.storage; const tService = Permission.locationWhenInUse; diff --git a/kuama_permissions/test/t_utils.dart b/kuama_permissions/test/t_utils.dart index 1253597..f7e2e3b 100644 --- a/kuama_permissions/test/t_utils.dart +++ b/kuama_permissions/test/t_utils.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:meta/meta.dart'; +// ignore: avoid_void_async void after(void Function() fn) async { await Future.delayed(const Duration(milliseconds: 1)); fn(); diff --git a/kuama_position/lib/src/blocs/_position_event.dart b/kuama_position/lib/src/blocs/_position_event.dart index addc2cb..80f9ca1 100644 --- a/kuama_position/lib/src/blocs/_position_event.dart +++ b/kuama_position/lib/src/blocs/_position_event.dart @@ -21,7 +21,7 @@ class _UpdateStatusEvent extends _PositionBlocEvent { final bool hasPermissionGranted; final bool isServiceEnabled; - const _UpdateStatusEvent(this.hasPermissionGranted, this.isServiceEnabled); + const _UpdateStatusEvent({required this.hasPermissionGranted, required this.isServiceEnabled}); @override R map({ diff --git a/kuama_position/lib/src/blocs/_position_state.dart b/kuama_position/lib/src/blocs/_position_state.dart index 7f0a431..bc5840a 100644 --- a/kuama_position/lib/src/blocs/_position_state.dart +++ b/kuama_position/lib/src/blocs/_position_state.dart @@ -21,7 +21,7 @@ abstract class PositionBlocState extends Equatable { return true; } - /// Check if you can call [PositionBloc.localize]. + /// Check if you can call [PositionBloc.locate]. /// You must have permission and active service bool get canLocalize => hasPermission && isServiceEnabled; @@ -69,10 +69,10 @@ class PositionBlocIdle extends PositionBlocState { final bool isServiceEnabled; const PositionBlocIdle({ - required GeoPoint? lastPosition, + required super.lastPosition, required this.hasPermission, required this.isServiceEnabled, - }) : super(lastPosition: lastPosition); + }); @override List get props => [lastPosition, hasPermission, isServiceEnabled]; @@ -83,9 +83,9 @@ class PositionBlocLocating extends PositionBlocState { final bool isRealTime; const PositionBlocLocating({ - required GeoPoint? lastPosition, + required super.lastPosition, required this.isRealTime, - }) : super(lastPosition: lastPosition); + }); @override List get props => [lastPosition, isRealTime]; @@ -96,9 +96,9 @@ class PositionBlocFailed extends PositionBlocState { final Failure failure; const PositionBlocFailed({ - required GeoPoint? lastPosition, + required super.lastPosition, required this.failure, - }) : super(lastPosition: lastPosition); + }); @override List get props => [lastPosition, failure]; diff --git a/kuama_position/lib/src/blocs/position_bloc.dart b/kuama_position/lib/src/blocs/position_bloc.dart index 58a58ba..d1a884b 100644 --- a/kuama_position/lib/src/blocs/position_bloc.dart +++ b/kuama_position/lib/src/blocs/position_bloc.dart @@ -79,7 +79,10 @@ class PositionBloc extends Bloc<_PositionBlocEvent, PositionBlocState> { permissionBloc.stream.listen((state) { final hasPermissionGranted = state.checkAny(permissions, PermissionStatus.granted); final isServiceEnabled = state.checkService(Service.location); - add(_UpdateStatusEvent(hasPermissionGranted, isServiceEnabled)); + add(_UpdateStatusEvent( + hasPermissionGranted: hasPermissionGranted, + isServiceEnabled: isServiceEnabled, + )); }, onError: onError).addTo(_initSubs); } diff --git a/kuama_position/lib/src/repositories/position_repository_impl.dart b/kuama_position/lib/src/repositories/position_repository_impl.dart index 17b9e9c..745fc34 100644 --- a/kuama_position/lib/src/repositories/position_repository_impl.dart +++ b/kuama_position/lib/src/repositories/position_repository_impl.dart @@ -30,10 +30,8 @@ class PositionRepositoryImpl implements PositionRepository { switch (status) { case ServiceStatus.disabled: yield false; - break; case ServiceStatus.enabled: yield true; - break; } } } diff --git a/kuama_position/pubspec.yaml b/kuama_position/pubspec.yaml index 502ca69..4ba2eb8 100644 --- a/kuama_position/pubspec.yaml +++ b/kuama_position/pubspec.yaml @@ -1,7 +1,7 @@ name: kuama_position description: A new Flutter project. publish_to: 'none' -version: 1.2.0 +version: 1.3.1 environment: sdk: '>=3.0.0 <4.0.0' @@ -18,12 +18,12 @@ dependencies: git: url: https://github.com/Kuama-IT/kuama_dart.git path: kuama_core - ref: 1.3.0 + ref: 1.3.1 kuama_permissions: git: url: https://github.com/Kuama-IT/kuama_dart.git path: kuama_permissions - ref: 1.3.0 + ref: 1.3.1 geolocator_platform_interface: ^4.2.4 @@ -41,7 +41,7 @@ dependency_overrides: kuama_permissions: { path: ../kuama_permissions } dev_dependencies: - mek_lints: ^1.0.0 + mek_lints: ^4.0.0 flutter_test: { sdk: flutter } diff --git a/kuama_position/test/position_bloc_test.dart b/kuama_position/test/position_bloc_test.dart index cb30e0a..57f03aa 100644 --- a/kuama_position/test/position_bloc_test.dart +++ b/kuama_position/test/position_bloc_test.dart @@ -165,7 +165,7 @@ void main() { return const GeoPoint(0.0, 0.0); }); when(() => mockPositionService.onPositionChanges).thenAnswer((_) async* { - await Future.delayed(const Duration()); + await Future.delayed(Duration.zero); yield const GeoPoint(1.0, 1.0); });