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> {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
|
||||
// https://docs.flutter.io/flutter/dart-core/List-class.html
|
||||
final List<BasicLocation> _saved = [];
|
||||
int length;
|
||||
|
|
@ -19,16 +20,20 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
_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<ActiveFiresPage> {
|
|||
}
|
||||
|
||||
Future<BasicLocation> 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<ActiveFiresPage> {
|
|||
|
||||
// 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<ActiveFiresPage> {
|
|||
@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<ActiveFiresPage> {
|
|||
|
||||
void _saveLocation(Future<BasicLocation> 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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = <String, WidgetBuilder>{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ Future<BasicLocation> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue