Skip to content

Commit

Permalink
fix: pure_extensions replacement
Browse files Browse the repository at this point in the history
Replaced pure_extensions with maps_toolkit for kuama_position
  • Loading branch information
MicheleTrevisanKuama committed Aug 29, 2024
1 parent a68c44b commit a078897
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 54 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 0 additions & 2 deletions kuama_core/lib/kuama_core.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kuama_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion kuama_permissions/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion kuama_position/lib/src/blocs/_position_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions kuama_position/lib/src/blocs/_position_state.dart
Original file line number Diff line number Diff line change
@@ -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});

Expand All @@ -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,
Expand All @@ -48,7 +48,7 @@ abstract class PositionBlocState extends Equatable {

PositionBlocState toLocated({
required bool isRealTime,
required GeoPoint currentPosition,
required LatLng currentPosition,
}) {
return PositionBlocLocated(
isRealTime: isRealTime,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions kuama_position/lib/src/blocs/position_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions kuama_position/lib/src/repositories/position_repository.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:pure_extensions/pure_extensions.dart';
import 'package:maps_toolkit/maps_toolkit.dart';

abstract class PositionRepository {
PositionRepository._();
Expand All @@ -13,8 +13,8 @@ abstract class PositionRepository {
Stream<bool> get onServiceChanges;

/// Request the current position of the user
Future<GeoPoint> get currentPosition;
Future<LatLng> get currentPosition;

/// Track the current position of the user
Stream<GeoPoint> get onPositionChanges;
Stream<LatLng> get onPositionChanges;
}
Original file line number Diff line number Diff line change
@@ -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<GeoPoint> get currentPosition async {
Future<LatLng> get currentPosition async {
final position = await geoLocator.getCurrentPosition();
return position.toGeoPoint();
}

@override
Stream<GeoPoint> get onPositionChanges async* {
Stream<LatLng> get onPositionChanges async* {
await for (final position in geoLocator.getPositionStream()) {
yield position.toGeoPoint();
}
Expand Down Expand Up @@ -43,5 +43,5 @@ class PositionRepositoryImpl implements PositionRepository {
}

extension _PositionToGeoPoint on Position {
GeoPoint toGeoPoint() => GeoPoint(latitude, longitude);
LatLng toGeoPoint() => LatLng(latitude, longitude);
}
6 changes: 3 additions & 3 deletions kuama_position/lib/src/service/position_service.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,12 +12,12 @@ class PositionService {
}

/// Request the current position of the user
Future<GeoPoint> getCurrentPosition() async {
Future<LatLng> getCurrentPosition() async {
return await locatorRepo.currentPosition;
}

/// Track the current position of the user
Stream<GeoPoint> get onPositionChanges {
Stream<LatLng> get onPositionChanges {
return locatorRepo.onPositionChanges;
}

Expand Down
4 changes: 2 additions & 2 deletions kuama_position/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 }
Expand Down
62 changes: 31 additions & 31 deletions kuama_position/test/position_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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();
Expand All @@ -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),
),
]),
);
Expand All @@ -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,
),
Expand All @@ -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 ========
Expand All @@ -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),
),
]),
);
Expand All @@ -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,
),
Expand All @@ -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),
),
]),
);
Expand All @@ -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,
),
Expand Down Expand Up @@ -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();
Expand All @@ -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),
),
]),
);
Expand All @@ -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,
),
Expand All @@ -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* {});

Expand All @@ -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),
),
]),
);
Expand Down

0 comments on commit a078897

Please sign in to comment.