Persist your saved locations
This commit is contained in:
parent
c9941429f0
commit
0ad2fce4f3
5 changed files with 19 additions and 33 deletions
|
|
@ -13,6 +13,7 @@ import 'locationUtils.dart';
|
||||||
import 'mainDrawer.dart';
|
import 'mainDrawer.dart';
|
||||||
import 'placesAutocompleteUtils.dart';
|
import 'placesAutocompleteUtils.dart';
|
||||||
import 'yourLocation.dart';
|
import 'yourLocation.dart';
|
||||||
|
import 'yourLocationPersist.dart';
|
||||||
|
|
||||||
class ActiveFiresPage extends StatefulWidget {
|
class ActiveFiresPage extends StatefulWidget {
|
||||||
static const String routeName = '/fires';
|
static const String routeName = '/fires';
|
||||||
|
|
@ -60,9 +61,9 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
loc.subscribed = !loc.subscribed;
|
loc.subscribed = !loc.subscribed;
|
||||||
int i = globals.yourLocations.indexOf(loc);
|
int i = globals.yourLocations.indexOf(loc);
|
||||||
YourLocationRepository.repo.update(i, loc);
|
|
||||||
globals.yourLocations.removeAt(i);
|
globals.yourLocations.removeAt(i);
|
||||||
globals.yourLocations.insert(i, loc);
|
globals.yourLocations.insert(i, loc);
|
||||||
|
persistYourLocations();
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}),
|
}),
|
||||||
title: new Text(loc.description),
|
title: new Text(loc.description),
|
||||||
|
|
@ -102,7 +103,8 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
|
|
||||||
void handleUndo(YourLocation item) {
|
void handleUndo(YourLocation item) {
|
||||||
setState(() {
|
setState(() {
|
||||||
YourLocationRepository.repo.save(item);
|
globals.yourLocations.add(item);
|
||||||
|
persistYourLocations();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,8 +116,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
onDismissed: (DismissDirection direction) {
|
onDismissed: (DismissDirection direction) {
|
||||||
setState(() {
|
setState(() {
|
||||||
globals.yourLocations.remove(item);
|
globals.yourLocations.remove(item);
|
||||||
int i = globals.yourLocations.indexOf(item);
|
persistYourLocations();
|
||||||
YourLocationRepository.repo.remove(i);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_scaffoldKey.currentState.showSnackBar(new SnackBar(
|
_scaffoldKey.currentState.showSnackBar(new SnackBar(
|
||||||
|
|
@ -207,7 +208,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
} else
|
} else
|
||||||
this.setState(() {
|
this.setState(() {
|
||||||
globals.yourLocations.add(newLocation);
|
globals.yourLocations.add(newLocation);
|
||||||
YourLocationRepository.repo.save(newLocation);
|
persistYourLocations();
|
||||||
new Timer(new Duration(milliseconds: 1000), () {
|
new Timer(new Duration(milliseconds: 1000), () {
|
||||||
showLocationMap(newLocation);
|
showLocationMap(newLocation);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ library fires.globals;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'yourLocation.dart';
|
import 'yourLocation.dart';
|
||||||
|
|
||||||
|
|
@ -14,7 +16,7 @@ final Widget appMediumIcon =
|
||||||
Image.asset('images/logo-200.png', width: 60.0, height: 60.0);
|
Image.asset('images/logo-200.png', width: 60.0, height: 60.0);
|
||||||
final Widget appIcon =
|
final Widget appIcon =
|
||||||
Image.asset('images/logo-200.png', width: 24.0, height: 24.0);
|
Image.asset('images/logo-200.png', width: 24.0, height: 24.0);
|
||||||
// final Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
final Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||||
List<YourLocation> yourLocations = [];
|
List<YourLocation> yourLocations = [];
|
||||||
final GetIt getIt = new GetIt();
|
final GetIt getIt = new GetIt();
|
||||||
bool isDevelopment = false;
|
bool isDevelopment = false;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import 'firebaseMessagingConf.dart';
|
||||||
import 'firesApp.dart';
|
import 'firesApp.dart';
|
||||||
import 'globals.dart' as globals;
|
import 'globals.dart' as globals;
|
||||||
import 'yourLocation.dart';
|
import 'yourLocation.dart';
|
||||||
|
import 'yourLocationPersist.dart';
|
||||||
|
|
||||||
Future<Map<String, dynamic>> loadSecrets() async {
|
Future<Map<String, dynamic>> loadSecrets() async {
|
||||||
return await SecretLoader(secretPath: 'assets/private-settings.json').load();
|
return await SecretLoader(secretPath: 'assets/private-settings.json').load();
|
||||||
}
|
}
|
||||||
|
|
@ -16,9 +18,8 @@ void mainCommon() {
|
||||||
globals.gmapKey = secrets['gmapKey'];
|
globals.gmapKey = secrets['gmapKey'];
|
||||||
globals.firesApiKey = secrets['firesApiKey'];
|
globals.firesApiKey = secrets['firesApiKey'];
|
||||||
globals.firesApiUrl = secrets['firesApiUrl'] + "api/v1/";
|
globals.firesApiUrl = secrets['firesApiUrl'] + "api/v1/";
|
||||||
YourLocationRepository.repo.remove(0);
|
globals.prefs.then((prefs) {
|
||||||
YourLocationRepository.repo.getAll().then((yourLocations) {
|
loadYourLocationsWithPrefs(prefs);
|
||||||
globals.yourLocations = yourLocations;
|
|
||||||
firebaseConfig();
|
firebaseConfig();
|
||||||
|
|
||||||
// Run baby run!
|
// Run baby run!
|
||||||
|
|
|
||||||
|
|
@ -58,21 +58,3 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
|
||||||
description.hashCode ^
|
description.hashCode ^
|
||||||
subscribed.hashCode;
|
subscribed.hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
class YourLocationRepository extends PreferencesRepository<YourLocation> {
|
|
||||||
|
|
||||||
static final repo = new YourLocationRepository();
|
|
||||||
|
|
||||||
YourLocationRepository() : super();
|
|
||||||
|
|
||||||
@override
|
|
||||||
YourLocation deserialize(String s) {
|
|
||||||
|
|
||||||
return YourLocation.fromJson(json.decode(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String serialize(YourLocation y) {
|
|
||||||
return json.encode(y.toJson());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'basicLocation.dart';
|
import 'yourLocation.dart';
|
||||||
import 'globals.dart' as globals;
|
import 'globals.dart' as globals;
|
||||||
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
@ -30,7 +30,7 @@ void loadYourLocationsWithPrefs(SharedPreferences prefs) {
|
||||||
}
|
}
|
||||||
yourLocations.forEach((locationString) {
|
yourLocations.forEach((locationString) {
|
||||||
Map locationMap = json.decode(locationString);
|
Map locationMap = json.decode(locationString);
|
||||||
globals.yourLocations.add(BasicLocation.fromJson(locationMap));
|
globals.yourLocations.add(YourLocation.fromJson(locationMap));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue