Keep replaced tab navigation owners from overwriting newer state
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../shell/destination.dart';
|
||||
import '../core/storage/ordered_local_storage.dart';
|
||||
import 'app_route.dart';
|
||||
import 'tab_locations_store.dart';
|
||||
import 'tab_location_routes.dart';
|
||||
@@ -19,6 +20,10 @@ class TabLocations {
|
||||
bool persistenceFailed = false;
|
||||
Future<void> _writes = Future<void>.value();
|
||||
|
||||
Object get _storageKey => store is SharedPreferencesTabLocationsStore
|
||||
? (store as SharedPreferencesTabLocationsStore).key
|
||||
: store;
|
||||
|
||||
void record(AppRoute route, {bool visited = true}) {
|
||||
if (_disposed) return;
|
||||
active = tabForRoute(route);
|
||||
@@ -34,7 +39,7 @@ class TabLocations {
|
||||
Future<AppRoute?> restore({required bool restoreActive}) async {
|
||||
TabLocationsSnapshot saved;
|
||||
try {
|
||||
saved = await store.load();
|
||||
saved = await orderedLocalStorage(_storageKey, store.load);
|
||||
} catch (_) {
|
||||
// Keep in-memory navigation, but never overwrite unread stored history.
|
||||
persistenceFailed = true;
|
||||
@@ -63,8 +68,13 @@ class TabLocations {
|
||||
},
|
||||
);
|
||||
_writes = _writes.then((_) async {
|
||||
if (_disposed) return;
|
||||
try {
|
||||
persistenceFailed = !await store.save(snapshot);
|
||||
final saved = await orderedLocalStorage<bool?>(_storageKey, () async {
|
||||
if (_disposed) return null;
|
||||
return store.save(snapshot);
|
||||
});
|
||||
if (saved != null) persistenceFailed = !saved;
|
||||
} catch (_) {
|
||||
persistenceFailed = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user