Skip to content

Commit

Permalink
[google_maps_flutter] Platform interface for camera animation duration (
Browse files Browse the repository at this point in the history
flutter#8596)

This PR contains platform interface changes for support to adjust camera animation speed (flutter#7648).

Linked issue:  flutter/flutter#39810
Linked issue:  flutter/flutter#44284
  • Loading branch information
jokerttu authored Feb 19, 2025
1 parent da5e46d commit a9b9172
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.11.0

* Adds support for animating the camera with a duration.

## 2.10.0

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
throw UnimplementedError('animateCamera() has not been implemented.');
}

/// Starts an animated change of the map camera position using the provided
/// [CameraUpdateAnimationConfiguration].
///
/// The returned [Future] completes after the change has been started on the
/// platform side.
Future<void> animateCameraWithConfiguration(
CameraUpdate cameraUpdate,
CameraUpdateAnimationConfiguration configuration, {
required int mapId,
}) {
return animateCamera(cameraUpdate, mapId: mapId);
}

/// Changes the map camera position.
///
/// The returned [Future] completes after the change has been made on the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,16 @@ abstract class GoogleMapsInspectorPlatform extends PlatformInterface {
{required int mapId, required ClusterManagerId clusterManagerId}) {
throw UnimplementedError('getClusters() has not been implemented.');
}

/// If the platform supports getting camera position.
bool supportsGettingGameraPosition() => false;

/// Returns current camera position.
///
/// The returned object will be synthesized from platform data, so will not
/// be the same Dart object as the original [CameraPosition] provided to the
/// platform interface with map initialization or with [CameraUpdate].
Future<CameraPosition> getCameraPosition({required int mapId}) {
throw UnimplementedError('getCameraPosition() has not been implemented.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,15 @@ class CameraUpdateZoomTo extends CameraUpdate {
@override
Object toJson() => <Object>['zoomTo', zoom];
}

/// Defines an animation configuration for camera updates.
@immutable
class CameraUpdateAnimationConfiguration {
/// Creates a immutable animation configuration for camera updates.
const CameraUpdateAnimationConfiguration({this.duration});

/// The duration of the animation.
///
/// If null, the platform will decide the default value.
final Duration? duration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_maps_f
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.10.0
version: 2.11.0

environment:
sdk: ^3.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ void main() {
expect(await platform.getStyleError(mapId: 0), null);
},
);

test(
'default implementation of `animateCameraWithConfiguration` delegates to `animateCamera`',
() {
final GoogleMapsFlutterPlatform platform =
ExtendsGoogleMapsFlutterPlatform();
GoogleMapsFlutterPlatform.instance = platform;

const CameraUpdateAnimationConfiguration animationConfig =
CameraUpdateAnimationConfiguration(duration: Duration(seconds: 2));
final CameraUpdate cameraUpdate = CameraUpdate.newCameraPosition(
const CameraPosition(target: LatLng(10.0, 15.0)),
);

expect(
() => platform.animateCameraWithConfiguration(
cameraUpdate, animationConfig, mapId: 0),
throwsA(isA<UnimplementedError>().having(
(UnimplementedError e) => e.message,
'message',
contains('animateCamera() has not been implemented'))));
});
});
}

Expand Down

0 comments on commit a9b9172

Please sign in to comment.