@ -11,41 +11,55 @@ import 'place.dart';
import ' place_details.dart ' ;
import ' place_details.dart ' ;
import ' place_tracker_app.dart ' ;
import ' place_tracker_app.dart ' ;
class MapConfiguration {
final List < Place > places ;
final PlaceCategory selectedCategory ;
const MapConfiguration ( {
@ required this . places ,
@ required this . selectedCategory ,
} ) : assert ( places ! = null ) ,
assert ( selectedCategory ! = null ) ;
@ override
int get hashCode = > places . hashCode ^ selectedCategory . hashCode ;
@ override
bool operator = = ( Object other ) {
if ( identical ( this , other ) ) {
return true ;
}
if ( other . runtimeType ! = runtimeType ) {
return false ;
}
return other is MapConfiguration & &
other . places = = places & &
other . selectedCategory = = selectedCategory ;
}
static MapConfiguration of ( AppState appState ) {
return MapConfiguration (
places: appState . places ,
selectedCategory: appState . selectedCategory ,
) ;
}
}
class PlaceMap extends StatefulWidget {
class PlaceMap extends StatefulWidget {
final LatLng center ;
const PlaceMap ( {
const PlaceMap ( {
Key key ,
Key key ,
this . center ,
this . center ,
} ) : super ( key: key ) ;
} ) : super ( key: key ) ;
final LatLng center ;
@ override
@ override
PlaceMapState createState ( ) = > PlaceMapState ( ) ;
PlaceMapState createState ( ) = > PlaceMapState ( ) ;
}
}
class PlaceMapState extends State < PlaceMap > {
class PlaceMapState extends State < PlaceMap > {
static Future < BitmapDescriptor > _getPlaceMarkerIcon (
BuildContext context , PlaceCategory category ) async {
switch ( category ) {
case PlaceCategory . favorite:
return BitmapDescriptor . fromAssetImage (
createLocalImageConfiguration ( context ) , ' assets/heart.png ' ) ;
break ;
case PlaceCategory . visited:
return BitmapDescriptor . fromAssetImage (
createLocalImageConfiguration ( context ) , ' assets/visited.png ' ) ;
break ;
case PlaceCategory . wantToGo:
default :
return BitmapDescriptor . defaultMarker ;
}
}
static List < Place > _getPlacesForCategory (
PlaceCategory category , List < Place > places ) {
return places . where ( ( place ) = > place . category = = category ) . toList ( ) ;
}
Completer < GoogleMapController > mapController = Completer ( ) ;
Completer < GoogleMapController > mapController = Completer ( ) ;
MapType _currentMapType = MapType . normal ;
MapType _currentMapType = MapType . normal ;
@ -60,6 +74,50 @@ class PlaceMapState extends State<PlaceMap> {
MapConfiguration _configuration ;
MapConfiguration _configuration ;
@ override
Widget build ( BuildContext context ) {
_maybeUpdateMapConfiguration ( ) ;
var state = Provider . of < AppState > ( context ) ;
return Builder ( builder: ( context ) {
/ / We need this additional builder here so that we can pass its context to
/ / _AddPlaceButtonBar ' s onSavePressed callback. This callback shows a
/ / SnackBar and to do this , we need a build context that has Scaffold as
/ / an ancestor .
return Center (
child: Stack (
children: [
GoogleMap (
onMapCreated: onMapCreated ,
initialCameraPosition: CameraPosition (
target: widget . center ,
zoom: 11.0 ,
) ,
mapType: _currentMapType ,
markers: _markers ,
onCameraMove: ( position ) = > _lastMapPosition = position . target ,
) ,
_CategoryButtonBar (
selectedPlaceCategory: state . selectedCategory ,
visible: _pendingMarker = = null ,
onChanged: _switchSelectedCategory ,
) ,
_AddPlaceButtonBar (
visible: _pendingMarker ! = null ,
onSavePressed: ( ) = > _confirmAddPlace ( context ) ,
onCancelPressed: _cancelAddPlace ,
) ,
_MapFabs (
visible: _pendingMarker = = null ,
onAddPlacePressed: _onAddPlacePressed ,
onToggleMapTypePressed: _onToggleMapTypePressed ,
) ,
] ,
) ,
) ;
} ) ;
}
Future < void > onMapCreated ( GoogleMapController controller ) async {
Future < void > onMapCreated ( GoogleMapController controller ) async {
mapController . complete ( controller ) ;
mapController . complete ( controller ) ;
_lastMapPosition = widget . center ;
_lastMapPosition = widget . center ;
@ -83,6 +141,82 @@ class PlaceMapState extends State<PlaceMap> {
) ;
) ;
}
}
void _cancelAddPlace ( ) {
if ( _pendingMarker ! = null ) {
setState ( ( ) {
_markers . remove ( _pendingMarker ) ;
_pendingMarker = null ;
} ) ;
}
}
Future < void > _confirmAddPlace ( BuildContext context ) async {
if ( _pendingMarker ! = null ) {
/ / Create a new Place and map it to the marker we just added .
final newPlace = Place (
id: Uuid ( ) . v1 ( ) ,
latLng: _pendingMarker . position ,
name: _pendingMarker . infoWindow . title ,
category:
Provider . of < AppState > ( context , listen: false ) . selectedCategory ,
) ;
var placeMarker = await _getPlaceMarkerIcon ( context ,
Provider . of < AppState > ( context , listen: false ) . selectedCategory ) ;
setState ( ( ) {
final updatedMarker = _pendingMarker . copyWith (
iconParam: placeMarker ,
infoWindowParam: InfoWindow (
title: ' New Place ' ,
snippet: null ,
onTap: ( ) = > _pushPlaceDetailsScreen ( newPlace ) ,
) ,
draggableParam: false ,
) ;
_updateMarker (
marker: _pendingMarker ,
updatedMarker: updatedMarker ,
place: newPlace ,
) ;
_pendingMarker = null ;
} ) ;
/ / Show a confirmation snackbar that has an action to edit the new place .
Scaffold . of ( context ) . showSnackBar (
SnackBar (
duration: Duration ( seconds: 3 ) ,
content:
const Text ( ' New place added. ' , style: TextStyle ( fontSize: 16.0 ) ) ,
action: SnackBarAction (
label: ' Edit ' ,
onPressed: ( ) async {
_pushPlaceDetailsScreen ( newPlace ) ;
} ,
) ,
) ,
) ;
/ / Add the new place to the places stored in appState .
final newPlaces =
List < Place > . from ( Provider . of < AppState > ( context , listen: false ) . places )
. . add ( newPlace ) ;
/ / Manually update our map configuration here since our map is already
/ / updated with the new marker . Otherwise , the map would be reconfigured
/ / in the main build method due to a modified AppState .
_configuration = MapConfiguration (
places: newPlaces ,
selectedCategory:
Provider . of < AppState > ( context , listen: false ) . selectedCategory ,
) ;
Provider . of < AppState > ( context , listen: false ) . setPlaces ( newPlaces ) ;
}
}
Future < Marker > _createPlaceMarker ( BuildContext context , Place place ) async {
Future < Marker > _createPlaceMarker ( BuildContext context , Place place ) async {
final marker = Marker (
final marker = Marker (
markerId: MarkerId ( place . latLng . toString ( ) ) ,
markerId: MarkerId ( place . latLng . toString ( ) ) ,
@ -100,18 +234,53 @@ class PlaceMapState extends State<PlaceMap> {
return marker ;
return marker ;
}
}
void _pushPlaceDetailsScreen ( Place place ) {
Future < void > _maybeUpdateMapConfiguration ( ) async {
assert ( place ! = null ) ;
_configuration ? ? =
MapConfiguration . of ( Provider . of < AppState > ( context , listen: false ) ) ;
final newConfiguration =
MapConfiguration . of ( Provider . of < AppState > ( context , listen: false ) ) ;
Navigator . push < void > (
/ / Since we manually update [ _configuration ] when place or selectedCategory
context ,
/ / changes come from the [ place_map ] , we should only enter this if statement
MaterialPageRoute ( builder: ( context ) {
/ / when returning to the [ place_map ] after changes have been made from
return PlaceDetails (
/ / [ place_list ] .
place: place ,
if ( _configuration ! = newConfiguration & & mapController ! = null ) {
onChanged: ( value ) = > _onPlaceChanged ( value ) ,
if ( _configuration . places = = newConfiguration . places & &
_configuration . selectedCategory ! =
newConfiguration . selectedCategory ) {
/ / If the configuration change is only a category change , just update
/ / the marker visibilities .
await _showPlacesForSelectedCategory ( newConfiguration . selectedCategory ) ;
} else {
/ / At this point , we know the places have been updated from the list
/ / view . We need to reconfigure the map to respect the updates .
newConfiguration . places
. where ( ( p ) = > ! _configuration . places . contains ( p ) )
. map ( ( value ) = > _updateExistingPlaceMarker ( place: value ) ) ;
await _zoomToFitPlaces (
_getPlacesForCategory (
newConfiguration . selectedCategory ,
newConfiguration . places ,
) ,
) ;
) ;
} ) ,
}
_configuration = newConfiguration ;
}
}
Future < void > _onAddPlacePressed ( ) async {
setState ( ( ) {
final newMarker = Marker (
markerId: MarkerId ( _lastMapPosition . toString ( ) ) ,
position: _lastMapPosition ,
infoWindow: InfoWindow ( title: ' New Place ' ) ,
draggable: true ,
icon: BitmapDescriptor . defaultMarkerWithHue ( BitmapDescriptor . hueGreen ) ,
) ;
) ;
_markers . add ( newMarker ) ;
_pendingMarker = newMarker ;
} ) ;
}
}
void _onPlaceChanged ( Place value ) {
void _onPlaceChanged ( Place value ) {
@ -135,37 +304,27 @@ class PlaceMapState extends State<PlaceMap> {
Provider . of < AppState > ( context , listen: false ) . setPlaces ( newPlaces ) ;
Provider . of < AppState > ( context , listen: false ) . setPlaces ( newPlaces ) ;
}
}
void _ updateExistingPlaceMarker( { @ required Place place } ) {
void _ onToggleMapTypePressed( ) {
var marker = _markedPlaces . keys
final nextType =
. singleWhere ( ( value ) = > _markedPlaces [ value ] . id = = place . id ) ;
MapType . values [ ( _currentMapType . index + 1 ) % MapType . values . length ] ;
setState ( ( ) {
setState ( ( ) {
final updatedMarker = marker . copyWith (
_currentMapType = nextType ;
infoWindowParam: InfoWindow (
title: place . name ,
snippet:
place . starRating ! = 0 ? ' ${ place . starRating } Star Rating ' : null ,
) ,
) ;
_updateMarker ( marker: marker , updatedMarker: updatedMarker , place: place ) ;
} ) ;
} ) ;
}
}
void _updateMarker ( {
void _pushPlaceDetailsScreen ( Place place ) {
@ required Marker marker ,
assert ( place ! = null ) ;
@ required Marker updatedMarker ,
@ required Place place ,
} ) {
_markers . remove ( marker ) ;
_markedPlaces . remove ( marker ) ;
_markers . add ( updatedMarker ) ;
_markedPlaces [ updatedMarker ] = place ;
}
Future < void > _switchSelectedCategory ( PlaceCategory category ) async {
Navigator . push < void > (
Provider . of < AppState > ( context , listen: false ) . setSelectedCategory ( category ) ;
context ,
await _showPlacesForSelectedCategory ( category ) ;
MaterialPageRoute ( builder: ( context ) {
return PlaceDetails (
place: place ,
onChanged: ( value ) = > _onPlaceChanged ( value ) ,
) ;
} ) ,
) ;
}
}
Future < void > _showPlacesForSelectedCategory ( PlaceCategory category ) async {
Future < void > _showPlacesForSelectedCategory ( PlaceCategory category ) async {
@ -190,213 +349,142 @@ class PlaceMapState extends State<PlaceMap> {
) ) ;
) ) ;
}
}
Future < void > _zoomToFitPlaces ( List < Place > places ) async {
Future < void > _switchSelectedCategory ( PlaceCategory category ) async {
var controller = await mapController . future ;
Provider . of < AppState > ( context , listen: false ) . setSelectedCategory ( category ) ;
await _showPlacesForSelectedCategory ( category ) ;
/ / Default min / max values to latitude and longitude of center .
var minLat = widget . center . latitude ;
var maxLat = widget . center . latitude ;
var minLong = widget . center . longitude ;
var maxLong = widget . center . longitude ;
for ( var place in places ) {
minLat = min ( minLat , place . latitude ) ;
maxLat = max ( maxLat , place . latitude ) ;
minLong = min ( minLong , place . longitude ) ;
maxLong = max ( maxLong , place . longitude ) ;
}
await controller . animateCamera (
CameraUpdate . newLatLngBounds (
LatLngBounds (
southwest: LatLng ( minLat , minLong ) ,
northeast: LatLng ( maxLat , maxLong ) ,
) ,
48.0 ,
) ,
) ;
}
Future < void > _onAddPlacePressed ( ) async {
setState ( ( ) {
final newMarker = Marker (
markerId: MarkerId ( _lastMapPosition . toString ( ) ) ,
position: _lastMapPosition ,
infoWindow: InfoWindow ( title: ' New Place ' ) ,
draggable: true ,
icon: BitmapDescriptor . defaultMarkerWithHue ( BitmapDescriptor . hueGreen ) ,
) ;
_markers . add ( newMarker ) ;
_pendingMarker = newMarker ;
} ) ;
}
}
Future < void > _confirmAddPlace ( BuildContext context ) async {
void _updateExistingPlaceMarker ( { @ required Place place } ) {
if ( _pendingMarker ! = null ) {
var marker = _markedPlaces . keys
/ / Create a new Place and map it to the marker we just added .
. singleWhere ( ( value ) = > _markedPlaces [ value ] . id = = place . id ) ;
final newPlace = Place (
id: Uuid ( ) . v1 ( ) ,
latLng: _pendingMarker . position ,
name: _pendingMarker . infoWindow . title ,
category:
Provider . of < AppState > ( context , listen: false ) . selectedCategory ,
) ;
var placeMarker = await _getPlaceMarkerIcon ( context ,
Provider . of < AppState > ( context , listen: false ) . selectedCategory ) ;
setState ( ( ) {
final updatedMarker = _pendingMarker . copyWith (
iconParam: placeMarker ,
infoWindowParam: InfoWindow (
title: ' New Place ' ,
snippet: null ,
onTap: ( ) = > _pushPlaceDetailsScreen ( newPlace ) ,
) ,
draggableParam: false ,
) ;
_updateMarker (
marker: _pendingMarker ,
updatedMarker: updatedMarker ,
place: newPlace ,
) ;
_pendingMarker = null ;
} ) ;
/ / Show a confirmation snackbar that has an action to edit the new place .
Scaffold . of ( context ) . showSnackBar (
SnackBar (
duration: Duration ( seconds: 3 ) ,
content:
const Text ( ' New place added. ' , style: TextStyle ( fontSize: 16.0 ) ) ,
action: SnackBarAction (
label: ' Edit ' ,
onPressed: ( ) async {
_pushPlaceDetailsScreen ( newPlace ) ;
} ,
) ,
) ,
) ;
/ / Add the new place to the places stored in appState .
final newPlaces =
List < Place > . from ( Provider . of < AppState > ( context , listen: false ) . places )
. . add ( newPlace ) ;
/ / Manually update our map configuration here since our map is already
/ / updated with the new marker . Otherwise , the map would be reconfigured
/ / in the main build method due to a modified AppState .
_configuration = MapConfiguration (
places: newPlaces ,
selectedCategory:
Provider . of < AppState > ( context , listen: false ) . selectedCategory ,
) ;
Provider . of < AppState > ( context , listen: false ) . setPlaces ( newPlaces ) ;
}
}
void _cancelAddPlace ( ) {
if ( _pendingMarker ! = null ) {
setState ( ( ) {
setState ( ( ) {
_markers . remove ( _pendingMarker ) ;
final updatedMarker = marker . copyWith (
_pendingMarker = null ;
infoWindowParam: InfoWindow (
title: place . name ,
snippet:
place . starRating ! = 0 ? ' ${ place . starRating } Star Rating ' : null ,
) ,
) ;
_updateMarker ( marker: marker , updatedMarker: updatedMarker , place: place ) ;
} ) ;
} ) ;
}
}
}
void _onToggleMapTypePressed ( ) {
void _updateMarker ( {
final nextType =
@ required Marker marker ,
MapType . values [ ( _currentMapType . index + 1 ) % MapType . values . length ] ;
@ required Marker updatedMarker ,
@ required Place place ,
} ) {
_markers . remove ( marker ) ;
_markedPlaces . remove ( marker ) ;
setState ( ( ) {
_markers . add ( updatedMarker ) ;
_currentMapType = nextType ;
_markedPlaces [ updatedMarker ] = place ;
} ) ;
}
}
Future < void > _maybeUpdateMapConfiguration ( ) async {
Future < void > _zoomToFitPlaces ( List < Place > places ) async {
_configuration ? ? =
var controller = await mapController . future ;
MapConfiguration . of ( Provider . of < AppState > ( context , listen: false ) ) ;
final newConfiguration =
MapConfiguration . of ( Provider . of < AppState > ( context , listen: false ) ) ;
/ / Since we manually update [ _configuration ] when place or selectedCategory
/ / Default min / max values to latitude and longitude of center .
/ / changes come from the [ place_map ] , we should only enter this if statement
var minLat = widget . center . latitude ;
/ / when returning to the [ place_map ] after changes have been made from
var maxLat = widget . center . latitude ;
/ / [ place_list ] .
var minLong = widget . center . longitude ;
if ( _configuration ! = newConfiguration & & mapController ! = null ) {
var maxLong = widget . center . longitude ;
if ( _configuration . places = = newConfiguration . places & &
_configuration . selectedCategory ! =
newConfiguration . selectedCategory ) {
/ / If the configuration change is only a category change , just update
/ / the marker visibilities .
await _showPlacesForSelectedCategory ( newConfiguration . selectedCategory ) ;
} else {
/ / At this point , we know the places have been updated from the list
/ / view . We need to reconfigure the map to respect the updates .
newConfiguration . places
. where ( ( p ) = > ! _configuration . places . contains ( p ) )
. map ( ( value ) = > _updateExistingPlaceMarker ( place: value ) ) ;
await _zoomToFitPlaces (
for ( var place in places ) {
_getPlacesForCategory (
minLat = min ( minLat , place . latitude ) ;
newConfiguration . selectedCategory ,
maxLat = max ( maxLat , place . latitude ) ;
newConfiguration . places ,
minLong = min ( minLong , place . longitude ) ;
maxLong = max ( maxLong , place . longitude ) ;
}
await controller . animateCamera (
CameraUpdate . newLatLngBounds (
LatLngBounds (
southwest: LatLng ( minLat , minLong ) ,
northeast: LatLng ( maxLat , maxLong ) ,
) ,
48.0 ,
) ,
) ,
) ;
) ;
}
}
_configuration = newConfiguration ;
static Future < BitmapDescriptor > _getPlaceMarkerIcon (
BuildContext context , PlaceCategory category ) async {
switch ( category ) {
case PlaceCategory . favorite:
return BitmapDescriptor . fromAssetImage (
createLocalImageConfiguration ( context ) , ' assets/heart.png ' ) ;
break ;
case PlaceCategory . visited:
return BitmapDescriptor . fromAssetImage (
createLocalImageConfiguration ( context ) , ' assets/visited.png ' ) ;
break ;
case PlaceCategory . wantToGo:
default :
return BitmapDescriptor . defaultMarker ;
}
}
}
}
static List < Place > _getPlacesForCategory (
PlaceCategory category , List < Place > places ) {
return places . where ( ( place ) = > place . category = = category ) . toList ( ) ;
}
}
class _AddPlaceButtonBar extends StatelessWidget {
final bool visible ;
final VoidCallback onSavePressed ;
final VoidCallback onCancelPressed ;
const _AddPlaceButtonBar ( {
Key key ,
@ required this . visible ,
@ required this . onSavePressed ,
@ required this . onCancelPressed ,
} ) : assert ( visible ! = null ) ,
assert ( onSavePressed ! = null ) ,
assert ( onCancelPressed ! = null ) ,
super ( key: key ) ;
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
_maybeUpdateMapConfiguration ( ) ;
return Visibility (
var state = Provider . of < AppState > ( context ) ;
visible: visible ,
child: Container (
return Builder ( builder: ( context ) {
padding: const EdgeInsets . fromLTRB ( 0.0 , 0.0 , 0.0 , 14.0 ) ,
/ / We need this additional builder here so that we can pass its context to
alignment: Alignment . bottomCenter ,
/ / _AddPlaceButtonBar ' s onSavePressed callback. This callback shows a
child: ButtonBar (
/ / SnackBar and to do this , we need a build context that has Scaffold as
alignment: MainAxisAlignment . center ,
/ / an ancestor .
children: [
return Center (
RaisedButton (
child: Stack (
color: Colors . blue ,
children: < Widget > [
child: const Text (
GoogleMap (
' Save ' ,
onMapCreated: onMapCreated ,
style: TextStyle ( color: Colors . white , fontSize: 16.0 ) ,
initialCameraPosition: CameraPosition (
target: widget . center ,
zoom: 11.0 ,
) ,
mapType: _currentMapType ,
markers: _markers ,
onCameraMove: ( position ) = > _lastMapPosition = position . target ,
) ,
) ,
_CategoryButtonBar (
onPressed: onSavePressed ,
selectedPlaceCategory: state . selectedCategory ,
visible: _pendingMarker = = null ,
onChanged: _switchSelectedCategory ,
) ,
) ,
_AddPlaceButtonBar (
RaisedButton (
visible: _pendingMarker ! = null ,
color: Colors . red ,
onSavePressed: ( ) = > _confirmAddPlace ( context ) ,
child: const Text (
onCancelPressed: _cancelAddPlace ,
' Cancel ' ,
style: TextStyle ( color: Colors . white , fontSize: 16.0 ) ,
) ,
) ,
_MapFabs (
onPressed: onCancelPressed ,
visible: _pendingMarker = = null ,
onAddPlacePressed: _onAddPlacePressed ,
onToggleMapTypePressed: _onToggleMapTypePressed ,
) ,
) ,
] ,
] ,
) ,
) ,
) ,
) ;
) ;
} ) ;
}
}
}
}
class _CategoryButtonBar extends StatelessWidget {
class _CategoryButtonBar extends StatelessWidget {
final PlaceCategory selectedPlaceCategory ;
final bool visible ;
final ValueChanged < PlaceCategory > onChanged ;
const _CategoryButtonBar ( {
const _CategoryButtonBar ( {
Key key ,
Key key ,
@ required this . selectedPlaceCategory ,
@ required this . selectedPlaceCategory ,
@ -407,10 +495,6 @@ class _CategoryButtonBar extends StatelessWidget {
assert ( onChanged ! = null ) ,
assert ( onChanged ! = null ) ,
super ( key: key ) ;
super ( key: key ) ;
final PlaceCategory selectedPlaceCategory ;
final bool visible ;
final ValueChanged < PlaceCategory > onChanged ;
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
return Visibility (
return Visibility (
@ -420,7 +504,7 @@ class _CategoryButtonBar extends StatelessWidget {
alignment: Alignment . bottomCenter ,
alignment: Alignment . bottomCenter ,
child: ButtonBar (
child: ButtonBar (
alignment: MainAxisAlignment . center ,
alignment: MainAxisAlignment . center ,
children: < Widget > [
children: [
RaisedButton (
RaisedButton (
color: selectedPlaceCategory = = PlaceCategory . favorite
color: selectedPlaceCategory = = PlaceCategory . favorite
? Colors . green [ 700 ]
? Colors . green [ 700 ]
@ -458,55 +542,11 @@ class _CategoryButtonBar extends StatelessWidget {
}
}
}
}
class _AddPlaceButtonBar extends StatelessWidget {
class _MapFabs extends StatelessWidget {
const _AddPlaceButtonBar ( {
Key key ,
@ required this . visible ,
@ required this . onSavePressed ,
@ required this . onCancelPressed ,
} ) : assert ( visible ! = null ) ,
assert ( onSavePressed ! = null ) ,
assert ( onCancelPressed ! = null ) ,
super ( key: key ) ;
final bool visible ;
final bool visible ;
final VoidCallback onSavePressed ;
final VoidCallback onAddPlacePressed ;
final VoidCallback onCancelPressed ;
final VoidCallback onToggleMapTypePressed ;
@ override
Widget build ( BuildContext context ) {
return Visibility (
visible: visible ,
child: Container (
padding: const EdgeInsets . fromLTRB ( 0.0 , 0.0 , 0.0 , 14.0 ) ,
alignment: Alignment . bottomCenter ,
child: ButtonBar (
alignment: MainAxisAlignment . center ,
children: < Widget > [
RaisedButton (
color: Colors . blue ,
child: const Text (
' Save ' ,
style: TextStyle ( color: Colors . white , fontSize: 16.0 ) ,
) ,
onPressed: onSavePressed ,
) ,
RaisedButton (
color: Colors . red ,
child: const Text (
' Cancel ' ,
style: TextStyle ( color: Colors . white , fontSize: 16.0 ) ,
) ,
onPressed: onCancelPressed ,
) ,
] ,
) ,
) ,
) ;
}
}
class _MapFabs extends StatelessWidget {
const _MapFabs ( {
const _MapFabs ( {
Key key ,
Key key ,
@ required this . visible ,
@ required this . visible ,
@ -517,10 +557,6 @@ class _MapFabs extends StatelessWidget {
assert ( onToggleMapTypePressed ! = null ) ,
assert ( onToggleMapTypePressed ! = null ) ,
super ( key: key ) ;
super ( key: key ) ;
final bool visible ;
final VoidCallback onAddPlacePressed ;
final VoidCallback onToggleMapTypePressed ;
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
return Container (
return Container (
@ -529,7 +565,7 @@ class _MapFabs extends StatelessWidget {
child: Visibility (
child: Visibility (
visible: visible ,
visible: visible ,
child: Column (
child: Column (
children: < Widget > [
children: [
FloatingActionButton (
FloatingActionButton (
heroTag: ' add_place_button ' ,
heroTag: ' add_place_button ' ,
onPressed: onAddPlacePressed ,
onPressed: onAddPlacePressed ,
@ -552,39 +588,3 @@ class _MapFabs extends StatelessWidget {
) ;
) ;
}
}
}
}
class MapConfiguration {
const MapConfiguration ( {
@ required this . places ,
@ required this . selectedCategory ,
} ) : assert ( places ! = null ) ,
assert ( selectedCategory ! = null ) ;
final List < Place > places ;
final PlaceCategory selectedCategory ;
@ override
int get hashCode = > places . hashCode ^ selectedCategory . hashCode ;
@ override
bool operator = = ( Object other ) {
if ( identical ( this , other ) ) {
return true ;
}
if ( other . runtimeType ! = runtimeType ) {
return false ;
}
return other is MapConfiguration & &
other . places = = places & &
other . selectedCategory = = selectedCategory ;
}
static MapConfiguration of ( AppState appState ) {
return MapConfiguration (
places: appState . places ,
selectedCategory: appState . selectedCategory ,
) ;
}
}