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

Commit 82f8f49

Browse files
authored
[google_maps_flutter] Add liteModeEnabled option (#2449)
1 parent 7bb3663 commit 82f8f49

14 files changed

Lines changed: 198 additions & 2 deletions

File tree

packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.28
2+
3+
* Android: Add liteModeEnabled option.
4+
15
## 0.5.27+3
26

37
* iOS: Update the gesture recognizer blocking policy to "WaitUntilTouchesEnded", which fixes the camera idle callback not triggered issue.

packages/google_maps_flutter/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ static void interpretGoogleMapOptions(Object o, GoogleMapOptionsSink sink) {
316316
if (zoomGesturesEnabled != null) {
317317
sink.setZoomGesturesEnabled(toBoolean(zoomGesturesEnabled));
318318
}
319+
final Object liteModeEnabled = data.get("liteModeEnabled");
320+
if (liteModeEnabled != null) {
321+
sink.setLiteModeEnabled(toBoolean(liteModeEnabled));
322+
}
319323
final Object myLocationEnabled = data.get("myLocationEnabled");
320324
if (myLocationEnabled != null) {
321325
sink.setMyLocationEnabled(toBoolean(myLocationEnabled));

packages/google_maps_flutter/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) {
128128
options.zoomGesturesEnabled(zoomGesturesEnabled);
129129
}
130130

131+
@Override
132+
public void setLiteModeEnabled(boolean liteModeEnabled) {
133+
options.liteMode(liteModeEnabled);
134+
}
135+
131136
@Override
132137
public void setIndoorEnabled(boolean indoorEnabled) {
133138
this.indoorEnabled = indoorEnabled;

packages/google_maps_flutter/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ final class GoogleMapController
7070
private final int id;
7171
private final AtomicInteger activityState;
7272
private final MethodChannel methodChannel;
73+
private final GoogleMapOptions options;
7374
private final MapView mapView;
7475
private GoogleMap googleMap;
7576
private boolean trackCameraPosition = false;
@@ -111,6 +112,7 @@ final class GoogleMapController
111112
this.id = id;
112113
this.context = context;
113114
this.activityState = activityState;
115+
this.options = options;
114116
this.mapView = new MapView(context, options);
115117
this.density = context.getResources().getDisplayMetrics().density;
116118
methodChannel = new MethodChannel(binaryMessenger, "plugins.flutter.io/google_maps_" + id);
@@ -383,6 +385,11 @@ public void onSnapshotReady(Bitmap bitmap) {
383385
result.success(googleMap.getUiSettings().isZoomGesturesEnabled());
384386
break;
385387
}
388+
case "map#isLiteModeEnabled":
389+
{
390+
result.success(options.getLiteMode());
391+
break;
392+
}
386393
case "map#isZoomControlsEnabled":
387394
{
388395
result.success(googleMap.getUiSettings().isZoomControlsEnabled());
@@ -749,6 +756,12 @@ public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) {
749756
googleMap.getUiSettings().setZoomGesturesEnabled(zoomGesturesEnabled);
750757
}
751758

759+
/** This call will have no effect on already created map */
760+
@Override
761+
public void setLiteModeEnabled(boolean liteModeEnabled) {
762+
options.liteMode(liteModeEnabled);
763+
}
764+
752765
@Override
753766
public void setMyLocationEnabled(boolean myLocationEnabled) {
754767
if (this.myLocationEnabled == myLocationEnabled) {

packages/google_maps_flutter/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ interface GoogleMapOptionsSink {
3030

3131
void setZoomGesturesEnabled(boolean zoomGesturesEnabled);
3232

33+
void setLiteModeEnabled(boolean liteModeEnabled);
34+
3335
void setMyLocationEnabled(boolean myLocationEnabled);
3436

3537
void setZoomControlsEnabled(boolean zoomControlsEnabled);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2019 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+
// ignore_for_file: public_member_api_docs
6+
7+
import 'package:flutter/material.dart';
8+
import 'package:flutter/widgets.dart';
9+
import 'package:google_maps_flutter/google_maps_flutter.dart';
10+
import 'page.dart';
11+
12+
const CameraPosition _kInitialPosition =
13+
CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0);
14+
15+
class LiteModePage extends GoogleMapExampleAppPage {
16+
LiteModePage() : super(const Icon(Icons.map), 'Lite mode');
17+
18+
@override
19+
Widget build(BuildContext context) {
20+
return const _LiteModeBody();
21+
}
22+
}
23+
24+
class _LiteModeBody extends StatelessWidget {
25+
const _LiteModeBody();
26+
27+
@override
28+
Widget build(BuildContext context) {
29+
return Card(
30+
child: Padding(
31+
padding: const EdgeInsets.symmetric(vertical: 30.0),
32+
child: Center(
33+
child: SizedBox(
34+
width: 300.0,
35+
height: 300.0,
36+
child: GoogleMap(
37+
initialCameraPosition: _kInitialPosition,
38+
liteModeEnabled: true,
39+
),
40+
),
41+
),
42+
),
43+
);
44+
}
45+
}

packages/google_maps_flutter/google_maps_flutter/example/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// ignore_for_file: public_member_api_docs
66

77
import 'package:flutter/material.dart';
8+
import 'package:google_maps_flutter_example/lite_mode.dart';
89
import 'animate_camera.dart';
910
import 'map_click.dart';
1011
import 'map_coordinates.dart';
@@ -34,6 +35,7 @@ final List<GoogleMapExampleAppPage> _allPages = <GoogleMapExampleAppPage>[
3435
PlaceCirclePage(),
3536
PaddingPage(),
3637
SnapshotPage(),
38+
LiteModePage(),
3739
];
3840

3941
class MapsDemo extends StatelessWidget {

packages/google_maps_flutter/google_maps_flutter/example/test_driver/google_map_inspector.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class GoogleMapInspector {
4545
return await _channel.invokeMethod<bool>('map#isZoomControlsEnabled');
4646
}
4747

48+
Future<bool> isLiteModeEnabled() async {
49+
return await _channel.invokeMethod<bool>('map#isLiteModeEnabled');
50+
}
51+
4852
Future<bool> isRotateGesturesEnabled() async {
4953
return await _channel.invokeMethod<bool>('map#isRotateGesturesEnabled');
5054
}

packages/google_maps_flutter/google_maps_flutter/example/test_driver/google_maps_e2e.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,46 @@ void main() {
263263
}
264264
});
265265

266+
testWidgets('testLiteModeEnabled', (WidgetTester tester) async {
267+
final Key key = GlobalKey();
268+
final Completer<GoogleMapInspector> inspectorCompleter =
269+
Completer<GoogleMapInspector>();
270+
271+
await tester.pumpWidget(Directionality(
272+
textDirection: TextDirection.ltr,
273+
child: GoogleMap(
274+
key: key,
275+
initialCameraPosition: _kInitialCameraPosition,
276+
liteModeEnabled: false,
277+
onMapCreated: (GoogleMapController controller) {
278+
final GoogleMapInspector inspector =
279+
// ignore: invalid_use_of_visible_for_testing_member
280+
GoogleMapInspector(controller.channel);
281+
inspectorCompleter.complete(inspector);
282+
},
283+
),
284+
));
285+
286+
final GoogleMapInspector inspector = await inspectorCompleter.future;
287+
bool liteModeEnabled = await inspector.isLiteModeEnabled();
288+
expect(liteModeEnabled, false);
289+
290+
await tester.pumpWidget(Directionality(
291+
textDirection: TextDirection.ltr,
292+
child: GoogleMap(
293+
key: key,
294+
initialCameraPosition: _kInitialCameraPosition,
295+
liteModeEnabled: true,
296+
onMapCreated: (GoogleMapController controller) {
297+
fail("OnMapCreated should get called only once.");
298+
},
299+
),
300+
));
301+
302+
liteModeEnabled = await inspector.isLiteModeEnabled();
303+
expect(liteModeEnabled, true);
304+
}, skip: !Platform.isAndroid);
305+
266306
testWidgets('testRotateGesturesEnabled', (WidgetTester tester) async {
267307
final Key key = GlobalKey();
268308
final Completer<GoogleMapInspector> inspectorCompleter =

packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library google_maps_flutter;
66

77
import 'dart:async';
8+
import 'dart:io';
89
import 'dart:typed_data';
910
import 'dart:ui';
1011

0 commit comments

Comments
 (0)