More work with active fires
This commit is contained in:
parent
8e4e469eb8
commit
ce2b65f1e0
5 changed files with 38 additions and 43 deletions
|
|
@ -12,6 +12,7 @@ import 'package:collection/collection.dart' show lowerBound;
|
||||||
|
|
||||||
class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||||
|
|
||||||
// https://docs.flutter.io/flutter/dart-core/List-class.html
|
// https://docs.flutter.io/flutter/dart-core/List-class.html
|
||||||
final List<BasicLocation> _saved = [];
|
final List<BasicLocation> _saved = [];
|
||||||
int length;
|
int length;
|
||||||
|
|
@ -19,16 +20,20 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
_ActiveFiresPageState();
|
_ActiveFiresPageState();
|
||||||
|
|
||||||
Widget _buildRow(BasicLocation loc) {
|
Widget _buildRow(BasicLocation loc) {
|
||||||
String desc = loc.description != null ? loc.description:
|
String desc = loc.description != null
|
||||||
'Position: ${loc.lat}, ${loc.lon}';
|
? loc.description
|
||||||
|
: 'Position: ${loc.lat}, ${loc.lon}';
|
||||||
return new ListTile(
|
return new ListTile(
|
||||||
dense: false,
|
dense: false,
|
||||||
leading: const Icon(Icons.location_on),
|
leading: const Icon(Icons.location_on),
|
||||||
// trailing: const Icon(Icons.delete),
|
// trailing: const Icon(Icons.delete),
|
||||||
title: new Text(desc),
|
title: new Text(desc),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context,
|
Navigator.push(
|
||||||
new MaterialPageRoute(builder: (context) => new GenericMap(title: desc, latitude: loc.lat, longitude: loc.lon)));
|
context,
|
||||||
|
new MaterialPageRoute(
|
||||||
|
builder: (context) => new GenericMap(
|
||||||
|
title: desc, latitude: loc.lat, longitude: loc.lon)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,8 +105,6 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<BasicLocation> getUserLocation() async {
|
Future<BasicLocation> getUserLocation() async {
|
||||||
// FIXME do something with this
|
|
||||||
|
|
||||||
String error;
|
String error;
|
||||||
// Platform messages may fail, so we use a try/catch PlatformException.
|
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||||
try {
|
try {
|
||||||
|
|
@ -112,16 +115,22 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
|
|
||||||
// It seems that the lib fails with lat/lon values
|
// It seems that the lib fails with lat/lon values
|
||||||
return new BasicLocation(
|
return new BasicLocation(
|
||||||
lon: location['latitude'], lat: location['longitude']);
|
lat: location['latitude'], lon: location['longitude']);
|
||||||
} on PlatformException catch (e) {
|
} on PlatformException catch (e) {
|
||||||
if (e.code == 'PERMISSION_DENIED') {
|
if (e.code == 'PERMISSION_DENIED') {
|
||||||
|
_scaffoldKey.currentState.showSnackBar(new SnackBar(
|
||||||
|
content: new Text('We don\'t have permission to get your location'),
|
||||||
|
));
|
||||||
error = 'Permission denied';
|
error = 'Permission denied';
|
||||||
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
|
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
|
||||||
error =
|
error =
|
||||||
'Permission denied - please ask the user to enable it from the app settings';
|
'Permission denied - please ask the user to enable it from the app settings';
|
||||||
}
|
}
|
||||||
// FIXME
|
_scaffoldKey.currentState.showSnackBar(new SnackBar(
|
||||||
throw e;
|
content: new Text(
|
||||||
|
'I cannot get your current location. It\'s your ubication enabled?'),
|
||||||
|
));
|
||||||
|
return BasicLocation.noLocation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +143,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
print('Building Active Fires, saved $length');
|
print('Building Active Fires, saved $length');
|
||||||
final title = 'Active fires locations';
|
final title = 'Your locations';
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
drawer: new MainDrawer(context),
|
drawer: new MainDrawer(context),
|
||||||
|
|
@ -211,29 +220,15 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
|
|
||||||
void _saveLocation(Future<BasicLocation> location) {
|
void _saveLocation(Future<BasicLocation> location) {
|
||||||
location.then((newLocation) {
|
location.then((newLocation) {
|
||||||
this.setState(() {
|
if (newLocation != BasicLocation.noLocation)
|
||||||
_saved.add(newLocation);
|
this.setState(() {
|
||||||
length = _saved.length;
|
_saved.add(newLocation);
|
||||||
});
|
length = _saved.length;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyDrawer extends StatelessWidget {
|
|
||||||
static final MyDrawer _drawer = new MyDrawer._internal();
|
|
||||||
|
|
||||||
factory MyDrawer() {
|
|
||||||
return _drawer;
|
|
||||||
}
|
|
||||||
|
|
||||||
MyDrawer._internal();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return new Text("Drawer");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ActiveFiresPage extends StatefulWidget {
|
class ActiveFiresPage extends StatefulWidget {
|
||||||
static const String routeName = '/fires';
|
static const String routeName = '/fires';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,7 @@ class BasicLocation {
|
||||||
final double lon;
|
final double lon;
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
|
static BasicLocation noLocation = new BasicLocation(lat:0.0, lon:0.0);
|
||||||
|
|
||||||
BasicLocation({@required this.lat, @required this.lon, this.description});
|
BasicLocation({@required this.lat, @required this.lon, this.description});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,17 @@ import 'placesAutocompleteWidget.dart';
|
||||||
import 'globals.dart' as globals;
|
import 'globals.dart' as globals;
|
||||||
|
|
||||||
class FiresApp extends StatelessWidget {
|
class FiresApp extends StatelessWidget {
|
||||||
|
static final WidgetBuilder introWidget = (context) => new IntroPage();
|
||||||
|
static final WidgetBuilder continueWidget = (context) => new HomePage();
|
||||||
|
|
||||||
Map routes = <String, WidgetBuilder>{
|
Map routes = <String, WidgetBuilder>{
|
||||||
PlacesAutocompleteWidget.routeName: (BuildContext context) =>
|
PlacesAutocompleteWidget.routeName: (BuildContext context) =>
|
||||||
new PlacesAutocompleteWidget(),
|
new PlacesAutocompleteWidget(),
|
||||||
Sandbox.routeName: (BuildContext context) => new Sandbox(),
|
Sandbox.routeName: (BuildContext context) => new Sandbox(),
|
||||||
ActiveFiresPage.routeName: (BuildContext context) =>
|
ActiveFiresPage.routeName: (BuildContext context) => new ActiveFiresPage(),
|
||||||
new ActiveFiresPage(),
|
HomePage.routeName: continueWidget,
|
||||||
IntroPage.routeName: (BuildContext context) => new IntroPage(),
|
IntroPage.routeName: introWidget,
|
||||||
};
|
};
|
||||||
final WidgetBuilder introWidget = (context) => new IntroPage();
|
|
||||||
final WidgetBuilder continueWidget = (context) => new HomePage();
|
|
||||||
|
|
||||||
// globals.getIt.registerSingleton
|
// globals.getIt.registerSingleton
|
||||||
FiresApp();
|
FiresApp();
|
||||||
|
|
@ -28,7 +27,7 @@ class FiresApp extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new MaterialApp(
|
return new MaterialApp(
|
||||||
home: new MaterialAppWithIntroHome(introWidget, continueWidget),
|
home: new MaterialAppWithIntroHome(introWidget, continueWidget, 'showInitialWizard234'),
|
||||||
title: 'All Against The Fire!',
|
title: 'All Against The Fire!',
|
||||||
theme: firesTheme,
|
theme: firesTheme,
|
||||||
routes: routes);
|
routes: routes);
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ Future<BasicLocation> openPlacesDialog(BuildContext context) async {
|
||||||
PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);
|
PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);
|
||||||
final lat = detail.result.geometry.location.lat;
|
final lat = detail.result.geometry.location.lat;
|
||||||
final lng = detail.result.geometry.location.lng;
|
final lng = detail.result.geometry.location.lng;
|
||||||
|
|
||||||
return new BasicLocation(lat: lat, lon: lng, description: p.description);
|
return new BasicLocation(lat: lat, lon: lng, description: p.description);
|
||||||
}
|
}
|
||||||
return null;
|
return BasicLocation.noLocation;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ dependencies:
|
||||||
shared_preferences: "^0.4.2"
|
shared_preferences: "^0.4.2"
|
||||||
comunes_flutter:
|
comunes_flutter:
|
||||||
path: /home/vjrj/dev/comunes_flutter
|
path: /home/vjrj/dev/comunes_flutter
|
||||||
version: "^0.0.4"
|
version: "^0.0.5"
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: "^0.1.2"
|
cupertino_icons: "^0.1.2"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue