Skip to content

Commit

Permalink
[google_maps_flutter] Fix CameraPosition regression (flutter#3547)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stuartmorgan authored Feb 16, 2021
1 parent 9136b68 commit 7a3b4ae
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.0-nullsafety.1

* Fix overly-restrictive type check.

## 2.0.0-nullsafety

* Migrated to null-safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CameraPosition {
///
/// Mainly for internal use.
static CameraPosition? fromMap(Object? json) {
if (json == null || !(json is Map<String, dynamic>)) {
if (json == null || !(json is Map<dynamic, dynamic>)) {
return null;
}
final LatLng? target = LatLng.fromJson(json['target']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the google_maps_flutter plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface
# 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.0.0-nullsafety
version: 2.0.0-nullsafety.1

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';

import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

test('toMap / fromMap', () {
final cameraPosition = CameraPosition(
target: LatLng(10.0, 15.0), bearing: 0.5, tilt: 30.0, zoom: 1.5);
// Cast to <dynamic, dynamic> to ensure that recreating from JSON, where
// type information will have likely been lost, still works.
final json = (cameraPosition.toMap() as Map<String, dynamic>)
.cast<dynamic, dynamic>();
final cameraPositionFromJson = CameraPosition.fromMap(json);

expect(cameraPosition, cameraPositionFromJson);
});
}

0 comments on commit 7a3b4ae

Please sign in to comment.