diff --git a/lib/activeFires.dart b/lib/activeFires.dart index c3870f2..456ca2a 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -25,31 +25,26 @@ class _ActiveFiresPageState extends State { final GlobalKey _scaffoldKey = new GlobalKey(); List _fabMiniMenuItemList(BuildContext context) { - return [ - new FabMiniMenuItem.withText( - new Icon(Icons.location_searching), - fires600, - 8.0, - "Add your current position", - () { - onAddYourLocation(); - }, - "Add your current position", - fires300, - Colors.white, - ), - new FabMiniMenuItem.withText( - new Icon(Icons.edit_location), + return [ + new FabMiniMenuItem.withText( + new Icon(Icons.location_searching), fires600, 8.0, - "Add some other place", + "Add your current position", () { - onAddOtherLocation(context); + onAddYourLocation(); }, - "Add some other place", - fires300, - Colors.white) - ];} + "Add your current position", + Colors.black38, + Colors.white, + ), + new FabMiniMenuItem.withText( + new Icon(Icons.edit_location), fires600, 8.0, "Add some other place", + () { + onAddOtherLocation(context); + }, "Add some other place", Colors.black38, Colors.white) + ]; + } _ActiveFiresPageState(); @@ -81,9 +76,9 @@ class _ActiveFiresPageState extends State { context, new MaterialPageRoute( builder: (context) => new GenericMap( - title: loc.description, - location: loc, - ))); + title: loc.description, + location: loc, + operation: MapOperation.view))); } void showSnackMsg(String msg) { @@ -162,7 +157,9 @@ class _ActiveFiresPageState extends State { @override Widget build(BuildContext context) { var hasLocations = globals.yourLocations.length > 0; - final title = hasLocations ? 'Active fires in your places': 'Active fires in the world'; + final title = hasLocations + ? 'Active fires in your places' + : 'Active fires in the world'; print('Building Active Fires'); return Scaffold( key: _scaffoldKey, @@ -182,7 +179,8 @@ class _ActiveFiresPageState extends State { body: hasLocations ? new Stack(children: [ _buildSavedLocations(), - new FabDialer(_fabMiniMenuItemList(context), fires600, new Icon(Icons.add)) + new FabDialer( + _fabMiniMenuItemList(context), fires600, new Icon(Icons.add)) ]) : new Center( child: new CenteredColumn(children: [ diff --git a/lib/fireMarker.dart b/lib/fireMarker.dart index d193e94..84280a3 100644 --- a/lib/fireMarker.dart +++ b/lib/fireMarker.dart @@ -13,7 +13,10 @@ class FireMarker extends Marker { height: 80.0, point: new LatLng(location.lat, location.lon), builder: (ctx) => new Container( - child: new FireMarkerIcon(type), + child: new GestureDetector( + child: new FireMarkerIcon(type), onTap: () { + print('marker pressed'); + }) ), anchor: anchor, anchorOverride: anchorOverride ?? type == FireMarkType.position diff --git a/lib/fireMarkerIcon.dart b/lib/fireMarkerIcon.dart index 16b361b..4e8c5ab 100644 --- a/lib/fireMarkerIcon.dart +++ b/lib/fireMarkerIcon.dart @@ -3,7 +3,6 @@ import 'fireMarkType.dart'; import 'colors.dart'; class FireMarkerIcon extends StatelessWidget { - final FireMarkType type; FireMarkerIcon(this.type); diff --git a/lib/genericMap.dart b/lib/genericMap.dart index 9ae2ef2..e8da53f 100644 --- a/lib/genericMap.dart +++ b/lib/genericMap.dart @@ -10,24 +10,29 @@ import 'dart:core'; import 'globals.dart' as globals; import 'package:http/http.dart' as http; import 'dart:convert' show json; -import 'slider.dart'; import 'fireMarker.dart'; import 'zoomMapPlugin.dart'; import 'dummyMapPlugin.dart'; -import 'package:just_debounce_it/just_debounce_it.dart'; import 'fireMarkType.dart'; +import 'slider.dart'; +import 'package:just_debounce_it/just_debounce_it.dart'; +import 'package:padder/padding.dart'; -enum MapOperation { view } +enum MapOperation { view, subscriptionConfirm, unsubscribe } class GenericMap extends StatefulWidget { final BasicLocation location; final String title; + final MapOperation operation; - GenericMap({@required this.title, @required this.location}); + GenericMap( + {@required this.title, + @required this.location, + @required this.operation}); @override _GenericMapState createState() => - _GenericMapState(title: title, location: location); + _GenericMapState(title: title, location: location, operation: operation); } class _GenericMapState extends State { @@ -40,6 +45,7 @@ class _GenericMapState extends State { List fires = []; List falsePos = []; List industries = []; + MapOperation operation; @override void initState() { @@ -63,16 +69,21 @@ class _GenericMapState extends State { var firesCount = fires.length; var industriesCount = industries.length; var falsePosCount = falsePos.length; - print('real: $numFires, fire: $firesCount falsePos: $falsePosCount industries: $industriesCount'); + print( + 'real: $numFires, fire: $firesCount falsePos: $falsePosCount industries: $industriesCount'); } }); }); } - _GenericMapState({@required this.title, @required this.location}); + _GenericMapState( + {@required this.title, + @required this.location, + @required this.operation}); @override Widget build(BuildContext context) { + print('Build map with operation: $operation'); MapOptions mapOptions = new MapOptions( center: new LatLng(this.location.lat, this.location.lon), plugins: globals.isDevelopment @@ -90,29 +101,32 @@ class _GenericMapState extends State { var mapController = new MapController(); // mapController.fitBounds(bounds); // mapController.center - var fmap = new FlutterMap( - options: mapOptions, - mapController: mapController, - layers: [ - new TileLayerOptions( - maxZoom: 6.0, - subdomains: ['a', 'b', 'c'], - urlTemplate: 'https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', - additionalOptions: { - // 'opacity': '0.1', - 'attribution': - '© OpenStreetMap contributors' - }, - ), - globals.isDevelopment - ? new ZoomMapPluginOptions() - : new DummyMapPluginOptions(), - new MarkerLayerOptions( - markers: buildMarkers( - this.location, this.fires, this.industries, this.falsePos), - ), - ], - ); + var fmap = new Opacity( + opacity: operation == MapOperation.subscriptionConfirm ? 0.5 : 1.0, + child: new FlutterMap( + options: mapOptions, + mapController: mapController, + layers: [ + new TileLayerOptions( + maxZoom: 6.0, + subdomains: ['a', 'b', 'c'], + urlTemplate: + 'https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', + additionalOptions: { + // 'opacity': '0.1', + 'attribution': + '© OpenStreetMap contributors' + }, + ), + globals.isDevelopment + ? new ZoomMapPluginOptions() + : new DummyMapPluginOptions(), + new MarkerLayerOptions( + markers: buildMarkers( + this.location, this.fires, this.industries, this.falsePos), + ), + ], + )); return new Scaffold( key: _scaffoldKey, @@ -120,15 +134,43 @@ class _GenericMapState extends State { appBar: new AppBar( title: new Text(title), ), - floatingActionButton: FloatingActionButton.extended( - onPressed: () {}, - icon: const Icon(Icons.notifications_none, color: fires600), - label: new Text( - 'Subscribe', - style: const TextStyle(color: fires600), - ), - backgroundColor: Colors.white, - ), + floatingActionButton: Column(mainAxisAlignment: MainAxisAlignment.end, + // crossAxisAlignment: CrossAxisAlignment.center, + children: [ + FloatingActionButton.extended( + onPressed: () { + setState(() { + switch (operation) { + case MapOperation.view: + operation = MapOperation.subscriptionConfirm; + break; + case MapOperation.subscriptionConfirm: + operation = MapOperation.unsubscribe; + break; + case MapOperation.unsubscribe: + operation = MapOperation.view; + break; + } + }); + }, + icon: new Icon( + operation == MapOperation.view + ? Icons.notifications_active + : operation == MapOperation.subscriptionConfirm + ? Icons.check + : Icons.notifications_off, + color: fires600), + label: new Text( + operation == MapOperation.view + ? 'Subscribe to fires notifications' + : operation == MapOperation.subscriptionConfirm + ? 'Confirm' + : 'Unsubscribe', + style: const TextStyle(color: fires600), + ), + backgroundColor: Colors.white, + ) + ]), floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, bottomNavigationBar: new CustomBottomAppBar( fabLocation: FloatingActionButtonLocation.centerFloat, @@ -137,7 +179,7 @@ class _GenericMapState extends State { // height: 170.0, mainAxisAlignment: MainAxisAlignment.center, actions: listWithoutNulls([ - numFires == null + operation == MapOperation.subscriptionConfirm|| numFires == null ? null : numFires > 0 ? new Text('${numFires.toString()} fires at ${kmAround @@ -152,22 +194,24 @@ class _GenericMapState extends State { // Material(color: Colors.yellowAccent), fmap, Positioned( - top: constraints.maxHeight - 160, + top: constraints.maxHeight - 200, right: 10.0, left: 10.0, child: new CenteredRow( // Fit sample: // https://github.com/apptreesoftware/flutter_map/blob/master/flutter_map_example/lib/pages/map_controller.dart - children: [ - new FireDistanceSlider( - initialValue: kmAround, - onSlide: (distance) { - setState(() { - kmAround = distance; - Debounce.seconds(1, updateFireStats); - }); - }) - ], + children: operation == MapOperation.subscriptionConfirm + ? [ + new FireDistanceSlider( + initialValue: kmAround, + onSlide: (distance) { + setState(() { + kmAround = distance; + Debounce.seconds(1, updateFireStats); + }); + }) + ] + : [], ), ) ]), diff --git a/lib/slider.dart b/lib/slider.dart index d58d32b..58e1b4d 100644 --- a/lib/slider.dart +++ b/lib/slider.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'colors.dart'; import 'package:comunes_flutter/comunes_flutter.dart'; import 'package:padder/padding.dart'; +import 'package:fluttery/framing.dart'; typedef void SlideCallback(int distance); @@ -25,7 +26,8 @@ class _FireDistanceSliderState extends State { } sizeText(_sliderValue) => - new Text('Subscribe to $_sliderValue км around this area'); + new Text('Subscribe to $_sliderValue км around this area', + style: new TextStyle(color: Colors.black87)); warningText(_sliderValue) => _sliderValue >= 50 ? new Text('Warning: this is a very large area', @@ -38,7 +40,6 @@ class _FireDistanceSliderState extends State { value: _sliderValue + 0.0, activeColor: fires900, inactiveColor: Colors.black45, - min: 1.0, max: 100.0, divisions: 99, @@ -54,14 +55,14 @@ class _FireDistanceSliderState extends State { return new Column( mainAxisSize: MainAxisSize.min, children: listWithoutNulls([ - slider, - new Card( - color: const Color(0x60FFFFFF), - child: PaddingAll(10.0, - child: new Column(children: [ - sizeText(_sliderValue), - warningText(_sliderValue) - ]))) + new SizedBox(height: 50.0), + new Row(mainAxisSize: MainAxisSize.max, children: [slider]), + // new SizedBox(height: 5.0), + new Column(children: [ + sizeText(_sliderValue), + new SizedBox(height: 5.0), + warningText(_sliderValue) + ]) ]), ); }