From 3d27f207982d959a894fabfa1d43027f391c95ad Mon Sep 17 00:00:00 2001 From: estevez-dev Date: Wed, 22 Jul 2020 13:32:34 +0300 Subject: [PATCH] Map fixes --- lib/cards/map_card.dart | 67 ++++++++++++++++++++++++++--- lib/cards/widgets/entities_map.dart | 23 +++++++--- 2 files changed, 79 insertions(+), 11 deletions(-) diff --git a/lib/cards/map_card.dart b/lib/cards/map_card.dart index 1569040..f298bfe 100644 --- a/lib/cards/map_card.dart +++ b/lib/cards/map_card.dart @@ -11,19 +11,76 @@ class MapCard extends StatefulWidget { class _MapCardState extends State { + void _openMap(BuildContext context) { + Navigator.of(context).push(MaterialPageRoute( + builder: (bc) { + return Scaffold( + primary: false, + /*appBar: new AppBar( + backgroundColor: Colors.transparent, + leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){ + Navigator.pop(context); + }), + actions: [ + IconButton( + icon: Icon(Icons.fullscreen), + onPressed: () {}, + ) + ], + // Here we take the value from the MyHomePage object that was created by + // the App.build method, and use it to set our appbar title. + title: new Text("${widget.card.title ?? ""}"), + ),*/ + body: Container( + color: Theme.of(context).primaryColor, + child: SafeArea( + child: Stack( + children: [ + EntitiesMap( + entities: widget.card.entities, + interactive: true + ), + Positioned( + top: 0, + left: 0, + child: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){ + Navigator.pop(context); + }) + ) + ], + ) + ) + ) + ); + } + )); + } + @override Widget build(BuildContext context) { - return CardWrapper( child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ CardHeader(name: widget.card.title), - EntitiesMap( - aspectRatio: 1, - entities: widget.card.entities, - ) + Stack( + children: [ + GestureDetector( + onTap: () => _openMap(context), + child: EntitiesMap( + aspectRatio: 1, + interactive: false, + entities: widget.card.entities, + ) + ), + Positioned( + bottom: 0, + left: 0, + child: Text('Tap to open interactive map', style: Theme.of(context).textTheme.caption) + ) + ], + ), ], ) ); diff --git a/lib/cards/widgets/entities_map.dart b/lib/cards/widgets/entities_map.dart index f07b4d4..2ed5faa 100644 --- a/lib/cards/widgets/entities_map.dart +++ b/lib/cards/widgets/entities_map.dart @@ -6,8 +6,10 @@ class EntitiesMap extends StatelessWidget { final List entities; final bool interactive; final double aspectRatio; + final LatLng center; + final double zoom; - const EntitiesMap({Key key, this.entities: const [], this.aspectRatio, this.interactive: false}) : super(key: key); + const EntitiesMap({Key key, this.entities: const [], this.aspectRatio, this.interactive: true, this.center, this.zoom}) : super(key: key); @override Widget build(BuildContext context) { @@ -34,12 +36,22 @@ class EntitiesMap extends StatelessWidget { ); } }); - Widget map = FlutterMap( - options: new MapOptions( - interactive: false, + MapOptions mapOptions; + if (center != null) { + mapOptions = MapOptions( + interactive: interactive, + center: center, + zoom: zoom ?? 10, + ); + } else { + mapOptions = MapOptions( + interactive: interactive, bounds: LatLngBounds.fromPoints(points), boundsOptions: FitBoundsOptions(padding: EdgeInsets.all(40)), - ), + ); + } + Widget map = FlutterMap( + options: mapOptions, layers: [ new TileLayerOptions( urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", @@ -58,5 +70,4 @@ class EntitiesMap extends StatelessWidget { } return map; } - } \ No newline at end of file