mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Add map type toggle to place_tracker demo. (#23)
Button will toggle between normal, satellite, terrain, hybrid, and none MapTypes.
This commit is contained in:
@@ -166,7 +166,7 @@ class PlaceMapState extends State<PlaceMap> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onAddPlaceFabPressed() async {
|
void _onAddPlacePressed() async {
|
||||||
Marker newMarker = await mapController.addMarker(
|
Marker newMarker = await mapController.addMarker(
|
||||||
MarkerOptions(
|
MarkerOptions(
|
||||||
position: LatLng(
|
position: LatLng(
|
||||||
@@ -234,6 +234,15 @@ class PlaceMapState extends State<PlaceMap> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onToggleMapTypePressed() {
|
||||||
|
final MapType nextType =
|
||||||
|
MapType.values[(mapController.options.mapType.index + 1) % MapType.values.length];
|
||||||
|
|
||||||
|
mapController.updateMapOptions(
|
||||||
|
GoogleMapOptions(mapType: nextType),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -278,9 +287,10 @@ class PlaceMapState extends State<PlaceMap> {
|
|||||||
onSavePressed: () => _confirmAddPlace(context),
|
onSavePressed: () => _confirmAddPlace(context),
|
||||||
onCancelPressed: _cancelAddPlace,
|
onCancelPressed: _cancelAddPlace,
|
||||||
),
|
),
|
||||||
_AddPlaceFab(
|
_MapFabs(
|
||||||
visible: _pendingMarker == null,
|
visible: _pendingMarker == null,
|
||||||
onPressed: _onAddPlaceFabPressed,
|
onAddPlacePressed: _onAddPlacePressed,
|
||||||
|
onToggleMapTypePressed: _onToggleMapTypePressed,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -307,8 +317,8 @@ class _CategoryButtonBar extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Opacity(
|
return Visibility(
|
||||||
opacity: visible ? 1.0 : 0.0,
|
visible: visible,
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 14.0),
|
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 14.0),
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
@@ -369,8 +379,8 @@ class _AddPlaceButtonBar extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Opacity(
|
return Visibility(
|
||||||
opacity: visible ? 1.0 : 0.0,
|
visible: visible,
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 14.0),
|
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 14.0),
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
@@ -400,33 +410,49 @@ class _AddPlaceButtonBar extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AddPlaceFab extends StatelessWidget {
|
class _MapFabs extends StatelessWidget {
|
||||||
const _AddPlaceFab({
|
const _MapFabs({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.visible,
|
@required this.visible,
|
||||||
@required this.onPressed,
|
@required this.onAddPlacePressed,
|
||||||
|
@required this.onToggleMapTypePressed,
|
||||||
}) : assert(visible != null),
|
}) : assert(visible != null),
|
||||||
assert(onPressed != null),
|
assert(onAddPlacePressed != null),
|
||||||
|
assert(onToggleMapTypePressed != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
final bool visible;
|
final bool visible;
|
||||||
final VoidCallback onPressed;
|
final VoidCallback onAddPlacePressed;
|
||||||
|
final VoidCallback onToggleMapTypePressed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Opacity(
|
return Container(
|
||||||
opacity: visible ? 1.0 : 0.0,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: Align(
|
|
||||||
alignment: Alignment.topRight,
|
alignment: Alignment.topRight,
|
||||||
child: FloatingActionButton(
|
margin: const EdgeInsets.only(top: 12.0, right: 12.0),
|
||||||
onPressed: onPressed,
|
child: Visibility(
|
||||||
|
visible: visible,
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
FloatingActionButton(
|
||||||
|
heroTag: "add_place_button",
|
||||||
|
onPressed: onAddPlacePressed,
|
||||||
materialTapTargetSize: MaterialTapTargetSize.padded,
|
materialTapTargetSize: MaterialTapTargetSize.padded,
|
||||||
backgroundColor: Colors.green,
|
backgroundColor: Colors.green,
|
||||||
child: const Icon(Icons.add_location, size: 36.0),
|
child: const Icon(Icons.add_location, size: 36.0),
|
||||||
),
|
),
|
||||||
|
SizedBox(height: 12.0),
|
||||||
|
FloatingActionButton(
|
||||||
|
heroTag: "toggle_map_type_button",
|
||||||
|
onPressed: onToggleMapTypePressed,
|
||||||
|
materialTapTargetSize: MaterialTapTargetSize.padded,
|
||||||
|
mini: true,
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
child: const Icon(Icons.layers, size: 28.0),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user