Dark/bright: Auto (Android's dark theme), Dark or Bright, kept across restarts
Settings has a segmented Auto / Dark / Bright. Auto follows platformBrightness, so Android's schedule too. The Dash's quick button holds the other variant; a long press is auto again. The mode is kept with shared_preferences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import 'package:display/theme/palette.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
final dispatcher = TestWidgetsFlutterBinding.instance.platformDispatcher;
|
||||
tearDown(dispatcher.clearPlatformBrightnessTestValue);
|
||||
|
||||
test(
|
||||
'auto follows Android, the quick switch holds one, and it is kept',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
Themes make() =>
|
||||
Themes('t', Palette.fallbackDark, Palette.fallbackBright, prefs);
|
||||
final t = make();
|
||||
var notified = 0;
|
||||
t.addListener(() => notified++);
|
||||
|
||||
expect(t.mode, VariantMode.auto);
|
||||
dispatcher.platformBrightnessTestValue = Brightness.light;
|
||||
expect(t.isDark, isFalse);
|
||||
expect(notified, 1); // the binding tells its observers
|
||||
|
||||
t.toggle(); // bright showing: hold dark
|
||||
expect((t.mode, t.isDark), (VariantMode.dark, true));
|
||||
dispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
dispatcher.platformBrightnessTestValue = Brightness.light;
|
||||
expect(notified, 2); // fixed: Android's changes are ignored
|
||||
|
||||
expect(make().mode, VariantMode.dark); // kept for the next start
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user