Skip to content

Commit eda1f3c

Browse files
stuartmorgan-gadsonpleal
authored andcommitted
[google_maps_flutter] Fix CameraPosition regression (flutter#3547)
The nullability conversion added a type check when recreating a CameraPosition from JSON that was too restrictive, and regressed the app-facing package. This relaxes that assertion, and adds a test to catch the issue.
1 parent 0d3c9a1 commit eda1f3c

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

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.0.0-nullsafety.1
2+
3+
* Fix overly-restrictive type check.
4+
15
## 2.0.0-nullsafety
26

37
* Migrated to null-safety.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class CameraPosition {
7272
///
7373
/// Mainly for internal use.
7474
static CameraPosition? fromMap(Object? json) {
75-
if (json == null || !(json is Map<String, dynamic>)) {
75+
if (json == null || !(json is Map<dynamic, dynamic>)) {
7676
return null;
7777
}
7878
final LatLng? target = LatLng.fromJson(json['target']);

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
@@ -3,7 +3,7 @@ description: A common platform interface for the google_maps_flutter plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 2.0.0-nullsafety
6+
version: 2.0.0-nullsafety.1
77

88
dependencies:
99
flutter:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
7+
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
8+
9+
void main() {
10+
TestWidgetsFlutterBinding.ensureInitialized();
11+
12+
test('toMap / fromMap', () {
13+
final cameraPosition = CameraPosition(
14+
target: LatLng(10.0, 15.0), bearing: 0.5, tilt: 30.0, zoom: 1.5);
15+
// Cast to <dynamic, dynamic> to ensure that recreating from JSON, where
16+
// type information will have likely been lost, still works.
17+
final json = (cameraPosition.toMap() as Map<String, dynamic>)
18+
.cast<dynamic, dynamic>();
19+
final cameraPositionFromJson = CameraPosition.fromMap(json);
20+
21+
expect(cameraPosition, cameraPositionFromJson);
22+
});
23+
}

0 commit comments

Comments
 (0)