Auto dark/bright takes a light sensor where the device allows one
lib/theme/light.dart: dark at 15 lux or less, bright from 60, held 5 s; Settings shows the reading. The Redmi Pad SE refuses apps its only light sensor (Xiaomi's, from the front camera), so there Auto keeps following Android's dark theme. DASH-NEXT.md records the other lux sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:display/theme/light.dart';
|
||||
import 'package:display/theme/palette.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -33,4 +36,38 @@ void main() {
|
||||
expect(make().mode, VariantMode.dark); // kept for the next start
|
||||
},
|
||||
);
|
||||
|
||||
test('the light switch has a gap and a hold', () {
|
||||
final s = LightSwitch();
|
||||
final t0 = DateTime(2026);
|
||||
DateTime at(int sec) => t0.add(Duration(seconds: sec));
|
||||
expect(s.feed(30, at(0)), isNull); // in the gap: no verdict yet
|
||||
expect(s.feed(500, at(1)), isFalse); // the first clear reading decides
|
||||
expect(s.feed(30, at(2)), isFalse); // the gap keeps it
|
||||
expect(s.feed(5, at(3)), isFalse); // dark, but not for long enough
|
||||
expect(s.pending, isTrue);
|
||||
expect(s.feed(200, at(4)), isFalse); // back: the hold restarts
|
||||
expect(s.pending, isFalse);
|
||||
s.feed(5, at(10));
|
||||
expect(s.feed(5, at(14)), isFalse);
|
||||
expect(s.feed(5, at(15)), isTrue);
|
||||
});
|
||||
|
||||
testWidgets('auto takes the light sensor over Android', (tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
final t = Themes('t', Palette.fallbackDark, Palette.fallbackBright, prefs);
|
||||
final levels = StreamController<double>();
|
||||
t.followLight(levels.stream);
|
||||
expect(t.isDark, isTrue); // no reading yet: Android's
|
||||
levels.add(800);
|
||||
await tester.pump();
|
||||
expect((t.isDark, t.lux.value), (false, 800));
|
||||
levels.add(2);
|
||||
await tester.pump(
|
||||
const Duration(seconds: 6),
|
||||
); // no new reading: the timer ends the hold
|
||||
expect(t.isDark, isTrue);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user