tentatively shrink trip overview, nicer onboarding
This commit is contained in:
@@ -1,16 +1,39 @@
|
||||
import 'package:anyway/structs/trip.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
Future<List<Trip>> loadTrips() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
List<Trip> trips = [];
|
||||
Set<String> keys = prefs.getKeys();
|
||||
for (String key in keys) {
|
||||
if (key.startsWith('trip_')) {
|
||||
String uuid = key.replaceFirst('trip_', '');
|
||||
trips.add(Trip.fromPrefs(prefs, uuid));
|
||||
class SavedTrips extends ChangeNotifier {
|
||||
List<Trip> _trips = [];
|
||||
|
||||
List<Trip> get trips => _trips;
|
||||
|
||||
void loadTrips() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
List<Trip> trips = [];
|
||||
Set<String> keys = prefs.getKeys();
|
||||
for (String key in keys) {
|
||||
if (key.startsWith('trip_')) {
|
||||
String uuid = key.replaceFirst('trip_', '');
|
||||
trips.add(Trip.fromPrefs(prefs, uuid));
|
||||
}
|
||||
}
|
||||
_trips = trips;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void addTrip(Trip trip) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
trip.toPrefs(prefs);
|
||||
_trips.add(trip);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clearTrips () async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.clear();
|
||||
_trips = [];
|
||||
notifyListeners();
|
||||
}
|
||||
return trips;
|
||||
}
|
||||
|
Reference in New Issue
Block a user