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

@ -35,21 +35,16 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
onAddYourLocation(); onAddYourLocation();
}, },
"Add your current position", "Add your current position",
fires300, Colors.black38,
Colors.white, Colors.white,
), ),
new FabMiniMenuItem.withText( new FabMiniMenuItem.withText(
new Icon(Icons.edit_location), new Icon(Icons.edit_location), fires600, 8.0, "Add some other place",
fires600,
8.0,
"Add some other place",
() { () {
onAddOtherLocation(context); onAddOtherLocation(context);
}, }, "Add some other place", Colors.black38, Colors.white)
"Add some other place", ];
fires300, }
Colors.white)
];}
_ActiveFiresPageState(); _ActiveFiresPageState();
@ -83,7 +78,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
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,14 +101,17 @@ 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(
opacity: operation == MapOperation.subscriptionConfirm ? 0.5 : 1.0,
child: new FlutterMap(
options: mapOptions, options: mapOptions,
mapController: mapController, mapController: mapController,
layers: [ layers: [
new TileLayerOptions( new TileLayerOptions(
maxZoom: 6.0, maxZoom: 6.0,
subdomains: ['a', 'b', 'c'], subdomains: ['a', 'b', 'c'],
urlTemplate: 'https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', urlTemplate:
'https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png',
additionalOptions: { additionalOptions: {
// 'opacity': '0.1', // 'opacity': '0.1',
'attribution': 'attribution':
@ -112,7 +126,7 @@ class _GenericMapState extends State<GenericMap> {
this.location, this.fires, this.industries, this.falsePos), 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>[
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( label: new Text(
'Subscribe', operation == MapOperation.view
? 'Subscribe to fires notifications'
: operation == MapOperation.subscriptionConfirm
? 'Confirm'
: 'Unsubscribe',
style: const TextStyle(color: fires600), style: const TextStyle(color: fires600),
), ),
backgroundColor: Colors.white, 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,13 +194,14 @@ 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
? <Widget>[
new FireDistanceSlider( new FireDistanceSlider(
initialValue: kmAround, initialValue: kmAround,
onSlide: (distance) { onSlide: (distance) {
@ -167,7 +210,8 @@ class _GenericMapState extends State<GenericMap> {
Debounce.seconds(1, updateFireStats); 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)
]))) ])
]), ]),
); );
} }