From ce2b65f1e0a805850eb93a171a7a52ff8ac7304b Mon Sep 17 00:00:00 2001 From: vjrj Date: Sat, 9 Jun 2018 17:25:55 +0200 Subject: [PATCH] More work with active fires --- lib/activeFires.dart | 53 +++++++++++++++----------------- lib/basicLocation.dart | 2 ++ lib/firesApp.dart | 21 ++++++------- lib/placesAutocompleteUtils.dart | 3 +- pubspec.yaml | 2 +- 5 files changed, 38 insertions(+), 43 deletions(-) diff --git a/lib/activeFires.dart b/lib/activeFires.dart index 99d74cf..a896ea2 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -12,6 +12,7 @@ import 'package:collection/collection.dart' show lowerBound; class _ActiveFiresPageState extends State { final GlobalKey _scaffoldKey = new GlobalKey(); + // https://docs.flutter.io/flutter/dart-core/List-class.html final List _saved = []; int length; @@ -19,16 +20,20 @@ class _ActiveFiresPageState extends State { _ActiveFiresPageState(); Widget _buildRow(BasicLocation loc) { - String desc = loc.description != null ? loc.description: - 'Position: ${loc.lat}, ${loc.lon}'; + String desc = loc.description != null + ? loc.description + : 'Position: ${loc.lat}, ${loc.lon}'; return new ListTile( dense: false, leading: const Icon(Icons.location_on), // trailing: const Icon(Icons.delete), title: new Text(desc), onTap: () { - Navigator.push(context, - new MaterialPageRoute(builder: (context) => new GenericMap(title: desc, latitude: loc.lat, longitude: loc.lon))); + Navigator.push( + context, + new MaterialPageRoute( + builder: (context) => new GenericMap( + title: desc, latitude: loc.lat, longitude: loc.lon))); }); } @@ -100,8 +105,6 @@ class _ActiveFiresPageState extends State { } Future getUserLocation() async { - // FIXME do something with this - String error; // Platform messages may fail, so we use a try/catch PlatformException. try { @@ -112,16 +115,22 @@ class _ActiveFiresPageState extends State { // It seems that the lib fails with lat/lon values return new BasicLocation( - lon: location['latitude'], lat: location['longitude']); + lat: location['latitude'], lon: location['longitude']); } on PlatformException catch (e) { 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'; } else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') { error = 'Permission denied - please ask the user to enable it from the app settings'; } - // FIXME - throw e; + _scaffoldKey.currentState.showSnackBar(new SnackBar( + 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 { @override Widget build(BuildContext context) { print('Building Active Fires, saved $length'); - final title = 'Active fires locations'; + final title = 'Your locations'; return Scaffold( key: _scaffoldKey, drawer: new MainDrawer(context), @@ -211,29 +220,15 @@ class _ActiveFiresPageState extends State { void _saveLocation(Future location) { location.then((newLocation) { - this.setState(() { - _saved.add(newLocation); - length = _saved.length; - }); + if (newLocation != BasicLocation.noLocation) + this.setState(() { + _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 { static const String routeName = '/fires'; diff --git a/lib/basicLocation.dart b/lib/basicLocation.dart index 4f04154..d7a8b25 100644 --- a/lib/basicLocation.dart +++ b/lib/basicLocation.dart @@ -5,5 +5,7 @@ class BasicLocation { final double lon; final String description; + static BasicLocation noLocation = new BasicLocation(lat:0.0, lon:0.0); + BasicLocation({@required this.lat, @required this.lon, this.description}); } diff --git a/lib/firesApp.dart b/lib/firesApp.dart index 2fca976..d64c641 100644 --- a/lib/firesApp.dart +++ b/lib/firesApp.dart @@ -9,18 +9,17 @@ import 'placesAutocompleteWidget.dart'; import 'globals.dart' as globals; class FiresApp extends StatelessWidget { - + static final WidgetBuilder introWidget = (context) => new IntroPage(); + static final WidgetBuilder continueWidget = (context) => new HomePage(); Map routes = { - PlacesAutocompleteWidget.routeName: (BuildContext context) => - new PlacesAutocompleteWidget(), - Sandbox.routeName: (BuildContext context) => new Sandbox(), - ActiveFiresPage.routeName: (BuildContext context) => - new ActiveFiresPage(), - IntroPage.routeName: (BuildContext context) => new IntroPage(), - }; - final WidgetBuilder introWidget = (context) => new IntroPage(); - final WidgetBuilder continueWidget = (context) => new HomePage(); + PlacesAutocompleteWidget.routeName: (BuildContext context) => + new PlacesAutocompleteWidget(), + Sandbox.routeName: (BuildContext context) => new Sandbox(), + ActiveFiresPage.routeName: (BuildContext context) => new ActiveFiresPage(), + HomePage.routeName: continueWidget, + IntroPage.routeName: introWidget, + }; // globals.getIt.registerSingleton FiresApp(); @@ -28,7 +27,7 @@ class FiresApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( - home: new MaterialAppWithIntroHome(introWidget, continueWidget), + home: new MaterialAppWithIntroHome(introWidget, continueWidget, 'showInitialWizard234'), title: 'All Against The Fire!', theme: firesTheme, routes: routes); diff --git a/lib/placesAutocompleteUtils.dart b/lib/placesAutocompleteUtils.dart index 7044703..51d5c2f 100644 --- a/lib/placesAutocompleteUtils.dart +++ b/lib/placesAutocompleteUtils.dart @@ -25,8 +25,7 @@ Future openPlacesDialog(BuildContext context) async { PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId); final lat = detail.result.geometry.location.lat; final lng = detail.result.geometry.location.lng; - return new BasicLocation(lat: lat, lon: lng, description: p.description); } - return null; + return BasicLocation.noLocation; } diff --git a/pubspec.yaml b/pubspec.yaml index 1497f8e..a0229e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: shared_preferences: "^0.4.2" 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. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: "^0.1.2"