Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter] Add liteModeEnabled option #2449

Merged
merged 50 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
073fca5
Merge pull request #1 from flutter/master
otopba Jul 26, 2019
bb12418
Merge pull request #2 from flutter/master
otopba Aug 6, 2019
a03ee88
Merge pull request #3 from flutter/master
otopba Aug 31, 2019
e2613e0
Merge pull request #4 from flutter/master
otopba Sep 11, 2019
1c98d10
Merge pull request #5 from flutter/master
otopba Sep 16, 2019
b50c88e
Merge pull request #6 from flutter/master
otopba Sep 20, 2019
ce695b1
Merge pull request #7 from flutter/master
otopba Sep 25, 2019
58192f4
Merge pull request #8 from flutter/master
otopba Oct 6, 2019
485a419
Merge pull request #9 from flutter/master
otopba Nov 2, 2019
dde8df7
Merge pull request #10 from flutter/master
otopba Nov 12, 2019
33ed689
Merge pull request #11 from flutter/master
otopba Nov 29, 2019
7ec3707
Merge remote-tracking branch 'upstream/master'
otopba Dec 8, 2019
f056c49
Merge remote-tracking branch 'upstream/master'
otopba Dec 11, 2019
ab1d5bc
Merge remote-tracking branch 'upstream/master'
otopba Dec 19, 2019
e4a6011
Merge remote-tracking branch 'upstream/master'
otopba Jan 7, 2020
6d8f634
Add liteModeEnabled option
otopba Jan 7, 2020
fb15656
Merge remote-tracking branch 'upstream/master'
otopba Jan 19, 2020
596184c
Merge remote-tracking branch 'upstream/master'
otopba Jan 21, 2020
e038a3e
Add dummy map initialization
otopba Jan 21, 2020
4345ed5
Revert "Add dummy map initialization"
otopba Jan 21, 2020
2d0abd4
Merge branch 'master' into liteModeEnabled
otopba Jan 21, 2020
7d9a2ac
format
otopba Jan 21, 2020
b4a4989
format
otopba Jan 21, 2020
2fe0b72
format
otopba Jan 21, 2020
ee302c1
Merge remote-tracking branch 'upstream/master'
otopba Jan 23, 2020
125fffd
Merge branch 'master' into liteModeEnabled
otopba Jan 23, 2020
97598ab
Merge remote-tracking branch 'upstream/master'
otopba Jan 29, 2020
c5a688e
Merge branch 'master' into liteModeEnabled
otopba Jan 29, 2020
76991a4
add exception of liteModeEnabled not for android
otopba Jan 29, 2020
e7ddaec
change exception to assert
otopba Jan 30, 2020
4c8d45a
Merge remote-tracking branch 'upstream/master'
otopba Feb 1, 2020
c5ac627
Merge branch 'master' into liteModeEnabled
otopba Feb 1, 2020
786e731
merge
otopba Feb 1, 2020
b7458b3
fix readme
otopba Feb 1, 2020
12722fa
fix assert
otopba Feb 1, 2020
6c7ff06
fix assert
otopba Feb 1, 2020
8788a6e
separate tests
otopba Feb 1, 2020
ce83d97
run limeDode test only on Android
otopba Feb 1, 2020
c267dca
Merge remote-tracking branch 'upstream/master'
otopba Feb 24, 2020
d6c7eb0
Merge branch 'master' into liteModeEnabled
otopba Feb 24, 2020
56b897d
merge
otopba Feb 24, 2020
454faa7
move file
otopba Feb 24, 2020
4816227
Merge remote-tracking branch 'upstream/master'
otopba Mar 19, 2020
bb4e5be
Merge remote-tracking branch 'upstream/master'
otopba Mar 22, 2020
5862774
Merge branch 'master' into liteModeEnabled
otopba Mar 22, 2020
bf0e39e
merge
otopba Mar 22, 2020
0a86ebc
Merge remote-tracking branch 'upstream/master'
otopba Apr 30, 2020
6cd64da
Merge remote-tracking branch 'upstream/master'
otopba May 15, 2020
a39de59
Merge branch 'master' into liteModeEnabled
otopba May 15, 2020
696468f
fix example
otopba May 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.28

* Android: Add liteModeEnabled option.

## 0.5.27+3

