Remember the diff layout across reloads

One file at a time or all files stacked is saved in the app's
preferences and restored when the app starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 19:23:21 +00:00
parent 9bf080597a
commit cbc06b2f13
4 changed files with 86 additions and 2 deletions
@@ -0,0 +1,45 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Whether diff pages show every file stacked (GitHub's Files changed) rather
/// than one file at a time, kept across reloads in the app's preferences.
class DiffLayoutPreference extends ValueNotifier<bool> {
DiffLayoutPreference() : super(false);
static const String storageKey = 'pipelines.diff.all-files.v1';
Future<void>? _restoring;
bool _chosen = false;
/// Reads the saved layout once. A choice made before the read finishes
/// wins over the saved one.
Future<void> restore() => _restoring ??= () async {
try {
final saved = (await SharedPreferences.getInstance()).getBool(storageKey);
if (saved != null && !_chosen) super.value = saved;
} catch (_) {
// Unavailable preferences keep the default layout.
}
}();
@override
set value(bool showAll) {
_chosen = true;
if (showAll == super.value) return;
super.value = showAll;
unawaited(_save(showAll));
}
Future<void> _save(bool showAll) async {
try {
await (await SharedPreferences.getInstance()).setBool(
storageKey,
showAll,
);
} catch (_) {
// The layout still applies for this session.
}
}
}