From 6d8f6348f2297bff6bcdc646719690d46f9a4cad Mon Sep 17 00:00:00 2001 From: otopba Date: Wed, 8 Jan 2020 02:17:08 +0300 Subject: [PATCH 01/18] Add liteModeEnabled option --- packages/google_maps_flutter/CHANGELOG.md | 4 ++ .../flutter/plugins/googlemaps/Convert.java | 4 ++ .../plugins/googlemaps/GoogleMapBuilder.java | 5 +++ .../googlemaps/GoogleMapController.java | 25 +++++++++-- .../googlemaps/GoogleMapOptionsSink.java | 2 + .../example/lib/lite_mode.dart | 45 +++++++++++++++++++ .../google_maps_flutter/example/lib/main.dart | 2 + .../test_driver/google_map_inspector.dart | 4 ++ .../example/test_driver/google_maps_e2e.dart | 40 +++++++++++++++++ .../lib/google_maps_flutter.dart | 1 + .../lib/src/google_map.dart | 12 +++++ packages/google_maps_flutter/pubspec.yaml | 2 +- .../test/fake_maps_controllers.dart | 5 +++ .../test/google_map_test.dart | 29 ++++++++++++ 14 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 packages/google_maps_flutter/example/lib/lite_mode.dart diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index 0f6908eb130b..db8b4a1681b7 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.22 + +* Add liteModeEnabled option. + ## 0.5.21+15 * Remove the deprecated `author:` field from pubspec.yaml diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java index c8429f78ba8b..110b4eebb1dc 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java @@ -316,6 +316,10 @@ static void interpretGoogleMapOptions(Object o, GoogleMapOptionsSink sink) { if (zoomGesturesEnabled != null) { sink.setZoomGesturesEnabled(toBoolean(zoomGesturesEnabled)); } + final Object liteModeEnabled = data.get("liteModeEnabled"); + if (liteModeEnabled != null) { + sink.setLiteModeEnabled(toBoolean(liteModeEnabled)); + } final Object myLocationEnabled = data.get("myLocationEnabled"); if (myLocationEnabled != null) { sink.setMyLocationEnabled(toBoolean(myLocationEnabled)); diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java index e78908d73cf2..a525ff979f40 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java @@ -109,6 +109,11 @@ public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) { options.zoomGesturesEnabled(zoomGesturesEnabled); } + @Override + public void setLiteModeEnabled(boolean liteModeEnabled) { + options.liteMode(liteModeEnabled); + } + @Override public void setIndoorEnabled(boolean indoorEnabled) { this.indoorEnabled = indoorEnabled; diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index 5c7d094e3d3f..bf54392cdba1 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -69,6 +69,7 @@ final class GoogleMapController private final AtomicInteger activityState; private final MethodChannel methodChannel; private final PluginRegistry.Registrar registrar; + private final GoogleMapOptions options; private final MapView mapView; private GoogleMap googleMap; private boolean trackCameraPosition = false; @@ -101,6 +102,7 @@ final class GoogleMapController this.context = context; this.activityState = activityState; this.registrar = registrar; + this.options = options; this.mapView = new MapView(context, options); this.density = context.getResources().getDisplayMetrics().density; methodChannel = @@ -338,6 +340,11 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { result.success(googleMap.getUiSettings().isZoomGesturesEnabled()); break; } + case "map#isLiteModeEnabled": + { + result.success(options.getLiteMode()); + break; + } case "map#isScrollGesturesEnabled": { result.success(googleMap.getUiSettings().isScrollGesturesEnabled()); @@ -476,17 +483,21 @@ public void dispose() { } // @Override - // The minimum supported version of Flutter doesn't have this method on the PlatformView interface, but the maximum + // The minimum supported version of Flutter doesn't have this method on the PlatformView + // interface, but the maximum // does. This will override it when available even with the annotation commented out. public void onInputConnectionLocked() { - // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 is fixed in stable. + // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 + // is fixed in stable. }; // @Override - // The minimum supported version of Flutter doesn't have this method on the PlatformView interface, but the maximum + // The minimum supported version of Flutter doesn't have this method on the PlatformView + // interface, but the maximum // does. This will override it when available even with the annotation commented out. public void onInputConnectionUnlocked() { - // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 is fixed in stable. + // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 + // is fixed in stable. }; @Override @@ -614,6 +625,12 @@ public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) { googleMap.getUiSettings().setZoomGesturesEnabled(zoomGesturesEnabled); } + /** This call will have no effect on already created map */ + @Override + public void setLiteModeEnabled(boolean liteModeEnabled) { + options.liteMode(liteModeEnabled); + } + @Override public void setMyLocationEnabled(boolean myLocationEnabled) { if (this.myLocationEnabled == myLocationEnabled) { diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java index fb88b368c5b8..14502baafe2f 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java @@ -30,6 +30,8 @@ interface GoogleMapOptionsSink { void setZoomGesturesEnabled(boolean zoomGesturesEnabled); + void setLiteModeEnabled(boolean liteModeEnabled); + void setMyLocationEnabled(boolean myLocationEnabled); void setMyLocationButtonEnabled(boolean myLocationButtonEnabled); diff --git a/packages/google_maps_flutter/example/lib/lite_mode.dart b/packages/google_maps_flutter/example/lib/lite_mode.dart new file mode 100644 index 000000000000..058e42ff03d8 --- /dev/null +++ b/packages/google_maps_flutter/example/lib/lite_mode.dart @@ -0,0 +1,45 @@ +// Copyright 2019 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. + +// ignore_for_file: public_member_api_docs + +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; +import 'page.dart'; + +const CameraPosition _kInitialPosition = + CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0); + +class LiteModePage extends Page { + LiteModePage() : super(const Icon(Icons.map), 'Lite mode'); + + @override + Widget build(BuildContext context) { + return const _LiteModeBody(); + } +} + +class _LiteModeBody extends StatelessWidget { + const _LiteModeBody(); + + @override + Widget build(BuildContext context) { + return Card( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 30.0), + child: Center( + child: SizedBox( + width: 300.0, + height: 300.0, + child: GoogleMap( + initialCameraPosition: _kInitialPosition, + liteModeEnabled: true, + ), + ), + ), + ), + ); + } +} diff --git a/packages/google_maps_flutter/example/lib/main.dart b/packages/google_maps_flutter/example/lib/main.dart index f4b8776559ec..d768189a0343 100644 --- a/packages/google_maps_flutter/example/lib/main.dart +++ b/packages/google_maps_flutter/example/lib/main.dart @@ -5,6 +5,7 @@ // ignore_for_file: public_member_api_docs import 'package:flutter/material.dart'; +import 'package:google_maps_flutter_example/lite_mode.dart'; import 'animate_camera.dart'; import 'map_click.dart'; import 'map_coordinates.dart'; @@ -32,6 +33,7 @@ final List _allPages = [ PlacePolygonPage(), PlaceCirclePage(), PaddingPage(), + LiteModePage(), ]; class MapsDemo extends StatelessWidget { diff --git a/packages/google_maps_flutter/example/test_driver/google_map_inspector.dart b/packages/google_maps_flutter/example/test_driver/google_map_inspector.dart index ab0f82a4a6ff..a6916ddafe06 100644 --- a/packages/google_maps_flutter/example/test_driver/google_map_inspector.dart +++ b/packages/google_maps_flutter/example/test_driver/google_map_inspector.dart @@ -34,6 +34,10 @@ class GoogleMapInspector { return await _channel.invokeMethod('map#isZoomGesturesEnabled'); } + Future isLiteModeEnabled() async { + return await _channel.invokeMethod('map#isLiteModeEnabled'); + } + Future isRotateGesturesEnabled() async { return await _channel.invokeMethod('map#isRotateGesturesEnabled'); } diff --git a/packages/google_maps_flutter/example/test_driver/google_maps_e2e.dart b/packages/google_maps_flutter/example/test_driver/google_maps_e2e.dart index 0c1f33ca453a..2099b5a9ca4c 100644 --- a/packages/google_maps_flutter/example/test_driver/google_maps_e2e.dart +++ b/packages/google_maps_flutter/example/test_driver/google_maps_e2e.dart @@ -183,6 +183,46 @@ void main() { expect(zoomGesturesEnabled, true); }); + testWidgets('testLiteModeEnabled', (WidgetTester tester) async { + final Key key = GlobalKey(); + final Completer inspectorCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + key: key, + initialCameraPosition: _kInitialCameraPosition, + liteModeEnabled: false, + onMapCreated: (GoogleMapController controller) { + final GoogleMapInspector inspector = + // ignore: invalid_use_of_visible_for_testing_member + GoogleMapInspector(controller.channel); + inspectorCompleter.complete(inspector); + }, + ), + )); + + final GoogleMapInspector inspector = await inspectorCompleter.future; + bool liteModeEnabled = await inspector.isLiteModeEnabled(); + expect(liteModeEnabled, false); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + key: key, + initialCameraPosition: _kInitialCameraPosition, + liteModeEnabled: true, + onMapCreated: (GoogleMapController controller) { + fail("OnMapCreated should get called only once."); + }, + ), + )); + + liteModeEnabled = await inspector.isLiteModeEnabled(); + expect(liteModeEnabled, true); + }); + testWidgets('testRotateGesturesEnabled', (WidgetTester tester) async { final Key key = GlobalKey(); final Completer inspectorCompleter = diff --git a/packages/google_maps_flutter/lib/google_maps_flutter.dart b/packages/google_maps_flutter/lib/google_maps_flutter.dart index 5f3889f7b2f1..e3e0e81abaec 100644 --- a/packages/google_maps_flutter/lib/google_maps_flutter.dart +++ b/packages/google_maps_flutter/lib/google_maps_flutter.dart @@ -5,6 +5,7 @@ library google_maps_flutter; import 'dart:async'; +import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; diff --git a/packages/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/lib/src/google_map.dart index f6a413a82ffb..708a71e54663 100644 --- a/packages/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/lib/src/google_map.dart @@ -36,6 +36,7 @@ class GoogleMap extends StatefulWidget { this.rotateGesturesEnabled = true, this.scrollGesturesEnabled = true, this.zoomGesturesEnabled = true, + this.liteModeEnabled = false, this.tiltGesturesEnabled = true, this.myLocationEnabled = false, this.myLocationButtonEnabled = true, @@ -91,6 +92,9 @@ class GoogleMap extends StatefulWidget { /// True if the map view should respond to zoom gestures. final bool zoomGesturesEnabled; + /// True if the map view should be in lite mode. Android only. See https://developers.google.com/maps/documentation/android-sdk/lite#overview_of_lite_mode for more details. + final bool liteModeEnabled; + /// True if the map view should respond to tilt gestures. final bool tiltGesturesEnabled; @@ -393,6 +397,7 @@ class _GoogleMapOptions { this.tiltGesturesEnabled, this.trackCameraPosition, this.zoomGesturesEnabled, + this.liteModeEnabled, this.myLocationEnabled, this.myLocationButtonEnabled, this.padding, @@ -413,6 +418,7 @@ class _GoogleMapOptions { tiltGesturesEnabled: map.tiltGesturesEnabled, trackCameraPosition: map.onCameraMove != null, zoomGesturesEnabled: map.zoomGesturesEnabled, + liteModeEnabled: map.liteModeEnabled, myLocationEnabled: map.myLocationEnabled, myLocationButtonEnabled: map.myLocationButtonEnabled, padding: map.padding, @@ -442,6 +448,8 @@ class _GoogleMapOptions { final bool zoomGesturesEnabled; + final bool liteModeEnabled; + final bool myLocationEnabled; final bool myLocationButtonEnabled; @@ -472,6 +480,10 @@ class _GoogleMapOptions { addIfNonNull('scrollGesturesEnabled', scrollGesturesEnabled); addIfNonNull('tiltGesturesEnabled', tiltGesturesEnabled); addIfNonNull('zoomGesturesEnabled', zoomGesturesEnabled); + addIfNonNull('liteModeEnabled', liteModeEnabled); + if (liteModeEnabled != null && liteModeEnabled && !Platform.isAndroid) { + print('Warning: liteModeEnabled is Android only'); + } addIfNonNull('trackCameraPosition', trackCameraPosition); addIfNonNull('myLocationEnabled', myLocationEnabled); addIfNonNull('myLocationButtonEnabled', myLocationButtonEnabled); diff --git a/packages/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/pubspec.yaml index f29c41cf221f..123462023ec3 100644 --- a/packages/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/pubspec.yaml @@ -1,7 +1,7 @@ name: google_maps_flutter description: A Flutter plugin for integrating Google Maps in iOS and Android applications. homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter -version: 0.5.21+15 +version: 0.5.22 dependencies: flutter: diff --git a/packages/google_maps_flutter/test/fake_maps_controllers.dart b/packages/google_maps_flutter/test/fake_maps_controllers.dart index 57b70c4d1525..eb64554fa7eb 100644 --- a/packages/google_maps_flutter/test/fake_maps_controllers.dart +++ b/packages/google_maps_flutter/test/fake_maps_controllers.dart @@ -43,6 +43,8 @@ class FakePlatformGoogleMap { bool zoomGesturesEnabled; + bool liteModeEnabled; + bool trackCameraPosition; bool myLocationEnabled; @@ -351,6 +353,9 @@ class FakePlatformGoogleMap { if (options.containsKey('zoomGesturesEnabled')) { zoomGesturesEnabled = options['zoomGesturesEnabled']; } + if (options.containsKey('liteModeEnabled')) { + liteModeEnabled = options['liteModeEnabled']; + } if (options.containsKey('myLocationEnabled')) { myLocationEnabled = options['myLocationEnabled']; } diff --git a/packages/google_maps_flutter/test/google_map_test.dart b/packages/google_maps_flutter/test/google_map_test.dart index 5d77ccfb2165..3e983c441f2e 100644 --- a/packages/google_maps_flutter/test/google_map_test.dart +++ b/packages/google_maps_flutter/test/google_map_test.dart @@ -386,6 +386,35 @@ void main() { expect(platformGoogleMap.zoomGesturesEnabled, true); }); + testWidgets('Can update liteModeEnabled', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + liteModeEnabled: false, + ), + ), + ); + + final FakePlatformGoogleMap platformGoogleMap = + fakePlatformViewsController.lastCreatedView; + + expect(platformGoogleMap.liteModeEnabled, false); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + liteModeEnabled: true, + ), + ), + ); + + expect(platformGoogleMap.liteModeEnabled, true); + }); + testWidgets('Can update myLocationEnabled', (WidgetTester tester) async { await tester.pumpWidget( const Directionality( From e038a3ee111ff7f047d301ef637b5e988a4e1cc8 Mon Sep 17 00:00:00 2001 From: otopba Date: Wed, 22 Jan 2020 00:19:46 +0300 Subject: [PATCH 02/18] Add dummy map initialization --- .../plugins/googlemaps/GoogleMapsPlugin.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapsPlugin.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapsPlugin.java index b27fea425ba5..9888b5ff8d93 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapsPlugin.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapsPlugin.java @@ -6,7 +6,12 @@ import android.app.Activity; import android.app.Application; +import android.app.FragmentManager; import android.os.Bundle; +import androidx.annotation.NonNull; +import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.maps.MapFragment; +import com.google.android.gms.maps.OnMapReadyCallback; import io.flutter.plugin.common.PluginRegistry.Registrar; import java.util.concurrent.atomic.AtomicInteger; @@ -25,6 +30,7 @@ public class GoogleMapsPlugin implements Application.ActivityLifecycleCallbacks static final int DESTROYED = 6; private final AtomicInteger state = new AtomicInteger(0); private final int registrarActivityHashCode; + private boolean dummyMapInitialized; public static void registerWith(Registrar registrar) { if (registrar.activity() == null) { @@ -94,5 +100,34 @@ public void onActivityDestroyed(Activity activity) { private GoogleMapsPlugin(Registrar registrar) { this.registrarActivityHashCode = registrar.activity().hashCode(); + if (dummyMapInitialized) { + return; + } + Activity activity = registrar.activity(); + if (activity == null) { + return; + } + FragmentManager fragmentManager = activity.getFragmentManager(); + if (fragmentManager == null) { + return; + } + initDummyMap(fragmentManager); + dummyMapInitialized = true; + } + + /** + * This method creates dummy map. This call will initialize all services needed by GoogleMaps This + * will speed up next GoogleMap view initialization + */ + private static void initDummyMap(@NonNull final FragmentManager fragmentManager) { + final MapFragment mapFragment = new MapFragment(); + fragmentManager.beginTransaction().add(mapFragment, "DummyMap").commit(); + mapFragment.getMapAsync( + new OnMapReadyCallback() { + @Override + public void onMapReady(GoogleMap googleMap) { + fragmentManager.beginTransaction().remove(mapFragment).commit(); + } + }); } } From 4345ed504c7d6042fa04b429d97d9f0dad68a28a Mon Sep 17 00:00:00 2001 From: otopba Date: Wed, 22 Jan 2020 00:21:30 +0300 Subject: [PATCH 03/18] Revert "Add dummy map initialization" This reverts commit e038a3ee --- .../plugins/googlemaps/GoogleMapsPlugin.java | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapsPlugin.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapsPlugin.java index 9888b5ff8d93..b27fea425ba5 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapsPlugin.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapsPlugin.java @@ -6,12 +6,7 @@ import android.app.Activity; import android.app.Application; -import android.app.FragmentManager; import android.os.Bundle; -import androidx.annotation.NonNull; -import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.MapFragment; -import com.google.android.gms.maps.OnMapReadyCallback; import io.flutter.plugin.common.PluginRegistry.Registrar; import java.util.concurrent.atomic.AtomicInteger; @@ -30,7 +25,6 @@ public class GoogleMapsPlugin implements Application.ActivityLifecycleCallbacks static final int DESTROYED = 6; private final AtomicInteger state = new AtomicInteger(0); private final int registrarActivityHashCode; - private boolean dummyMapInitialized; public static void registerWith(Registrar registrar) { if (registrar.activity() == null) { @@ -100,34 +94,5 @@ public void onActivityDestroyed(Activity activity) { private GoogleMapsPlugin(Registrar registrar) { this.registrarActivityHashCode = registrar.activity().hashCode(); - if (dummyMapInitialized) { - return; - } - Activity activity = registrar.activity(); - if (activity == null) { - return; - } - FragmentManager fragmentManager = activity.getFragmentManager(); - if (fragmentManager == null) { - return; - } - initDummyMap(fragmentManager); - dummyMapInitialized = true; - } - - /** - * This method creates dummy map. This call will initialize all services needed by GoogleMaps This - * will speed up next GoogleMap view initialization - */ - private static void initDummyMap(@NonNull final FragmentManager fragmentManager) { - final MapFragment mapFragment = new MapFragment(); - fragmentManager.beginTransaction().add(mapFragment, "DummyMap").commit(); - mapFragment.getMapAsync( - new OnMapReadyCallback() { - @Override - public void onMapReady(GoogleMap googleMap) { - fragmentManager.beginTransaction().remove(mapFragment).commit(); - } - }); } } From 7d9a2ac4f80235c71a24b55e17077f30c3c4160b Mon Sep 17 00:00:00 2001 From: otopba Date: Wed, 22 Jan 2020 00:47:03 +0300 Subject: [PATCH 04/18] format --- .../flutter/plugins/googlemaps/GoogleMapController.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index bf54392cdba1..fc17188390df 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -483,12 +483,10 @@ public void dispose() { } // @Override - // The minimum supported version of Flutter doesn't have this method on the PlatformView - // interface, but the maximum + // The minimum supported version of Flutter doesn't have this method on the PlatformView interface, but the maximum // does. This will override it when available even with the annotation commented out. public void onInputConnectionLocked() { - // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 - // is fixed in stable. + // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 is fixed in stable. }; // @Override @@ -496,8 +494,7 @@ public void onInputConnectionLocked() { // interface, but the maximum // does. This will override it when available even with the annotation commented out. public void onInputConnectionUnlocked() { - // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 - // is fixed in stable. + // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 is fixed in stable. }; @Override From b4a4989f22260b97b2cd43b28ba4375def80dc05 Mon Sep 17 00:00:00 2001 From: otopba Date: Wed, 22 Jan 2020 00:48:39 +0300 Subject: [PATCH 05/18] format --- .../io/flutter/plugins/googlemaps/GoogleMapController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index fc17188390df..84f58bc86805 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -490,8 +490,7 @@ public void onInputConnectionLocked() { }; // @Override - // The minimum supported version of Flutter doesn't have this method on the PlatformView - // interface, but the maximum + // The minimum supported version of Flutter doesn't have this method on the PlatformView interface, but the maximum // does. This will override it when available even with the annotation commented out. public void onInputConnectionUnlocked() { // TODO(mklim): Remove this empty override once https://github.com/flutter/flutter/issues/40126 is fixed in stable. From 2fe0b7220776d1ae0e8a03bdd1745f7d78d330f7 Mon Sep 17 00:00:00 2001 From: otopba Date: Wed, 22 Jan 2020 02:20:34 +0300 Subject: [PATCH 06/18] format --- packages/google_maps_flutter/lib/src/google_map.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/lib/src/google_map.dart index 708a71e54663..9615b99222b6 100644 --- a/packages/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/lib/src/google_map.dart @@ -92,7 +92,9 @@ class GoogleMap extends StatefulWidget { /// True if the map view should respond to zoom gestures. final bool zoomGesturesEnabled; - /// True if the map view should be in lite mode. Android only. See https://developers.google.com/maps/documentation/android-sdk/lite#overview_of_lite_mode for more details. + /// True if the map view should be in lite mode. Android only. + /// + /// See https://developers.google.com/maps/documentation/android-sdk/lite#overview_of_lite_mode for more details. final bool liteModeEnabled; /// True if the map view should respond to tilt gestures. From 76991a42c1f553f40a30bfd5b5c7d4f7b8ed65e5 Mon Sep 17 00:00:00 2001 From: otopba Date: Thu, 30 Jan 2020 01:08:54 +0300 Subject: [PATCH 07/18] add exception of liteModeEnabled not for android --- packages/google_maps_flutter/lib/src/google_map.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/lib/src/google_map.dart index 9615b99222b6..be12a82fdf18 100644 --- a/packages/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/lib/src/google_map.dart @@ -484,7 +484,7 @@ class _GoogleMapOptions { addIfNonNull('zoomGesturesEnabled', zoomGesturesEnabled); addIfNonNull('liteModeEnabled', liteModeEnabled); if (liteModeEnabled != null && liteModeEnabled && !Platform.isAndroid) { - print('Warning: liteModeEnabled is Android only'); + throw Exception('liteModeEnabled is Android only'); } addIfNonNull('trackCameraPosition', trackCameraPosition); addIfNonNull('myLocationEnabled', myLocationEnabled); From e7ddaec139a5222e86460a942ad60268c9014f1c Mon Sep 17 00:00:00 2001 From: otopba Date: Thu, 30 Jan 2020 16:24:20 +0300 Subject: [PATCH 08/18] change exception to assert --- packages/google_maps_flutter/lib/src/google_map.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/lib/src/google_map.dart index be12a82fdf18..b4af89e60a4a 100644 --- a/packages/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/lib/src/google_map.dart @@ -406,7 +406,9 @@ class _GoogleMapOptions { this.indoorViewEnabled, this.trafficEnabled, this.buildingsEnabled, - }); + }) { + assert(liteModeEnabled != null && liteModeEnabled && !Platform.isAndroid); + } static _GoogleMapOptions fromWidget(GoogleMap map) { return _GoogleMapOptions( @@ -483,9 +485,6 @@ class _GoogleMapOptions { addIfNonNull('tiltGesturesEnabled', tiltGesturesEnabled); addIfNonNull('zoomGesturesEnabled', zoomGesturesEnabled); addIfNonNull('liteModeEnabled', liteModeEnabled); - if (liteModeEnabled != null && liteModeEnabled && !Platform.isAndroid) { - throw Exception('liteModeEnabled is Android only'); - } addIfNonNull('trackCameraPosition', trackCameraPosition); addIfNonNull('myLocationEnabled', myLocationEnabled); addIfNonNull('myLocationButtonEnabled', myLocationButtonEnabled); From 786e731d3f448d698ff69a2c2569912bc9ec6853 Mon Sep 17 00:00:00 2001 From: otopba Date: Sat, 1 Feb 2020 15:46:12 +0300 Subject: [PATCH 09/18] merge --- packages/google_maps_flutter/CHANGELOG.md | 8 ++++---- .../flutter/plugins/googlemaps/GoogleMapController.java | 1 - packages/google_maps_flutter/pubspec.yaml | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index 8d6eed3ad184..782ba33bfa04 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.23 + +* Add liteModeEnabled option. + ## 0.5.22 * Support Android v2 embedding. @@ -12,10 +16,6 @@ * Fixed typo in LatLng's documentation. -## 0.5.22 - -* Add liteModeEnabled option. - ## 0.5.21+15 * Remove the deprecated `author:` field from pubspec.yaml diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index c466855eb9e1..50967b48a051 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -117,7 +117,6 @@ final class GoogleMapController this.id = id; this.context = context; this.activityState = activityState; - this.registrar = registrar; this.options = options; this.mapView = new MapView(context, options); this.density = context.getResources().getDisplayMetrics().density; diff --git a/packages/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/pubspec.yaml index b2ea9a193812..d3e751e9a52d 100644 --- a/packages/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/pubspec.yaml @@ -1,7 +1,7 @@ name: google_maps_flutter description: A Flutter plugin for integrating Google Maps in iOS and Android applications. homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter -version: 0.5.22 +version: 0.5.23 dependencies: flutter: From b7458b3b589b13cbdf1711571bf26eaf14beb6cc Mon Sep 17 00:00:00 2001 From: otopba Date: Sat, 1 Feb 2020 15:59:41 +0300 Subject: [PATCH 10/18] fix readme --- packages/google_maps_flutter/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index 782ba33bfa04..81abd64242fd 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.5.23 -* Add liteModeEnabled option. +* Android: Add liteModeEnabled option. ## 0.5.22 From 12722fa309e0c6296d19cdd43ef30f20d758dafb Mon Sep 17 00:00:00 2001 From: otopba Date: Sat, 1 Feb 2020 16:18:40 +0300 Subject: [PATCH 11/18] fix assert --- packages/google_maps_flutter/lib/src/google_map.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/lib/src/google_map.dart index b4af89e60a4a..f37c9f904f09 100644 --- a/packages/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/lib/src/google_map.dart @@ -407,7 +407,7 @@ class _GoogleMapOptions { this.trafficEnabled, this.buildingsEnabled, }) { - assert(liteModeEnabled != null && liteModeEnabled && !Platform.isAndroid); + assert(liteModeEnabled == null || (liteModeEnabled && Platform.isAndroid)); } static _GoogleMapOptions fromWidget(GoogleMap map) { From 6c7ff06d46c102f4a307c0b6edef2175aa94751a Mon Sep 17 00:00:00 2001 From: otopba Date: Sat, 1 Feb 2020 16:30:02 +0300 Subject: [PATCH 12/18] fix assert --- packages/google_maps_flutter/lib/src/google_map.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/lib/src/google_map.dart index f37c9f904f09..97c451e974b9 100644 --- a/packages/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/lib/src/google_map.dart @@ -407,7 +407,9 @@ class _GoogleMapOptions { this.trafficEnabled, this.buildingsEnabled, }) { - assert(liteModeEnabled == null || (liteModeEnabled && Platform.isAndroid)); + assert(liteModeEnabled == null || + !liteModeEnabled || + (liteModeEnabled && Platform.isAndroid)); } static _GoogleMapOptions fromWidget(GoogleMap map) { From 8788a6e1adbaf9e30c15a7761724ce3342c20396 Mon Sep 17 00:00:00 2001 From: otopba Date: Sat, 1 Feb 2020 17:12:17 +0300 Subject: [PATCH 13/18] separate tests --- .../test/android_google_map_test.dart | 56 +++++++++++++++++++ .../test/google_map_test.dart | 29 ---------- 2 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 packages/google_maps_flutter/test/android_google_map_test.dart diff --git a/packages/google_maps_flutter/test/android_google_map_test.dart b/packages/google_maps_flutter/test/android_google_map_test.dart new file mode 100644 index 000000000000..194efe9a66f0 --- /dev/null +++ b/packages/google_maps_flutter/test/android_google_map_test.dart @@ -0,0 +1,56 @@ +// Copyright 2018 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. + +@TestOn('android') +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; + +import 'fake_maps_controllers.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + final FakePlatformViewsController fakePlatformViewsController = + FakePlatformViewsController(); + + setUpAll(() { + SystemChannels.platform_views.setMockMethodCallHandler( + fakePlatformViewsController.fakePlatformViewsMethodHandler); + }); + + setUp(() { + fakePlatformViewsController.reset(); + }); + + testWidgets('Can update liteModeEnabled', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + liteModeEnabled: false, + ), + ), + ); + + final FakePlatformGoogleMap platformGoogleMap = + fakePlatformViewsController.lastCreatedView; + + expect(platformGoogleMap.liteModeEnabled, false); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + liteModeEnabled: true, + ), + ), + ); + + expect(platformGoogleMap.liteModeEnabled, true); + }); +} diff --git a/packages/google_maps_flutter/test/google_map_test.dart b/packages/google_maps_flutter/test/google_map_test.dart index 3e983c441f2e..5d77ccfb2165 100644 --- a/packages/google_maps_flutter/test/google_map_test.dart +++ b/packages/google_maps_flutter/test/google_map_test.dart @@ -386,35 +386,6 @@ void main() { expect(platformGoogleMap.zoomGesturesEnabled, true); }); - testWidgets('Can update liteModeEnabled', (WidgetTester tester) async { - await tester.pumpWidget( - const Directionality( - textDirection: TextDirection.ltr, - child: GoogleMap( - initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), - liteModeEnabled: false, - ), - ), - ); - - final FakePlatformGoogleMap platformGoogleMap = - fakePlatformViewsController.lastCreatedView; - - expect(platformGoogleMap.liteModeEnabled, false); - - await tester.pumpWidget( - const Directionality( - textDirection: TextDirection.ltr, - child: GoogleMap( - initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), - liteModeEnabled: true, - ), - ), - ); - - expect(platformGoogleMap.liteModeEnabled, true); - }); - testWidgets('Can update myLocationEnabled', (WidgetTester tester) async { await tester.pumpWidget( const Directionality( From ce83d97ae146d85f4009e62e16ae7dd434799565 Mon Sep 17 00:00:00 2001 From: otopba Date: Sat, 1 Feb 2020 18:38:15 +0300 Subject: [PATCH 14/18] run limeDode test only on Android --- .../example/test_driver/google_maps_e2e.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/example/test_driver/google_maps_e2e.dart b/packages/google_maps_flutter/example/test_driver/google_maps_e2e.dart index 1e36935505bb..d4e558d346ae 100644 --- a/packages/google_maps_flutter/example/test_driver/google_maps_e2e.dart +++ b/packages/google_maps_flutter/example/test_driver/google_maps_e2e.dart @@ -258,7 +258,7 @@ void main() { liteModeEnabled = await inspector.isLiteModeEnabled(); expect(liteModeEnabled, true); - }); + }, skip: !Platform.isAndroid); testWidgets('testRotateGesturesEnabled', (WidgetTester tester) async { final Key key = GlobalKey(); From 56b897d9160bc799d97211f3b063bce82ed4bcb3 Mon Sep 17 00:00:00 2001 From: otopba Date: Mon, 24 Feb 2020 21:14:17 +0300 Subject: [PATCH 15/18] merge --- packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index efd3416b4636..fe3aea91e86e 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.5.24 +## 0.5.25 * Android: Add liteModeEnabled option. From 454faa77007659e568100218383b6aab8e8d7973 Mon Sep 17 00:00:00 2001 From: otopba Date: Mon, 24 Feb 2020 21:23:12 +0300 Subject: [PATCH 16/18] move file --- .../{ => google_maps_flutter}/example/lib/lite_mode.dart | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/google_maps_flutter/{ => google_maps_flutter}/example/lib/lite_mode.dart (100%) diff --git a/packages/google_maps_flutter/example/lib/lite_mode.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/lite_mode.dart similarity index 100% rename from packages/google_maps_flutter/example/lib/lite_mode.dart rename to packages/google_maps_flutter/google_maps_flutter/example/lib/lite_mode.dart From bf0e39e11e0b36d3808d251c7d16205b480307db Mon Sep 17 00:00:00 2001 From: otopba Date: Sun, 22 Mar 2020 12:58:25 +0300 Subject: [PATCH 17/18] merge --- packages/google_maps_flutter/google_maps_flutter/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index e6dfb6bea412..507343e6a7ac 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -1,7 +1,7 @@ name: google_maps_flutter description: A Flutter plugin for integrating Google Maps in iOS and Android applications. homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter -version: 0.5.25 +version: 0.5.26 dependencies: flutter: From 696468fc751be54c89beabe07acdb73ececfe2b1 Mon Sep 17 00:00:00 2001 From: otopba Date: Fri, 15 May 2020 20:07:23 +0300 Subject: [PATCH 18/18] fix example --- .../google_maps_flutter/example/lib/lite_mode.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/lite_mode.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/lite_mode.dart index 058e42ff03d8..7c814f31a660 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/lite_mode.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/lite_mode.dart @@ -12,7 +12,7 @@ import 'page.dart'; const CameraPosition _kInitialPosition = CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0); -class LiteModePage extends Page { +class LiteModePage extends GoogleMapExampleAppPage { LiteModePage() : super(const Icon(Icons.map), 'Lite mode'); @override