More work with map location operations

This commit is contained in:
vjrj 2018-06-13 09:57:24 +02:00
parent b22ee50f89
commit 521eef5aa8
5 changed files with 134 additions and 89 deletions

View file

@ -25,31 +25,26 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
List<FabMiniMenuItem> _fabMiniMenuItemList(BuildContext context) { List<FabMiniMenuItem> _fabMiniMenuItemList(BuildContext context) {
return [ return [
new FabMiniMenuItem.withText( new FabMiniMenuItem.withText(
new Icon(Icons.location_searching), 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),
fires600, fires600,
8.0, 8.0,
"Add some other place", "Add your current position",
() { () {
onAddOtherLocation(context); onAddYourLocation();
}, },
"Add some other place", "Add your current position",
fires300, Colors.black38,
Colors.white) 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(); _ActiveFiresPageState();
@ -81,9 +76,9 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
context, context,
new MaterialPageRoute( new MaterialPageRoute(
builder: (context) => new GenericMap( builder: (context) => new GenericMap(
title: loc.description, title: loc.description,
location: loc, location: loc,
))); operation: MapOperation.view)));
} }
void showSnackMsg(String msg) { void showSnackMsg(String msg) {
@ -162,7 +157,9 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var hasLocations = globals.yourLocations.length > 0; 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'); print('Building Active Fires');
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
@ -182,7 +179,8 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
body: hasLocations body: hasLocations
? new Stack(children: <Widget>[ ? new Stack(children: <Widget>[
_buildSavedLocations(), _buildSavedLocations(),
new FabDialer(_fabMiniMenuItemList(context), fires600, new Icon(Icons.add)) new FabDialer(
_fabMiniMenuItemList(context), fires600, new Icon(Icons.add))
]) ])
: new Center( : new Center(
child: new CenteredColumn(children: <Widget>[ child: new CenteredColumn(children: <Widget>[

View file

@ -13,7 +13,10 @@ class FireMarker extends Marker {
height: 80.0, height: 80.0,
point: new LatLng(location.lat, location.lon), point: new LatLng(location.lat, location.lon),
builder: (ctx) => new Container( builder: (ctx) => new Container(
child: new FireMarkerIcon(type), child: new GestureDetector(
child: new FireMarkerIcon(type), onTap: () {
print('marker pressed');
})
), ),
anchor: anchor, anchor: anchor,
anchorOverride: anchorOverride ?? type == FireMarkType.position anchorOverride: anchorOverride ?? type == FireMarkType.position

View file

@ -3,7 +3,6 @@ import 'fireMarkType.dart';
import 'colors.dart'; import 'colors.dart';
class FireMarkerIcon extends StatelessWidget { class FireMarkerIcon extends StatelessWidget {
final FireMarkType type; final FireMarkType type;
FireMarkerIcon(this.type); FireMarkerIcon(this.type);

View file

@ -10,24 +10,29 @@ import 'dart:core';
import 'globals.dart' as globals; import 'globals.dart' as globals;
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:convert' show json; import 'dart:convert' show json;
import 'slider.dart';
import 'fireMarker.dart'; import 'fireMarker.dart';
import 'zoomMapPlugin.dart'; import 'zoomMapPlugin.dart';
import 'dummyMapPlugin.dart'; import 'dummyMapPlugin.dart';
import 'package:just_debounce_it/just_debounce_it.dart';
import 'fireMarkType.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 { class GenericMap extends StatefulWidget {
final BasicLocation location; final BasicLocation location;
final String title; final String title;
final MapOperation operation;
GenericMap({@required this.title, @required this.location}); GenericMap(
{@required this.title,
@required this.location,
@required this.operation});
@override @override
_GenericMapState createState() => _GenericMapState createState() =>
_GenericMapState(title: title, location: location); _GenericMapState(title: title, location: location, operation: operation);
} }
class _GenericMapState extends State<GenericMap> { class _GenericMapState extends State<GenericMap> {
@ -40,6 +45,7 @@ class _GenericMapState extends State<GenericMap> {
List<dynamic> fires = []; List<dynamic> fires = [];
List<dynamic> falsePos = []; List<dynamic> falsePos = [];
List<dynamic> industries = []; List<dynamic> industries = [];
MapOperation operation;
@override @override
void initState() { void initState() {
@ -63,16 +69,21 @@ class _GenericMapState extends State<GenericMap> {
var firesCount = fires.length; var firesCount = fires.length;
var industriesCount = industries.length; var industriesCount = industries.length;
var falsePosCount = falsePos.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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('Build map with operation: $operation');
MapOptions mapOptions = new MapOptions( MapOptions mapOptions = new MapOptions(
center: new LatLng(this.location.lat, this.location.lon), center: new LatLng(this.location.lat, this.location.lon),
plugins: globals.isDevelopment plugins: globals.isDevelopment
@ -90,29 +101,32 @@ class _GenericMapState extends State<GenericMap> {
var mapController = new MapController(); var mapController = new MapController();
// mapController.fitBounds(bounds); // mapController.fitBounds(bounds);
// mapController.center // mapController.center
var fmap = new FlutterMap( var fmap = new Opacity(
options: mapOptions, opacity: operation == MapOperation.subscriptionConfirm ? 0.5 : 1.0,
mapController: mapController, child: new FlutterMap(
layers: [ options: mapOptions,
new TileLayerOptions( mapController: mapController,
maxZoom: 6.0, layers: [
subdomains: ['a', 'b', 'c'], new TileLayerOptions(
urlTemplate: 'https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', maxZoom: 6.0,
additionalOptions: { subdomains: ['a', 'b', 'c'],
// 'opacity': '0.1', urlTemplate:
'attribution': 'https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png',
'&copy; <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors' additionalOptions: {
}, // 'opacity': '0.1',
), 'attribution':
globals.isDevelopment '&copy; <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors'
? new ZoomMapPluginOptions() },
: new DummyMapPluginOptions(), ),
new MarkerLayerOptions( globals.isDevelopment
markers: buildMarkers( ? new ZoomMapPluginOptions()
this.location, this.fires, this.industries, this.falsePos), : new DummyMapPluginOptions(),
), new MarkerLayerOptions(
], markers: buildMarkers(
); this.location, this.fires, this.industries, this.falsePos),
),
],
));
return new Scaffold( return new Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
@ -120,15 +134,43 @@ class _GenericMapState extends State<GenericMap> {
appBar: new AppBar( appBar: new AppBar(
title: new Text(title), title: new Text(title),
), ),
floatingActionButton: FloatingActionButton.extended( floatingActionButton: Column(mainAxisAlignment: MainAxisAlignment.end,
onPressed: () {}, // crossAxisAlignment: CrossAxisAlignment.center,
icon: const Icon(Icons.notifications_none, color: fires600), children: <Widget>[
label: new Text( FloatingActionButton.extended(
'Subscribe', onPressed: () {
style: const TextStyle(color: fires600), setState(() {
), switch (operation) {
backgroundColor: Colors.white, 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, floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
bottomNavigationBar: new CustomBottomAppBar( bottomNavigationBar: new CustomBottomAppBar(
fabLocation: FloatingActionButtonLocation.centerFloat, fabLocation: FloatingActionButtonLocation.centerFloat,
@ -137,7 +179,7 @@ class _GenericMapState extends State<GenericMap> {
// height: 170.0, // height: 170.0,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
actions: listWithoutNulls(<Widget>[ actions: listWithoutNulls(<Widget>[
numFires == null operation == MapOperation.subscriptionConfirm|| numFires == null
? null ? null
: numFires > 0 : numFires > 0
? new Text('${numFires.toString()} fires at ${kmAround ? new Text('${numFires.toString()} fires at ${kmAround
@ -152,22 +194,24 @@ class _GenericMapState extends State<GenericMap> {
// Material(color: Colors.yellowAccent), // Material(color: Colors.yellowAccent),
fmap, fmap,
Positioned( Positioned(
top: constraints.maxHeight - 160, top: constraints.maxHeight - 200,
right: 10.0, right: 10.0,
left: 10.0, left: 10.0,
child: new CenteredRow( child: new CenteredRow(
// Fit sample: // Fit sample:
// https://github.com/apptreesoftware/flutter_map/blob/master/flutter_map_example/lib/pages/map_controller.dart // https://github.com/apptreesoftware/flutter_map/blob/master/flutter_map_example/lib/pages/map_controller.dart
children: <Widget>[ children: operation == MapOperation.subscriptionConfirm
new FireDistanceSlider( ? <Widget>[
initialValue: kmAround, new FireDistanceSlider(
onSlide: (distance) { initialValue: kmAround,
setState(() { onSlide: (distance) {
kmAround = distance; setState(() {
Debounce.seconds(1, updateFireStats); kmAround = distance;
}); Debounce.seconds(1, updateFireStats);
}) });
], })
]
: [],
), ),
) )
]), ]),

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'colors.dart'; import 'colors.dart';
import 'package:comunes_flutter/comunes_flutter.dart'; import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:padder/padding.dart'; import 'package:padder/padding.dart';
import 'package:fluttery/framing.dart';
typedef void SlideCallback(int distance); typedef void SlideCallback(int distance);
@ -25,7 +26,8 @@ class _FireDistanceSliderState extends State<FireDistanceSlider> {
} }
sizeText(_sliderValue) => 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 warningText(_sliderValue) => _sliderValue >= 50
? new Text('Warning: this is a very large area', ? new Text('Warning: this is a very large area',
@ -38,7 +40,6 @@ class _FireDistanceSliderState extends State<FireDistanceSlider> {
value: _sliderValue + 0.0, value: _sliderValue + 0.0,
activeColor: fires900, activeColor: fires900,
inactiveColor: Colors.black45, inactiveColor: Colors.black45,
min: 1.0, min: 1.0,
max: 100.0, max: 100.0,
divisions: 99, divisions: 99,
@ -54,14 +55,14 @@ class _FireDistanceSliderState extends State<FireDistanceSlider> {
return new Column( return new Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: listWithoutNulls(<Widget>[ children: listWithoutNulls(<Widget>[
slider, new SizedBox(height: 50.0),
new Card( new Row(mainAxisSize: MainAxisSize.max, children: <Widget>[slider]),
color: const Color(0x60FFFFFF), // new SizedBox(height: 5.0),
child: PaddingAll(10.0, new Column(children: <Widget>[
child: new Column(children: <Widget>[ sizeText(_sliderValue),
sizeText(_sliderValue), new SizedBox(height: 5.0),
warningText(_sliderValue) warningText(_sliderValue)
]))) ])
]), ]),
); );
} }