From a0788970a604874deafbff058351252a94f5d0e3 Mon Sep 17 00:00:00 2001 From: Michele Trevisan Date: Thu, 29 Aug 2024 14:07:27 +0200 Subject: [PATCH] fix: pure_extensions replacement Replaced pure_extensions with maps_toolkit for kuama_position --- CHANGELOG.md | 3 + kuama_core/lib/kuama_core.dart | 2 - kuama_core/pubspec.yaml | 2 +- kuama_permissions/pubspec.yaml | 2 +- .../lib/src/blocs/_position_event.dart | 2 +- .../lib/src/blocs/_position_state.dart | 8 +-- .../lib/src/blocs/position_bloc.dart | 4 +- .../src/repositories/position_repository.dart | 6 +- .../position_repository_impl.dart | 8 +-- .../lib/src/service/position_service.dart | 6 +- kuama_position/pubspec.yaml | 4 +- kuama_position/test/position_bloc_test.dart | 62 +++++++++---------- 12 files changed, 55 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8515e49..b9eacda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 1.4.0 (2024-08-29) +- fix: replaced pure_extensions with maps_toolkit for kuama_position + ## 1.3.0 (2024-07-23) - chore: bumped permission_handler to `^11.3.1` - chore: changed rxdart dependency constraints to support version `>=0.27.0 <0.29.0` diff --git a/kuama_core/lib/kuama_core.dart b/kuama_core/lib/kuama_core.dart index 77cad41..cef2112 100644 --- a/kuama_core/lib/kuama_core.dart +++ b/kuama_core/lib/kuama_core.dart @@ -2,8 +2,6 @@ library kuama_core; -export 'package:tuple/tuple.dart'; - export 'src/failures/failure.dart'; export 'src/failures/failure_extensions.dart'; export 'src/identifiable.dart'; diff --git a/kuama_core/pubspec.yaml b/kuama_core/pubspec.yaml index cd51906..d4c7049 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.1 +version: 1.4.0 environment: sdk: '>=3.0.0 <4.0.0' diff --git a/kuama_permissions/pubspec.yaml b/kuama_permissions/pubspec.yaml index f6d217f..213fca1 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.1 +version: 1.4.0 environment: sdk: '>=3.0.0 <4.0.0' diff --git a/kuama_position/lib/src/blocs/_position_event.dart b/kuama_position/lib/src/blocs/_position_event.dart index 80f9ca1..75886bd 100644 --- a/kuama_position/lib/src/blocs/_position_event.dart +++ b/kuama_position/lib/src/blocs/_position_event.dart @@ -101,7 +101,7 @@ class _UnTrackPositionBloc extends _PositionBlocEvent { /// Event to update the realtime position class _EmitTrackingPositionEvent extends _PositionBlocEvent { - final GeoPoint position; + final LatLng position; const _EmitTrackingPositionEvent(this.position); diff --git a/kuama_position/lib/src/blocs/_position_state.dart b/kuama_position/lib/src/blocs/_position_state.dart index bc5840a..9a8b52b 100644 --- a/kuama_position/lib/src/blocs/_position_state.dart +++ b/kuama_position/lib/src/blocs/_position_state.dart @@ -1,7 +1,7 @@ part of 'position_bloc.dart'; abstract class PositionBlocState extends Equatable { - final GeoPoint? lastPosition; + final LatLng? lastPosition; const PositionBlocState({required this.lastPosition}); @@ -27,7 +27,7 @@ abstract class PositionBlocState extends Equatable { bool get hasLastPosition => lastPosition != null; - PositionBlocState toIdle({GeoPoint? position, bool? hasPermission, bool? isServiceEnabled}) { + PositionBlocState toIdle({LatLng? position, bool? hasPermission, bool? isServiceEnabled}) { return PositionBlocIdle( lastPosition: position ?? lastPosition, hasPermission: hasPermission ?? this.hasPermission, @@ -48,7 +48,7 @@ abstract class PositionBlocState extends Equatable { PositionBlocState toLocated({ required bool isRealTime, - required GeoPoint currentPosition, + required LatLng currentPosition, }) { return PositionBlocLocated( isRealTime: isRealTime, @@ -108,7 +108,7 @@ class PositionBlocFailed extends PositionBlocState { /// Other positions will be issued if [isRealTime] is true class PositionBlocLocated extends PositionBlocState { final bool isRealTime; - final GeoPoint currentPosition; + final LatLng currentPosition; const PositionBlocLocated({ required this.isRealTime, diff --git a/kuama_position/lib/src/blocs/position_bloc.dart b/kuama_position/lib/src/blocs/position_bloc.dart index d1a884b..8238203 100644 --- a/kuama_position/lib/src/blocs/position_bloc.dart +++ b/kuama_position/lib/src/blocs/position_bloc.dart @@ -7,7 +7,7 @@ import 'package:get_it/get_it.dart'; import 'package:kuama_core/kuama_core.dart'; import 'package:kuama_permissions/kuama_permissions.dart'; import 'package:kuama_position/src/service/position_service.dart'; -import 'package:pure_extensions/pure_extensions.dart'; +import 'package:maps_toolkit/maps_toolkit.dart'; import 'package:rxdart/rxdart.dart'; part '_position_event.dart'; @@ -28,7 +28,7 @@ class PositionBloc extends Bloc<_PositionBlocEvent, PositionBlocState> { var _realTimeListenerCount = 0; PositionBloc({ - GeoPoint? lastPosition, + LatLng? lastPosition, required PermissionsBloc permissionsBloc, }) : super(PositionBlocIdle( lastPosition: lastPosition, diff --git a/kuama_position/lib/src/repositories/position_repository.dart b/kuama_position/lib/src/repositories/position_repository.dart index ad9a93f..6fce8b4 100644 --- a/kuama_position/lib/src/repositories/position_repository.dart +++ b/kuama_position/lib/src/repositories/position_repository.dart @@ -1,4 +1,4 @@ -import 'package:pure_extensions/pure_extensions.dart'; +import 'package:maps_toolkit/maps_toolkit.dart'; abstract class PositionRepository { PositionRepository._(); @@ -13,8 +13,8 @@ abstract class PositionRepository { Stream get onServiceChanges; /// Request the current position of the user - Future get currentPosition; + Future get currentPosition; /// Track the current position of the user - Stream get onPositionChanges; + Stream get onPositionChanges; } diff --git a/kuama_position/lib/src/repositories/position_repository_impl.dart b/kuama_position/lib/src/repositories/position_repository_impl.dart index 745fc34..fb74480 100644 --- a/kuama_position/lib/src/repositories/position_repository_impl.dart +++ b/kuama_position/lib/src/repositories/position_repository_impl.dart @@ -1,19 +1,19 @@ import 'package:geolocator_platform_interface/geolocator_platform_interface.dart'; import 'package:get_it/get_it.dart'; import 'package:kuama_position/src/repositories/position_repository.dart'; -import 'package:pure_extensions/pure_extensions.dart'; +import 'package:maps_toolkit/maps_toolkit.dart'; class PositionRepositoryImpl implements PositionRepository { final GeolocatorPlatform geoLocator = GetIt.I(); @override - Future get currentPosition async { + Future get currentPosition async { final position = await geoLocator.getCurrentPosition(); return position.toGeoPoint(); } @override - Stream get onPositionChanges async* { + Stream get onPositionChanges async* { await for (final position in geoLocator.getPositionStream()) { yield position.toGeoPoint(); } @@ -43,5 +43,5 @@ class PositionRepositoryImpl implements PositionRepository { } extension _PositionToGeoPoint on Position { - GeoPoint toGeoPoint() => GeoPoint(latitude, longitude); + LatLng toGeoPoint() => LatLng(latitude, longitude); } diff --git a/kuama_position/lib/src/service/position_service.dart b/kuama_position/lib/src/service/position_service.dart index 59c2e32..7230adb 100644 --- a/kuama_position/lib/src/service/position_service.dart +++ b/kuama_position/lib/src/service/position_service.dart @@ -1,6 +1,6 @@ import 'package:get_it/get_it.dart'; import 'package:kuama_position/src/repositories/position_repository.dart'; -import 'package:pure_extensions/pure_extensions.dart'; +import 'package:maps_toolkit/maps_toolkit.dart'; // TODO: Handle exception in geolocator_platform_interface/src/implementations/method_channel_geolocator.dart:229 class PositionService { @@ -12,12 +12,12 @@ class PositionService { } /// Request the current position of the user - Future getCurrentPosition() async { + Future getCurrentPosition() async { return await locatorRepo.currentPosition; } /// Track the current position of the user - Stream get onPositionChanges { + Stream get onPositionChanges { return locatorRepo.onPositionChanges; } diff --git a/kuama_position/pubspec.yaml b/kuama_position/pubspec.yaml index 4ba2eb8..3555a69 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.3.1 +version: 1.4.0 environment: sdk: '>=3.0.0 <4.0.0' @@ -31,10 +31,10 @@ dependencies: get_it: # Version defined in kuama_core rxdart: '>=0.27.0 <0.29.0' - pure_extensions: ^5.0.0 bloc: ^8.1.1 bloc_concurrency: ^0.2.1 equatable: ^2.0.5 + maps_toolkit: ^3.0.0 dependency_overrides: kuama_core: { path: ../kuama_core } diff --git a/kuama_position/test/position_bloc_test.dart b/kuama_position/test/position_bloc_test.dart index 57f03aa..d2c7b5c 100644 --- a/kuama_position/test/position_bloc_test.dart +++ b/kuama_position/test/position_bloc_test.dart @@ -3,8 +3,8 @@ import 'package:get_it/get_it.dart'; import 'package:kuama_permissions/kuama_permissions.dart'; import 'package:kuama_position/src/blocs/position_bloc.dart'; import 'package:kuama_position/src/service/position_service.dart'; +import 'package:maps_toolkit/maps_toolkit.dart'; import 'package:mocktail/mocktail.dart'; -import 'package:pure_extensions/pure_extensions.dart'; class _MockPositionService extends Mock implements PositionService {} @@ -122,7 +122,7 @@ void main() { init(permission: EmissionType.alreadyHas, service: EmissionType.alreadyHas); when(() => mockPositionService.getCurrentPosition()).thenAnswer((_) async { - return const GeoPoint(0.0, 0.0); + return LatLng(0.0, 0.0); }); bloc.locate(); @@ -134,9 +134,9 @@ void main() { isRealTime: false, lastPosition: null, ), - const PositionBlocLocated( + PositionBlocLocated( isRealTime: false, - currentPosition: GeoPoint(0.0, 0.0), + currentPosition: LatLng(0.0, 0.0), ), ]), ); @@ -146,8 +146,8 @@ void main() { expect( bloc.stream, emitsInOrder([ - const PositionBlocIdle( - lastPosition: GeoPoint(0.0, 0.0), + PositionBlocIdle( + lastPosition: LatLng(0.0, 0.0), hasPermission: true, isServiceEnabled: true, ), @@ -162,11 +162,11 @@ void main() { init(permission: EmissionType.alreadyHas, service: EmissionType.alreadyHas); when(() => mockPositionService.getCurrentPosition()).thenAnswer((_) async { - return const GeoPoint(0.0, 0.0); + return LatLng(0.0, 0.0); }); when(() => mockPositionService.onPositionChanges).thenAnswer((_) async* { await Future.delayed(Duration.zero); - yield const GeoPoint(1.0, 1.0); + yield LatLng(1.0, 1.0); }); // ======== Test user tracking ======== @@ -180,13 +180,13 @@ void main() { isRealTime: true, lastPosition: null, ), - const PositionBlocLocated( + PositionBlocLocated( isRealTime: true, - currentPosition: GeoPoint(0.0, 0.0), + currentPosition: LatLng(0.0, 0.0), ), - const PositionBlocLocated( + PositionBlocLocated( isRealTime: true, - currentPosition: GeoPoint(1.0, 1.0), + currentPosition: LatLng(1.0, 1.0), ), ]), ); @@ -196,8 +196,8 @@ void main() { await expectLater( bloc.stream, emitsInOrder([ - const PositionBlocIdle( - lastPosition: GeoPoint(1.0, 1.0), + PositionBlocIdle( + lastPosition: LatLng(1.0, 1.0), hasPermission: true, isServiceEnabled: true, ), @@ -211,17 +211,17 @@ void main() { await expectLater( bloc.stream, emitsInOrder([ - const PositionBlocLocating( + PositionBlocLocating( isRealTime: true, - lastPosition: GeoPoint(1.0, 1.0), + lastPosition: LatLng(1.0, 1.0), ), - const PositionBlocLocated( + PositionBlocLocated( isRealTime: true, - currentPosition: GeoPoint(0.0, 0.0), + currentPosition: LatLng(0.0, 0.0), ), - const PositionBlocLocated( + PositionBlocLocated( isRealTime: true, - currentPosition: GeoPoint(1.0, 1.0), + currentPosition: LatLng(1.0, 1.0), ), ]), ); @@ -231,8 +231,8 @@ void main() { await expectLater( bloc.stream, emitsInOrder([ - const PositionBlocIdle( - lastPosition: GeoPoint(1.0, 1.0), + PositionBlocIdle( + lastPosition: LatLng(1.0, 1.0), hasPermission: true, isServiceEnabled: true, ), @@ -260,10 +260,10 @@ void main() { )); when(() => mockPositionService.getCurrentPosition()).thenAnswer((_) async { - return const GeoPoint(0.0, 0.0); + return LatLng(0.0, 0.0); }); when(() => mockPositionService.onPositionChanges).thenAnswer((_) async* { - yield const GeoPoint(0.0, 0.0); + yield LatLng(0.0, 0.0); }); bloc.track(); @@ -277,9 +277,9 @@ void main() { isRealTime: true, lastPosition: null, ), - const PositionBlocLocated( + PositionBlocLocated( isRealTime: true, - currentPosition: GeoPoint(0.0, 0.0), + currentPosition: LatLng(0.0, 0.0), ), ]), ); @@ -293,8 +293,8 @@ void main() { await expectLater( bloc.stream, emitsInOrder([ - const PositionBlocIdle( - lastPosition: GeoPoint(0.0, 0.0), + PositionBlocIdle( + lastPosition: LatLng(0.0, 0.0), hasPermission: true, isServiceEnabled: true, ), @@ -313,7 +313,7 @@ void main() { test('Emit real time position after bloc is initialized but track request before it', () async { when(() => mockPositionService.getCurrentPosition()).thenAnswer((_) async { - return const GeoPoint(0.0, 0.0); + return LatLng(0.0, 0.0); }); when(() => mockPositionService.onPositionChanges).thenAnswer((_) async* {}); @@ -333,9 +333,9 @@ void main() { isRealTime: true, lastPosition: null, ), - const PositionBlocLocated( + PositionBlocLocated( isRealTime: true, - currentPosition: GeoPoint(0.0, 0.0), + currentPosition: LatLng(0.0, 0.0), ), ]), );