Skip to content

Commit a9b9172

Browse files
authored
[google_maps_flutter] Platform interface for camera animation duration (#8596)
This PR contains platform interface changes for support to adjust camera animation speed (#7648). Linked issue: flutter/flutter#39810 Linked issue: flutter/flutter#44284
1 parent da5e46d commit a9b9172

6 files changed

Lines changed: 64 additions & 1 deletion

File tree

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.11.0
2+
3+
* Adds support for animating the camera with a duration.
4+
15
## 2.10.0
26

37
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,19 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
206206
throw UnimplementedError('animateCamera() has not been implemented.');
207207
}
208208

209+
/// Starts an animated change of the map camera position using the provided
210+
/// [CameraUpdateAnimationConfiguration].
211+
///
212+
/// The returned [Future] completes after the change has been started on the
213+
/// platform side.
214+
Future<void> animateCameraWithConfiguration(
215+
CameraUpdate cameraUpdate,
216+
CameraUpdateAnimationConfiguration configuration, {
217+
required int mapId,
218+
}) {
219+
return animateCamera(cameraUpdate, mapId: mapId);
220+
}
221+
209222
/// Changes the map camera position.
210223
///
211224
/// The returned [Future] completes after the change has been made on the

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_inspector_platform.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,16 @@ abstract class GoogleMapsInspectorPlatform extends PlatformInterface {
147147
{required int mapId, required ClusterManagerId clusterManagerId}) {
148148
throw UnimplementedError('getClusters() has not been implemented.');
149149
}
150+
151+
/// If the platform supports getting camera position.
152+
bool supportsGettingGameraPosition() => false;
153+
154+
/// Returns current camera position.
155+
///
156+
/// The returned object will be synthesized from platform data, so will not
157+
/// be the same Dart object as the original [CameraPosition] provided to the
158+
/// platform interface with map initialization or with [CameraUpdate].
159+
Future<CameraPosition> getCameraPosition({required int mapId}) {
160+
throw UnimplementedError('getCameraPosition() has not been implemented.');
161+
}
150162
}

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,15 @@ class CameraUpdateZoomTo extends CameraUpdate {
331331
@override
332332
Object toJson() => <Object>['zoomTo', zoom];
333333
}
334+
335+
/// Defines an animation configuration for camera updates.
336+
@immutable
337+
class CameraUpdateAnimationConfiguration {
338+
/// Creates a immutable animation configuration for camera updates.
339+
const CameraUpdateAnimationConfiguration({this.duration});
340+
341+
/// The duration of the animation.
342+
///
343+
/// If null, the platform will decide the default value.
344+
final Duration? duration;
345+
}

packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_maps_f
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.10.0
7+
version: 2.11.0
88

99
environment:
1010
sdk: ^3.4.0

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ void main() {
121121
expect(await platform.getStyleError(mapId: 0), null);
122122
},
123123
);
124+
125+
test(
126+
'default implementation of `animateCameraWithConfiguration` delegates to `animateCamera`',
127+
() {
128+
final GoogleMapsFlutterPlatform platform =
129+
ExtendsGoogleMapsFlutterPlatform();
130+
GoogleMapsFlutterPlatform.instance = platform;
131+
132+
const CameraUpdateAnimationConfiguration animationConfig =
133+
CameraUpdateAnimationConfiguration(duration: Duration(seconds: 2));
134+
final CameraUpdate cameraUpdate = CameraUpdate.newCameraPosition(
135+
const CameraPosition(target: LatLng(10.0, 15.0)),
136+
);
137+
138+
expect(
139+
() => platform.animateCameraWithConfiguration(
140+
cameraUpdate, animationConfig, mapId: 0),
141+
throwsA(isA<UnimplementedError>().having(
142+
(UnimplementedError e) => e.message,
143+
'message',
144+
contains('animateCamera() has not been implemented'))));
145+
});
124146
});
125147
}
126148

0 commit comments

Comments
 (0)