More work with redux, and location edit (wip)
This commit is contained in:
parent
e97a5a1a9f
commit
e55edce3d4
17 changed files with 311 additions and 186 deletions
|
|
@ -199,13 +199,13 @@ class ActiveFiresPage extends StatelessWidget {
|
||||||
child: new CenteredColumn(children: <Widget>[
|
child: new CenteredColumn(children: <Widget>[
|
||||||
new RoundedBtn(
|
new RoundedBtn(
|
||||||
icon: Icons.location_searching,
|
icon: Icons.location_searching,
|
||||||
text: 'Fires near your',
|
text: S.of(context).addYourCurrentPosition,
|
||||||
onPressed: () => onAddYourLocation(view.onAdd),
|
onPressed: () => onAddYourLocation(view.onAdd),
|
||||||
backColor: fires600),
|
backColor: fires600),
|
||||||
const SizedBox(height: 26.0),
|
const SizedBox(height: 26.0),
|
||||||
new RoundedBtn(
|
new RoundedBtn(
|
||||||
icon: Icons.edit_location,
|
icon: Icons.edit_location,
|
||||||
text: S.of(context).firesNearPlace,
|
text: S.of(context).addSomePlace,
|
||||||
onPressed: () => onAddOtherLocation(view.onAdd),
|
onPressed: () => onAddOtherLocation(view.onAdd),
|
||||||
backColor: fires600),
|
backColor: fires600),
|
||||||
])),
|
])),
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,11 @@ class FiresApp extends StatelessWidget {
|
||||||
home: new MaterialAppWithIntroHome(
|
home: new MaterialAppWithIntroHome(
|
||||||
introWidget, continueWidget, 'showInitialWizard-2018-06-27-01'),
|
introWidget, continueWidget, 'showInitialWizard-2018-06-27-01'),
|
||||||
onGenerateTitle: (context) {
|
onGenerateTitle: (context) {
|
||||||
String lang = Localizations.localeOf(context).languageCode;
|
print('MaterialApp onGenerateTitle');
|
||||||
this.store.dispatch(new OnUserLangAction(lang));
|
if (store.state.user.lang == null) {
|
||||||
|
String lang = Localizations.localeOf(context).languageCode;
|
||||||
|
this.store.dispatch(new OnUserLangAction(lang));
|
||||||
|
}
|
||||||
return S.of(context).appName;
|
return S.of(context).appName;
|
||||||
},
|
},
|
||||||
theme: firesTheme,
|
theme: firesTheme,
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ class S implements WidgetsLocalizations {
|
||||||
TextDirection get textDirection => TextDirection.ltr;
|
TextDirection get textDirection => TextDirection.ltr;
|
||||||
|
|
||||||
String get AvoidThisStringsIfisNotPlural => "Zero One Two Few Many Other";
|
String get AvoidThisStringsIfisNotPlural => "Zero One Two Few Many Other";
|
||||||
|
String get CANCEL => "CANCEL";
|
||||||
|
String get SAVE => "SAVE";
|
||||||
String get UNDO => "UNDO";
|
String get UNDO => "UNDO";
|
||||||
String get aDay => "a day";
|
String get aDay => "a day";
|
||||||
String get aF3wSeconds => "a few seconds";
|
String get aF3wSeconds => "a few seconds";
|
||||||
|
|
@ -104,6 +106,8 @@ class es extends S {
|
||||||
@override
|
@override
|
||||||
String get supportThisInitiative => "Apoya esta iniciativa";
|
String get supportThisInitiative => "Apoya esta iniciativa";
|
||||||
@override
|
@override
|
||||||
|
String get SAVE => "GUARDAR";
|
||||||
|
@override
|
||||||
String get toFiresNotifications => "Suscríbete a alertas de fuegos";
|
String get toFiresNotifications => "Suscríbete a alertas de fuegos";
|
||||||
@override
|
@override
|
||||||
String get notPermsUbication => "No tenemos permisos para conocer tu ubicación";
|
String get notPermsUbication => "No tenemos permisos para conocer tu ubicación";
|
||||||
|
|
@ -134,6 +138,8 @@ class es extends S {
|
||||||
@override
|
@override
|
||||||
String get chooseAWatchRadio => "Elige un radio de vigilancia";
|
String get chooseAWatchRadio => "Elige un radio de vigilancia";
|
||||||
@override
|
@override
|
||||||
|
String get CANCEL => "CANCELAR";
|
||||||
|
@override
|
||||||
String get chooseAPlace => "Elige un lugar";
|
String get chooseAPlace => "Elige un lugar";
|
||||||
@override
|
@override
|
||||||
String get firesNearPlace => "Fuegos cercanos a ti";
|
String get firesNearPlace => "Fuegos cercanos a ti";
|
||||||
|
|
|
||||||
|
|
@ -22,27 +22,27 @@ class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
http.read('${firesApiUrl}status/last-fire-check').then((result) {
|
/* http.read('${firesApiUrl}status/last-fire-check').then((result) {
|
||||||
try {
|
try {
|
||||||
var now = Moment.now();
|
var now = Moment.now();
|
||||||
var last = DateTime.parse(json.decode(result)['value']);
|
var last = DateTime.parse(json.decode(result)['value']);
|
||||||
setState(() {
|
http.read('${firesApiUrl}status/active-fires-count').then((result) {
|
||||||
lastCheck = now.from(context, last);
|
try {
|
||||||
|
int count = json.decode(result)['total'];
|
||||||
|
setState(() {
|
||||||
|
lastCheck = now.from(context, last);
|
||||||
|
activeFires = count;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
print('Cannot get the last fire stats');
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Cannot get the last fire check');
|
print('Cannot get the last fire check');
|
||||||
|
print(e);
|
||||||
}
|
}
|
||||||
});
|
}); */
|
||||||
http.read('${firesApiUrl}status/active-fires-count').then((result) {
|
|
||||||
try {
|
|
||||||
int count = json.decode(result)['total'];
|
|
||||||
setState(() {
|
|
||||||
activeFires = count;
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
print('Cannot get the last fire stats');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,30 @@
|
||||||
|
import 'package:redux/redux.dart';
|
||||||
import 'package:redux_logging/redux_logging.dart';
|
import 'package:redux_logging/redux_logging.dart';
|
||||||
|
|
||||||
import 'globals.dart' as globals;
|
import 'globals.dart' as globals;
|
||||||
import 'mainCommon.dart';
|
import 'mainCommon.dart';
|
||||||
import 'package:redux/redux.dart';
|
|
||||||
|
enum LogLevel { none, actions, full }
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
globals.isDevelopment = true;
|
globals.isDevelopment = true;
|
||||||
var logRedux = false;
|
|
||||||
|
|
||||||
List<Middleware> devMiddlewares = logRedux ? [
|
String onlyLogActionFormatter<State>(
|
||||||
LoggingMiddleware.printer(formatter: LoggingMiddleware.multiLineFormatter)
|
State state,
|
||||||
] : [];
|
dynamic action,
|
||||||
|
DateTime timestamp,
|
||||||
|
) {
|
||||||
|
return "${action.toString().replaceAll('Instance of ', '')}";
|
||||||
|
}
|
||||||
|
|
||||||
|
LogLevel logRedux = LogLevel.actions;
|
||||||
|
|
||||||
|
List<Middleware> devMiddlewares = logRedux == LogLevel.none
|
||||||
|
? []
|
||||||
|
: [LoggingMiddleware.printer(
|
||||||
|
formatter: logRedux == LogLevel.full
|
||||||
|
? LoggingMiddleware.multiLineFormatter
|
||||||
|
: onlyLogActionFormatter)];
|
||||||
|
|
||||||
mainCommon(devMiddlewares);
|
mainCommon(devMiddlewares);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import 'package:meta/meta.dart';
|
||||||
import 'fireMapState.dart';
|
import 'fireMapState.dart';
|
||||||
import 'user.dart';
|
import 'user.dart';
|
||||||
|
|
||||||
|
export 'fireMapState.dart';
|
||||||
|
|
||||||
part 'appState.g.dart';
|
part 'appState.g.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
|
|
@ -86,5 +88,9 @@ typedef void OnSubscribeDistanceChangeFunction(YourLocation loc);
|
||||||
typedef void OnUnSubscribeFunction(YourLocation loc);
|
typedef void OnUnSubscribeFunction(YourLocation loc);
|
||||||
typedef void OnSubscribeConfirmedFunction(YourLocation loc);
|
typedef void OnSubscribeConfirmedFunction(YourLocation loc);
|
||||||
|
|
||||||
|
typedef void OnLocationEdit(YourLocation loc);
|
||||||
|
typedef void OnLocationEditConfirm(YourLocation loc);
|
||||||
|
typedef void OnLocationEditCancel(YourLocation loc);
|
||||||
|
|
||||||
// unused
|
// unused
|
||||||
// typedef void UpdateYourLocationFunction(ObjectId id, YourLocation loc);
|
// typedef void UpdateYourLocationFunction(ObjectId id, YourLocation loc);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:fires_flutter/models/yourLocation.dart';
|
import 'package:fires_flutter/models/yourLocation.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
enum FireMapStatus { view, subscriptionConfirm, unsubscribe }
|
enum FireMapStatus { view, subscriptionConfirm, unsubscribe, edit }
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class FireMapState {
|
class FireMapState {
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export 'appActions.dart';
|
export 'appActions.dart';
|
||||||
export 'yourLocationActions.dart';
|
export 'yourLocationActions.dart';
|
||||||
|
export 'fireMapActions.dart';
|
||||||
|
|
@ -36,6 +36,16 @@ void fetchYourLocationsMiddleware(
|
||||||
createUser(store, store.state.user.lang, action.token);
|
createUser(store, store.state.user.lang, action.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action is EditConfirmYourLocationAction) {
|
||||||
|
if (action.loc.subscribed) {
|
||||||
|
// FXIME save lat/lon
|
||||||
|
} else {
|
||||||
|
// No subscribed (only local)
|
||||||
|
store.dispatch(new UpdateYourLocationAction(action.loc));
|
||||||
|
persistYourLocations(store.state.yourLocations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (action is AddYourLocationAction) {
|
if (action is AddYourLocationAction) {
|
||||||
if (action.loc.subscribed) {
|
if (action.loc.subscribed) {
|
||||||
subscribeViaApi(store, action.loc,
|
subscribeViaApi(store, action.loc,
|
||||||
|
|
@ -64,25 +74,28 @@ void fetchYourLocationsMiddleware(
|
||||||
.then((result) => store.dispatch(result));
|
.then((result) => store.dispatch(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action is UpdateLocalYourLocationAction) {
|
if (action is UpdateYourLocationAction) {
|
||||||
if (action.loc.subscribed)
|
if (action.loc.subscribed)
|
||||||
Debounce.seconds(
|
Debounce.seconds(
|
||||||
2,
|
2,
|
||||||
() => api
|
() => api
|
||||||
.getYourLocationFireStats(store.state, action.loc)
|
.getYourLocationFireStats(store.state, action.loc)
|
||||||
.then((result) => store.dispatch(result)));
|
.then((result) => store.dispatch(result)));
|
||||||
|
else {
|
||||||
|
// FIXME do something?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action is SubscribeConfirmAction) {
|
if (action is SubscribeConfirmAction) {
|
||||||
subscribeViaApi(store, action.loc, (sub) {
|
subscribeViaApi(store, action.loc, (sub) {
|
||||||
store.dispatch(new UpdateLocalYourLocationAction(action.loc));
|
store.dispatch(new UpdateYourLocationAction(action.loc));
|
||||||
persistYourLocations(store.state.yourLocations);
|
persistYourLocations(store.state.yourLocations);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action is UnSubscribeAction) {
|
if (action is UnSubscribeAction) {
|
||||||
unsubsViaApi(store, action.loc.id, () {
|
unsubsViaApi(store, action.loc.id, () {
|
||||||
store.dispatch(new UpdateLocalYourLocationAction(action.loc));
|
store.dispatch(new UpdateYourLocationAction(action.loc));
|
||||||
persistYourLocations(store.state.yourLocations);
|
persistYourLocations(store.state.yourLocations);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,13 @@ final fireMapReducer = combineReducers<FireMapState>([
|
||||||
_subscribeConfirmYourLocationMap),
|
_subscribeConfirmYourLocationMap),
|
||||||
new TypedReducer<FireMapState, UnSubscribeAction>(
|
new TypedReducer<FireMapState, UnSubscribeAction>(
|
||||||
_unsubscribeYourLocationMap),
|
_unsubscribeYourLocationMap),
|
||||||
|
new TypedReducer<FireMapState, EditYourLocationAction>(_editYourLocationMap),
|
||||||
|
new TypedReducer<FireMapState, EditConfirmYourLocationAction>(
|
||||||
|
_editConfirmYourLocationMap),
|
||||||
|
new TypedReducer<FireMapState, EditCancelYourLocationAction>(
|
||||||
|
_editCancelYourLocationMap),
|
||||||
|
new TypedReducer<FireMapState, UpdateYourLocationMapAction>(
|
||||||
|
_updateYourLocationMap)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
FireMapState _updateYourLocationMapStats(
|
FireMapState _updateYourLocationMapStats(
|
||||||
|
|
@ -24,6 +31,11 @@ FireMapState _updateYourLocationMapStats(
|
||||||
industries: action.industries);
|
industries: action.industries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FireMapState _updateYourLocationMap(
|
||||||
|
FireMapState state, UpdateYourLocationMapAction action) {
|
||||||
|
return state.copyWith(yourLocation: action.loc);
|
||||||
|
}
|
||||||
|
|
||||||
FireMapState _showYourLocationMap(
|
FireMapState _showYourLocationMap(
|
||||||
FireMapState state, ShowYourLocationMapAction action) {
|
FireMapState state, ShowYourLocationMapAction action) {
|
||||||
return state.copyWith(
|
return state.copyWith(
|
||||||
|
|
@ -47,3 +59,21 @@ FireMapState _unsubscribeYourLocationMap(
|
||||||
FireMapState state, UnSubscribeAction action) {
|
FireMapState state, UnSubscribeAction action) {
|
||||||
return state.copyWith(status: FireMapStatus.view);
|
return state.copyWith(status: FireMapStatus.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FireMapState _editYourLocationMap(
|
||||||
|
FireMapState state, EditYourLocationAction action) {
|
||||||
|
return state.copyWith(status: FireMapStatus.edit);
|
||||||
|
}
|
||||||
|
|
||||||
|
FireMapState _editConfirmYourLocationMap(
|
||||||
|
FireMapState state, EditConfirmYourLocationAction action) {
|
||||||
|
return state.copyWith(status: restoreStatusAfterSave(action.loc));
|
||||||
|
}
|
||||||
|
|
||||||
|
FireMapState _editCancelYourLocationMap(
|
||||||
|
FireMapState state, EditCancelYourLocationAction action) {
|
||||||
|
return state.copyWith(status: restoreStatusAfterSave(action.loc));
|
||||||
|
}
|
||||||
|
|
||||||
|
FireMapStatus restoreStatusAfterSave(loc) =>
|
||||||
|
loc.subscribed ? FireMapStatus.unsubscribe : FireMapStatus.view;
|
||||||
|
|
|
||||||
|
|
@ -16,25 +16,6 @@ class AddedYourLocationAction extends YourLocationActions {
|
||||||
AddedYourLocationAction(this.loc);
|
AddedYourLocationAction(this.loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ShowYourLocationMapAction extends YourLocationActions {
|
|
||||||
YourLocation loc;
|
|
||||||
|
|
||||||
ShowYourLocationMapAction(this.loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
class UpdateYourLocationMapStatsAction extends YourLocationActions {
|
|
||||||
int numFires;
|
|
||||||
List<dynamic> fires = [];
|
|
||||||
List<dynamic> falsePos = [];
|
|
||||||
List<dynamic> industries = [];
|
|
||||||
|
|
||||||
UpdateYourLocationMapStatsAction(
|
|
||||||
{@required this.numFires,
|
|
||||||
@required this.fires,
|
|
||||||
@required this.falsePos,
|
|
||||||
@required this.industries});
|
|
||||||
}
|
|
||||||
|
|
||||||
class DeleteYourLocationAction extends YourLocationActions {
|
class DeleteYourLocationAction extends YourLocationActions {
|
||||||
YourLocation loc;
|
YourLocation loc;
|
||||||
|
|
||||||
|
|
@ -47,10 +28,10 @@ class DeletedYourLocationAction extends YourLocationActions {
|
||||||
DeletedYourLocationAction(this.id);
|
DeletedYourLocationAction(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
class UpdateLocalYourLocationAction extends YourLocationActions {
|
class UpdateYourLocationAction extends YourLocationActions {
|
||||||
YourLocation loc;
|
YourLocation loc;
|
||||||
|
|
||||||
UpdateLocalYourLocationAction(this.loc);
|
UpdateYourLocationAction(this.loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ToggleSubscriptionAction extends YourLocationActions {
|
class ToggleSubscriptionAction extends YourLocationActions {
|
||||||
|
|
@ -81,3 +62,19 @@ class UnSubscribeAction extends YourLocationActions {
|
||||||
UnSubscribeAction(this.loc);
|
UnSubscribeAction(this.loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EditYourLocationAction extends YourLocationActions {
|
||||||
|
YourLocation loc;
|
||||||
|
|
||||||
|
EditYourLocationAction(this.loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
class EditConfirmYourLocationAction extends YourLocationActions {
|
||||||
|
YourLocation loc;
|
||||||
|
|
||||||
|
EditConfirmYourLocationAction(this.loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
class EditCancelYourLocationAction extends YourLocationActions {
|
||||||
|
YourLocation loc;
|
||||||
|
EditCancelYourLocationAction(this.loc);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ final yourLocationsReducer = combineReducers<List<YourLocation>>([
|
||||||
_addedYourLocation),
|
_addedYourLocation),
|
||||||
new TypedReducer<List<YourLocation>, DeletedYourLocationAction>(
|
new TypedReducer<List<YourLocation>, DeletedYourLocationAction>(
|
||||||
_deletedYourLocation),
|
_deletedYourLocation),
|
||||||
new TypedReducer<List<YourLocation>, UpdateLocalYourLocationAction>(
|
new TypedReducer<List<YourLocation>, UpdateYourLocationAction>(
|
||||||
_updateLocalYourLocation),
|
_updateYourLocation),
|
||||||
new TypedReducer<List<YourLocation>, ToggledSubscriptionAction>(
|
new TypedReducer<List<YourLocation>, ToggledSubscriptionAction>(
|
||||||
_toggledSubscriptionAction)
|
_toggledSubscriptionAction)
|
||||||
]);
|
]);
|
||||||
|
|
@ -26,8 +26,8 @@ List<YourLocation> _deletedYourLocation(
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<YourLocation> _updateLocalYourLocation(
|
List<YourLocation> _updateYourLocation(
|
||||||
List<YourLocation> yourLocations, UpdateLocalYourLocationAction action) {
|
List<YourLocation> yourLocations, UpdateYourLocationAction action) {
|
||||||
return yourLocations
|
return yourLocations
|
||||||
.map((yourLocation) =>
|
.map((yourLocation) =>
|
||||||
yourLocation.id == action.loc.id ? action.loc : yourLocation)
|
yourLocation.id == action.loc.id ? action.loc : yourLocation)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
|
||||||
import 'slider.dart';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Useful for debug
|
Useful for debug
|
||||||
|
|
@ -15,24 +13,14 @@ class Sandbox extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
//showDialog(context: context, child: builder(context));
|
//showDialog(context: context, child: builder(context));
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: LayoutBuilder(
|
appBar: new AppBar(
|
||||||
builder: (context, constraints) =>
|
title: new TextField(
|
||||||
Stack(fit: StackFit.expand, children: <Widget>[
|
controller: new TextEditingController(text: "kk"),
|
||||||
// Material(color: Colors.yellowAccent),
|
decoration: new InputDecoration(),
|
||||||
Positioned(
|
onSubmitted: (todoText) {},
|
||||||
top: 0.0,
|
)),
|
||||||
child: Icon(Icons.star, size: 40.0),
|
body: new Text("Sandbox"),
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
top: constraints.maxHeight - 80,
|
|
||||||
right: 10.0,
|
|
||||||
left: 10.0,
|
|
||||||
child: new CenteredRow(
|
|
||||||
children: <Widget>[new FireDistanceSlider()],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
-añ
|
||||||
|
|
@ -7,6 +7,7 @@ import 'package:fires_flutter/models/yourLocation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_map/flutter_map.dart';
|
import 'package:flutter_map/flutter_map.dart';
|
||||||
import 'package:flutter_map/plugin_api.dart';
|
import 'package:flutter_map/plugin_api.dart';
|
||||||
|
import 'package:flutter_map/src/map/flutter_map_state.dart';
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
import 'package:latlong/latlong.dart';
|
import 'package:latlong/latlong.dart';
|
||||||
|
|
||||||
|
|
@ -30,13 +31,17 @@ class _ViewModel {
|
||||||
final OnSubscribeConfirmedFunction onSubsConfirmed;
|
final OnSubscribeConfirmedFunction onSubsConfirmed;
|
||||||
final OnUnSubscribeFunction onUnSubs;
|
final OnUnSubscribeFunction onUnSubs;
|
||||||
final OnSubscribeDistanceChangeFunction onSlide;
|
final OnSubscribeDistanceChangeFunction onSlide;
|
||||||
|
final OnLocationEdit onEdit;
|
||||||
|
final OnLocationEditConfirm onEditConfirm;
|
||||||
|
|
||||||
_ViewModel(
|
_ViewModel(
|
||||||
{@required this.mapState,
|
{@required this.mapState,
|
||||||
@required this.onSubs,
|
@required this.onSubs,
|
||||||
@required this.onSubsConfirmed,
|
@required this.onSubsConfirmed,
|
||||||
@required this.onUnSubs,
|
@required this.onUnSubs,
|
||||||
@required this.onSlide});
|
@required this.onSlide,
|
||||||
|
@required this.onEdit,
|
||||||
|
@required this.onEditConfirm});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
|
|
@ -58,6 +63,7 @@ class YourLocationMap extends StatelessWidget {
|
||||||
return new StoreConnector<AppState, _ViewModel>(
|
return new StoreConnector<AppState, _ViewModel>(
|
||||||
distinct: true,
|
distinct: true,
|
||||||
converter: (store) {
|
converter: (store) {
|
||||||
|
print('New map viewer');
|
||||||
return new _ViewModel(
|
return new _ViewModel(
|
||||||
onSubs: (loc) {
|
onSubs: (loc) {
|
||||||
store.dispatch(new SubscribeAction());
|
store.dispatch(new SubscribeAction());
|
||||||
|
|
@ -71,20 +77,27 @@ class YourLocationMap extends StatelessWidget {
|
||||||
store.dispatch(new UnSubscribeAction(loc));
|
store.dispatch(new UnSubscribeAction(loc));
|
||||||
},
|
},
|
||||||
onSlide: (loc) {
|
onSlide: (loc) {
|
||||||
store.dispatch(new UpdateLocalYourLocationAction(loc));
|
store.dispatch(new UpdateYourLocationMapAction(loc));
|
||||||
},
|
},
|
||||||
|
onEdit: (loc) => store.dispatch(new EditYourLocationAction(loc)),
|
||||||
|
onEditConfirm: (loc) =>
|
||||||
|
store.dispatch(new EditConfirmYourLocationAction(loc)),
|
||||||
mapState: store.state.fireMapState);
|
mapState: store.state.fireMapState);
|
||||||
},
|
},
|
||||||
builder: (context, view) {
|
builder: (context, view) {
|
||||||
|
print('New map builder');
|
||||||
YourLocation location = view.mapState.yourLocation;
|
YourLocation location = view.mapState.yourLocation;
|
||||||
assert(location != null);
|
assert(location != null);
|
||||||
|
TextEditingController textController =
|
||||||
|
new TextEditingController(text: location.description);
|
||||||
|
|
||||||
MapOptions mapOptions = new MapOptions(
|
MapOptions mapOptions = new MapOptions(
|
||||||
center: new LatLng(location.lat, location.lon),
|
center: new LatLng(location.lat, location.lon),
|
||||||
plugins: globals.isDevelopment
|
plugins: globals.isDevelopment
|
||||||
? [new ZoomMapPlugin()]
|
? [new ZoomMapPlugin()]
|
||||||
: [new DummyMapPlugin()],
|
: [new DummyMapPlugin()],
|
||||||
// this works ?
|
// this works ?
|
||||||
// interactive: false,
|
interactive: false,
|
||||||
zoom: 13.0,
|
zoom: 13.0,
|
||||||
// THIS does not works as expected
|
// THIS does not works as expected
|
||||||
// maxZoom: 6.0,
|
// maxZoom: 6.0,
|
||||||
|
|
@ -93,115 +106,136 @@ class YourLocationMap extends StatelessWidget {
|
||||||
// print('${positionCallback.center}, ${positionCallback.zoom}');
|
// print('${positionCallback.center}, ${positionCallback.zoom}');
|
||||||
});
|
});
|
||||||
var mapController = new MapController();
|
var mapController = new MapController();
|
||||||
|
|
||||||
// mapController.fitBounds(bounds);
|
// mapController.fitBounds(bounds);
|
||||||
// mapController.center
|
// mapController.center
|
||||||
|
|
||||||
FireMapState mapState = view.mapState;
|
FireMapState mapState = view.mapState;
|
||||||
FireMapStatus operation = mapState.status;
|
FireMapStatus status = mapState.status;
|
||||||
print('Build map with operation: $operation');
|
print('Build map with status: $status');
|
||||||
final btnText = operation == FireMapStatus.view
|
final btnText = status == FireMapStatus.view
|
||||||
? S.of(context).toFiresNotifications
|
? S.of(context).toFiresNotifications
|
||||||
: operation == FireMapStatus.subscriptionConfirm
|
: status == FireMapStatus.subscriptionConfirm
|
||||||
? S.of(context).confirm
|
? S.of(context).confirm
|
||||||
: S.of(context).unsubscribe;
|
: S.of(context).unsubscribe;
|
||||||
final btnIcon = operation == FireMapStatus.view
|
final btnIcon = status == FireMapStatus.view
|
||||||
? Icons.notifications_active
|
? Icons.notifications_active
|
||||||
: operation == FireMapStatus.subscriptionConfirm
|
: status == FireMapStatus.subscriptionConfirm
|
||||||
? Icons.check
|
? Icons.check
|
||||||
: Icons.notifications_off;
|
: Icons.notifications_off;
|
||||||
|
FlutterMap map = 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':
|
||||||
|
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||||
|
},
|
||||||
|
),
|
||||||
|
globals.isDevelopment
|
||||||
|
? new ZoomMapPluginOptions()
|
||||||
|
: new DummyMapPluginOptions(),
|
||||||
|
new MarkerLayerOptions(
|
||||||
|
markers: buildMarkers(location, mapState.fires,
|
||||||
|
mapState.industries, mapState.falsePos),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
FlutterMapState leafletState = map.createState();
|
||||||
|
// Do something with it
|
||||||
return new Scaffold(
|
return new Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
appBar: new AppBar(
|
appBar: new AppBar(
|
||||||
title: new Text(location.description),
|
title: status == FireMapStatus.edit
|
||||||
),
|
? new TextField(
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
// autofocus: true,
|
||||||
onPressed: () {
|
key: new Key('LocationDescField'),
|
||||||
switch (operation) {
|
keyboardType: TextInputType.text,
|
||||||
case FireMapStatus.view:
|
controller: textController,
|
||||||
view.onSubs(location);
|
decoration: new InputDecoration(),
|
||||||
break;
|
/* onSubmitted: (newDesc) {
|
||||||
case FireMapStatus.subscriptionConfirm:
|
// location.description = newDesc;
|
||||||
view.onSubsConfirmed(location);
|
// view.onEditConfirm(location);
|
||||||
// IOS specific
|
// view.editController.text = '';
|
||||||
_firebaseMessaging.requestNotificationPermissions();
|
},*/
|
||||||
break;
|
)
|
||||||
case FireMapStatus.unsubscribe:
|
: new Text(location.description),
|
||||||
view.onUnSubs(location);
|
actions: listWithoutNulls(<Widget>[
|
||||||
break;
|
status == FireMapStatus.view ||
|
||||||
}
|
status == FireMapStatus.unsubscribe
|
||||||
},
|
? new IconButton(
|
||||||
// https://github.com/flutter/flutter/issues/17583
|
icon: new Icon(Icons.edit),
|
||||||
heroTag: "firesmap" + location.id.toHexString(),
|
onPressed: () => view.onEdit(location))
|
||||||
icon: new Icon(btnIcon, color: fires600),
|
: null
|
||||||
label: new Text(
|
]),
|
||||||
btnText,
|
|
||||||
style: const TextStyle(color: fires600),
|
|
||||||
),
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
),
|
),
|
||||||
|
floatingActionButton: status == FireMapStatus.edit
|
||||||
|
? null
|
||||||
|
: FloatingActionButton.extended(
|
||||||
|
onPressed: () {
|
||||||
|
switch (status) {
|
||||||
|
case FireMapStatus.view:
|
||||||
|
view.onSubs(location);
|
||||||
|
break;
|
||||||
|
case FireMapStatus.subscriptionConfirm:
|
||||||
|
view.onSubsConfirmed(location);
|
||||||
|
// IOS specific
|
||||||
|
_firebaseMessaging.requestNotificationPermissions();
|
||||||
|
break;
|
||||||
|
case FireMapStatus.unsubscribe:
|
||||||
|
view.onUnSubs(location);
|
||||||
|
break;
|
||||||
|
case FireMapStatus.edit:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// https://github.com/flutter/flutter/issues/17583
|
||||||
|
heroTag: "firesmap" + location.id.toHexString(),
|
||||||
|
icon: new Icon(btnIcon, color: fires600),
|
||||||
|
label: new Text(
|
||||||
|
btnText,
|
||||||
|
style: const TextStyle(color: fires600),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
),
|
||||||
floatingActionButtonLocation:
|
floatingActionButtonLocation:
|
||||||
FloatingActionButtonLocation.centerFloat,
|
FloatingActionButtonLocation.centerFloat,
|
||||||
bottomNavigationBar: new YourLocationMapBottom(),
|
bottomNavigationBar: new YourLocationMapBottom(),
|
||||||
body: LayoutBuilder(
|
body: LayoutBuilder(
|
||||||
builder: (context, constraints) =>
|
builder: (context, constraints) =>
|
||||||
Stack(fit: StackFit.expand, children: <Widget>[
|
Stack(fit: StackFit.expand, children: <Widget>[
|
||||||
// Material(color: Colors.yellowAccent),
|
// Material(color: Colors.yellowAccent),
|
||||||
new Opacity(
|
new Opacity(
|
||||||
opacity:
|
opacity: status == FireMapStatus.subscriptionConfirm
|
||||||
operation == FireMapStatus.subscriptionConfirm
|
? 0.5
|
||||||
? 0.5
|
: 1.0,
|
||||||
: 1.0,
|
child: map),
|
||||||
child: new FlutterMap(
|
Positioned(
|
||||||
options: mapOptions,
|
top: constraints.maxHeight - 200,
|
||||||
mapController: mapController,
|
right: 10.0,
|
||||||
layers: [
|
left: 10.0,
|
||||||
new TileLayerOptions(
|
child: new CenteredRow(
|
||||||
maxZoom: 6.0,
|
// Fit sample:
|
||||||
subdomains: ['a', 'b', 'c'],
|
// https://github.com/apptreesoftware/flutter_map/blob/master/flutter_map_example/lib/pages/map_controller.dart
|
||||||
urlTemplate:
|
children:
|
||||||
'https://tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png',
|
status == FireMapStatus.subscriptionConfirm
|
||||||
additionalOptions: {
|
? <Widget>[
|
||||||
// 'opacity': '0.1',
|
new FireDistanceSlider(
|
||||||
'attribution':
|
initialValue: location.distance,
|
||||||
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
onSlide: (distance) {
|
||||||
},
|
location.distance = distance;
|
||||||
),
|
view.onSlide(location);
|
||||||
globals.isDevelopment
|
})
|
||||||
? new ZoomMapPluginOptions()
|
]
|
||||||
: new DummyMapPluginOptions(),
|
: []),
|
||||||
new MarkerLayerOptions(
|
)
|
||||||
markers: buildMarkers(location, mapState.fires,
|
])));
|
||||||
mapState.industries, mapState.falsePos),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
Positioned(
|
|
||||||
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:
|
|
||||||
operation == FireMapStatus.subscriptionConfirm
|
|
||||||
? <Widget>[
|
|
||||||
new FireDistanceSlider(
|
|
||||||
initialValue: location.distance,
|
|
||||||
onSlide: (distance) {
|
|
||||||
location.distance = distance;
|
|
||||||
view.onSlide(location);
|
|
||||||
/* FIXME
|
|
||||||
setState(() {
|
|
||||||
kmAround = distance;
|
|
||||||
Debounce.seconds(1, updateFireStats);
|
|
||||||
}); */
|
|
||||||
})
|
|
||||||
]
|
|
||||||
: [],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
import 'package:fires_flutter/models/yourLocation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
|
||||||
|
|
@ -7,12 +7,18 @@ import 'customBottomAppBar.dart';
|
||||||
import 'generated/i18n.dart';
|
import 'generated/i18n.dart';
|
||||||
import 'models/appState.dart';
|
import 'models/appState.dart';
|
||||||
import 'models/fireMapState.dart';
|
import 'models/fireMapState.dart';
|
||||||
|
import 'redux/actions.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class _ViewModel {
|
class _ViewModel {
|
||||||
final FireMapState state;
|
final FireMapState state;
|
||||||
|
final OnLocationEditConfirm onLocationEditConfirm;
|
||||||
|
final OnLocationEditCancel onLocationEditCancel;
|
||||||
|
|
||||||
_ViewModel({@required this.state});
|
_ViewModel(
|
||||||
|
{@required this.state,
|
||||||
|
@required this.onLocationEditConfirm,
|
||||||
|
@required this.onLocationEditCancel});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
|
|
@ -29,30 +35,53 @@ class YourLocationMapBottom extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new StoreConnector<AppState, _ViewModel>(
|
return new StoreConnector<AppState, _ViewModel>(
|
||||||
distinct: true, // FIXME
|
distinct: true,
|
||||||
converter: (store) {
|
converter: (store) {
|
||||||
return new _ViewModel(state: store.state.fireMapState);
|
return new _ViewModel(
|
||||||
|
state: store.state.fireMapState,
|
||||||
|
onLocationEditConfirm: (loc) =>
|
||||||
|
store.dispatch(new EditConfirmYourLocationAction(loc)),
|
||||||
|
onLocationEditCancel: (loc) =>
|
||||||
|
store.dispatch(new
|
||||||
|
EditCancelYourLocationAction(loc)));
|
||||||
},
|
},
|
||||||
builder: (context, view) {
|
builder: (context, view) {
|
||||||
int kmAround = view.state.yourLocation.distance;
|
YourLocation loc = view.state.yourLocation;
|
||||||
|
int kmAround = loc.distance;
|
||||||
return new CustomBottomAppBar(
|
return new CustomBottomAppBar(
|
||||||
fabLocation: FloatingActionButtonLocation.centerFloat,
|
fabLocation: FloatingActionButtonLocation.centerFloat,
|
||||||
showNotch: false,
|
showNotch: false,
|
||||||
color: fires100,
|
color: fires100,
|
||||||
// height: 170.0,
|
// height: 170.0,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
actions: listWithoutNulls(<Widget>[
|
actions: buildActionList(view, loc, context, kmAround));
|
||||||
view.state.status == FireMapStatus.subscriptionConfirm ||
|
|
||||||
view.state.numFires == null
|
|
||||||
? null
|
|
||||||
: new Text(view.state.numFires > 0
|
|
||||||
? S.of(context).firesAroundThisArea(
|
|
||||||
view.state.numFires.toString(), kmAround.toString())
|
|
||||||
: S
|
|
||||||
.of(context)
|
|
||||||
.noFiresAroundThisArea(kmAround.toString())),
|
|
||||||
SizedBox(width: 10.0)
|
|
||||||
]));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Widget> buildActionList(
|
||||||
|
_ViewModel view, YourLocation loc, BuildContext context, int kmAround) {
|
||||||
|
List<Widget> actionList = new List<Widget>();
|
||||||
|
switch (view.state.status) {
|
||||||
|
case FireMapStatus.edit:
|
||||||
|
actionList.add(new FlatButton(
|
||||||
|
onPressed: () => view.onLocationEditConfirm(loc),
|
||||||
|
child: new Text(S.of(context).SAVE, style: Theme.of(context).textTheme.button)));
|
||||||
|
actionList.add(new FlatButton(
|
||||||
|
onPressed: () => view.onLocationEditCancel(loc),
|
||||||
|
child: new Text(S.of(context).CANCEL, style: Theme.of(context).textTheme.button)));
|
||||||
|
break;
|
||||||
|
case FireMapStatus.subscriptionConfirm:
|
||||||
|
break;
|
||||||
|
case FireMapStatus.unsubscribe:
|
||||||
|
case FireMapStatus.view:
|
||||||
|
if (view.state.numFires != null) {
|
||||||
|
actionList.add(new Text(view.state.numFires > 0
|
||||||
|
? S.of(context).firesAroundThisArea(
|
||||||
|
view.state.numFires.toString(), kmAround.toString())
|
||||||
|
: S.of(context).noFiresAroundThisArea(kmAround.toString())));
|
||||||
|
// SizedBox(width: 10.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return actionList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,5 +42,7 @@
|
||||||
"aYear": "a year",
|
"aYear": "a year",
|
||||||
"inYears": "$value years",
|
"inYears": "$value years",
|
||||||
"somethingAgo": "$something ago",
|
"somethingAgo": "$something ago",
|
||||||
"inSomething": "in $something"
|
"inSomething": "in $something",
|
||||||
|
"SAVE": "SAVE",
|
||||||
|
"CANCEL": "CANCEL"
|
||||||
}
|
}
|
||||||
|
|
@ -42,5 +42,7 @@
|
||||||
"aYear": "un año",
|
"aYear": "un año",
|
||||||
"inYears": "$value años",
|
"inYears": "$value años",
|
||||||
"somethingAgo": "hace $something",
|
"somethingAgo": "hace $something",
|
||||||
"inSomething": "en $something"
|
"inSomething": "en $something",
|
||||||
|
"SAVE": "GUARDAR",
|
||||||
|
"CANCEL": "CANCELAR"
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue