Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/google_maps_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import 'map_ui.dart';
import 'move_camera.dart';
import 'page.dart';
import 'place_marker.dart';
import 'scrolling_map.dart';

final List<Page> _allPages = <Page>[
MapUiPage(),
AnimateCameraPage(),
MoveCameraPage(),
PlaceMarkerPage(),
ScrollingMapPage(),
];

class MapsDemo extends StatelessWidget {
Expand Down
107 changes: 107 additions & 0 deletions packages/google_maps_flutter/example/lib/scrolling_map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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.

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

import 'page.dart';

class ScrollingMapPage extends Page {
ScrollingMapPage() : super(const Icon(Icons.map), 'Scrolling map');

@override
Widget build(BuildContext context) {
return const ScrollingMapBody();
}
}

class ScrollingMapBody extends StatelessWidget {
const ScrollingMapBody();

final LatLng center = const LatLng(32.080664, 34.9563837);

@override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
new Card(
child: new Padding(
padding: const EdgeInsets.symmetric(vertical: 30.0),
child: new Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.only(bottom: 12.0),
child: Text('This map consumes all touch events.'),
),
Center(
child: SizedBox(
width: 300.0,
height: 300.0,
child: GoogleMap(
onMapCreated: onMapCreated,
options: new GoogleMapOptions(
cameraPosition: CameraPosition(
target: center,
zoom: 11.0,
),
),
gestureRecognizers: <OneSequenceGestureRecognizer>[
new EagerGestureRecognizer()
],
),
),
),
],
),
),
),
new Card(
child: new Padding(
padding: const EdgeInsets.symmetric(vertical: 30.0),
child: new Column(
children: <Widget>[
const Text('This map doesn\'t consume the vertical drags.'),
const Padding(
padding: EdgeInsets.only(bottom: 12.0),
child:
Text('It still gets other gestures (e.g scale or tap).'),
),
Center(
child: SizedBox(
width: 300.0,
height: 300.0,
child: GoogleMap(
onMapCreated: onMapCreated,
options: new GoogleMapOptions(
cameraPosition: CameraPosition(
target: center,
zoom: 11.0,
),
),
gestureRecognizers: <OneSequenceGestureRecognizer>[
ScaleGestureRecognizer()
],
),
),
),
],
),
),
),
],
);
}

void onMapCreated(GoogleMapController controller) {
controller.addMarker(MarkerOptions(
position: LatLng(
center.latitude,
center.longitude,
),
infoWindowText: const InfoWindowText('An interesting location', '*'),
));
}
}
1 change: 1 addition & 0 deletions packages/google_maps_flutter/lib/google_maps_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:async';
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand Down
25 changes: 23 additions & 2 deletions packages/google_maps_flutter/lib/src/google_map.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
// 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.

part of google_maps_flutter;

typedef void MapCreatedCallback(GoogleMapController controller);

class GoogleMap extends StatefulWidget {
GoogleMap({@required this.onMapCreated, GoogleMapOptions options})
: this.options = GoogleMapOptions.defaultOptions.copyWith(options);
GoogleMap({
@required this.onMapCreated,
GoogleMapOptions options,
this.gestureRecognizers = const <OneSequenceGestureRecognizer>[],
}) : assert(gestureRecognizers != null),
this.options = GoogleMapOptions.defaultOptions.copyWith(options);

final MapCreatedCallback onMapCreated;

final GoogleMapOptions options;

/// Which gestures should be consumed by the map.
///
/// It is possible for other gesture recognizers to be competing with the map on pointer
/// events, e.g if the map is inside a [ListView] the [ListView] will want to handle
/// vertical drags. The map will claim gestures that are recognized by any of the
/// recognizers on this list.
///
/// When this list is empty, the map will only handle pointer events for gestures that
/// were not claimed by any other gesture recognizer.
final List<OneSequenceGestureRecognizer> gestureRecognizers;

@override
State createState() => new _GoogleMapState();
}
Expand All @@ -20,6 +40,7 @@ class _GoogleMapState extends State<GoogleMap> {
return AndroidView(
viewType: 'plugins.flutter.io/google_maps',
onPlatformViewCreated: onPlatformViewCreated,
gestureRecognizers: widget.gestureRecognizers,
creationParams: widget.options._toJson(),
creationParamsCodec: const StandardMessageCodec(),
);
Expand Down