* iOS: Update the gesture recognizer blocking policy to "WaitUntilTouchesEnded", which fixes the camera idle callback not triggered issue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ final class GoogleMapController
private final int id;
private final AtomicInteger activityState;
private final MethodChannel methodChannel;
private final GoogleMapOptions options;
private final MapView mapView;
private GoogleMap googleMap;
private boolean trackCameraPosition = false;
Expand Down Expand Up @@ -111,6 +112,7 @@ final class GoogleMapController
this.id = id;
this.context = context;
this.activityState = activityState;
this.options = options;
this.mapView = new MapView(context, options);
this.density = context.getResources().getDisplayMetrics().density;
methodChannel = new MethodChannel(binaryMessenger, "plugins.flutter.io/google_maps_" + id);
Expand Down Expand Up @@ -383,6 +385,11 @@ public void onSnapshotReady(Bitmap bitmap) {
result.success(googleMap.getUiSettings().isZoomGesturesEnabled());
break;
}
case "map#isLiteModeEnabled":
{
result.success(options.getLiteMode());
break;
}
case "map#isZoomControlsEnabled":
{
result.success(googleMap.getUiSettings().isZoomControlsEnabled());
Expand Down Expand Up @@ -749,6 +756,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ interface GoogleMapOptionsSink {

void setZoomGesturesEnabled(boolean zoomGesturesEnabled);

void setLiteModeEnabled(boolean liteModeEnabled);

void setMyLocationEnabled(boolean myLocationEnabled);

void setZoomControlsEnabled(boolean zoomControlsEnabled);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 GoogleMapExampleAppPage {
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,
),
),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -34,6 +35,7 @@ final List<GoogleMapExampleAppPage> _allPages = <GoogleMapExampleAppPage>[
PlaceCirclePage(),
PaddingPage(),
SnapshotPage(),
LiteModePage(),
];

class MapsDemo extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class GoogleMapInspector {
return await _channel.invokeMethod<bool>('map#isZoomControlsEnabled');
}

Future<bool> isLiteModeEnabled() async {
return await _channel.invokeMethod<bool>('map#isLiteModeEnabled');
}

Future<bool> isRotateGesturesEnabled() async {
return await _channel.invokeMethod<bool>('map#isRotateGesturesEnabled');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,46 @@ void main() {
}
});

testWidgets('testLiteModeEnabled', (WidgetTester tester) async {
final Key key = GlobalKey();
final Completer<GoogleMapInspector> inspectorCompleter =
Completer<GoogleMapInspector>();

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);
}, skip: !Platform.isAndroid);

testWidgets('testRotateGesturesEnabled', (WidgetTester tester) async {
final Key key = GlobalKey();
final Completer<GoogleMapInspector> inspectorCompleter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
library google_maps_flutter;

import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class GoogleMap extends StatefulWidget {
this.scrollGesturesEnabled = true,
this.zoomControlsEnabled = true,
this.zoomGesturesEnabled = true,
this.liteModeEnabled = false,
this.tiltGesturesEnabled = true,
this.myLocationEnabled = false,
this.myLocationButtonEnabled = true,
Expand Down Expand Up @@ -90,6 +91,11 @@ 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;

Expand Down Expand Up @@ -372,13 +378,18 @@ class _GoogleMapOptions {
this.trackCameraPosition,
this.zoomControlsEnabled,
this.zoomGesturesEnabled,
this.liteModeEnabled,
this.myLocationEnabled,
this.myLocationButtonEnabled,
this.padding,
this.indoorViewEnabled,
this.trafficEnabled,
this.buildingsEnabled,
});
}) {
assert(liteModeEnabled == null ||
!liteModeEnabled ||
(liteModeEnabled && Platform.isAndroid));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: what about leaving this as a noop if !Platform.isAndroid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave it as is, an assertion helps the user to be more explicit when using liteMode so they are aware it doesn't work on iOS.

}

static _GoogleMapOptions fromWidget(GoogleMap map) {
return _GoogleMapOptions(
Expand All @@ -393,6 +404,7 @@ class _GoogleMapOptions {
trackCameraPosition: map.onCameraMove != null,
zoomControlsEnabled: map.zoomControlsEnabled,
zoomGesturesEnabled: map.zoomGesturesEnabled,
liteModeEnabled: map.liteModeEnabled,
myLocationEnabled: map.myLocationEnabled,
myLocationButtonEnabled: map.myLocationButtonEnabled,
padding: map.padding,
Expand Down Expand Up @@ -424,6 +436,8 @@ class _GoogleMapOptions {

final bool zoomGesturesEnabled;

final bool liteModeEnabled;

final bool myLocationEnabled;

final bool myLocationButtonEnabled;
Expand Down Expand Up @@ -455,6 +469,7 @@ class _GoogleMapOptions {
addIfNonNull('tiltGesturesEnabled', tiltGesturesEnabled);
addIfNonNull('zoomControlsEnabled', zoomControlsEnabled);
addIfNonNull('zoomGesturesEnabled', zoomGesturesEnabled);
addIfNonNull('liteModeEnabled', liteModeEnabled);
addIfNonNull('trackCameraPosition', trackCameraPosition);
addIfNonNull('myLocationEnabled', myLocationEnabled);
addIfNonNull('myLocationButtonEnabled', myLocationButtonEnabled);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.27+3
version: 0.5.28

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class FakePlatformGoogleMap {

bool zoomControlsEnabled;

bool liteModeEnabled;

bool trackCameraPosition;

bool myLocationEnabled;
Expand Down Expand Up @@ -356,6 +358,9 @@ class FakePlatformGoogleMap {
if (options.containsKey('zoomControlsEnabled')) {
zoomControlsEnabled = options['zoomControlsEnabled'];
}
if (options.containsKey('liteModeEnabled')) {
liteModeEnabled = options['liteModeEnabled'];
}
if (options.containsKey('myLocationEnabled')) {
myLocationEnabled = options['myLocationEnabled'];
}
Expand Down
56 changes: 56 additions & 0 deletions packages/google_maps_flutter/test/android_google_map_test.dart
Original file line number Diff line number Diff line change
@@ -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);
});
}