- introPage.dart: Convert fireItems to proper static function closure - mainDrawer.dart: Convert unreadCount int to String for Text widget
34 lines
1.2 KiB
Dart
34 lines
1.2 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:comunes_flutter/comunes_flutter.dart';
|
|
import 'package:shared_preferences/src/shared_preferences_legacy.dart';
|
|
|
|
import '../globals.dart' as globals;
|
|
import 'yourLocation.dart';
|
|
|
|
const String locationKey = 'yourlocations';
|
|
|
|
Future<List<YourLocation>> loadYourLocations() async {
|
|
return globals.prefs.then((SharedPreferences prefs) {
|
|
final List<String>? yourLocations = prefs.getStringList(locationKey);
|
|
final List<YourLocation> persistedList = <YourLocation>[];
|
|
for (final String locationString in (yourLocations ?? <String>[])) {
|
|
final Map<String, dynamic> locationMap =
|
|
json.decode(locationString) as Map<String, dynamic>;
|
|
persistedList.add(YourLocation.fromJson(locationMap));
|
|
}
|
|
return persistedList;
|
|
});
|
|
}
|
|
|
|
void persistYourLocations(List<YourLocation> yl) {
|
|
// debugPrint('Persisting $yl');
|
|
globals.prefs.then((SharedPreferences prefs) {
|
|
final List<String> ylAsString = <String>[];
|
|
yl.where(notNull).toList().forEach((YourLocation location) {
|
|
ylAsString.add(json.encode(location.toJson()));
|
|
});
|
|
prefs.setStringList(locationKey, ylAsString);
|
|
});
|
|
}
|