Auto dark/bright follows the sun at the tablet's own location
Without a light sensor an app may read (the Redmi Pad SE has none), auto is dark while the sun is more than 4° below the horizon (lib/theme/sun.dart), at Android's coarse location, polled and kept across restarts. The tablet's own, not the Orin's GNSS: the tablet has its own GNSS and cellular. Android's dark theme is the last fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:display/theme/light.dart';
|
||||
import 'package:display/theme/palette.dart';
|
||||
import 'package:display/theme/sun.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -69,5 +70,57 @@ void main() {
|
||||
const Duration(seconds: 6),
|
||||
); // no new reading: the timer ends the hold
|
||||
expect(t.isDark, isTrue);
|
||||
t.dispose();
|
||||
});
|
||||
|
||||
test(
|
||||
'the sun: high at noon, below at midnight, sets near the almanac time',
|
||||
() {
|
||||
// Tokyo, 2026-06-21: noon (03:00 UTC) about 77°, midnight well below.
|
||||
expect(
|
||||
sunElevation(35.68, 139.77, DateTime.utc(2026, 6, 21, 2, 43)),
|
||||
closeTo(77.7, 1),
|
||||
);
|
||||
expect(
|
||||
sunElevation(35.68, 139.77, DateTime.utc(2026, 6, 21, 15)),
|
||||
lessThan(-20),
|
||||
);
|
||||
// Helsinki, 2026-10-15: sunset 18:14 EEST (15:14 UTC): -0.8° there.
|
||||
expect(
|
||||
sunElevation(60.17, 24.94, DateTime.utc(2026, 10, 15, 15, 14)),
|
||||
closeTo(-0.8, 0.6),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'auto: the sun before Android, the light sensor before the sun',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
dispatcher.platformBrightnessTestValue = Brightness.light;
|
||||
var now = DateTime.utc(2026, 6, 21, 15); // Tokyo midnight
|
||||
final t = Themes(
|
||||
't',
|
||||
Palette.fallbackDark,
|
||||
Palette.fallbackBright,
|
||||
prefs,
|
||||
() => now,
|
||||
);
|
||||
expect((t.isDark, t.autoSource), (false, "Android's dark theme"));
|
||||
t.setPosition(35.68, 139.77);
|
||||
expect((t.isDark, t.autoSource), (true, 'the sun'));
|
||||
now = DateTime.utc(2026, 6, 21, 3);
|
||||
final again = Themes(
|
||||
't',
|
||||
Palette.fallbackDark,
|
||||
Palette.fallbackBright,
|
||||
prefs,
|
||||
() => now,
|
||||
);
|
||||
expect(again.isDark, isFalse); // position kept; Tokyo noon
|
||||
t.dispose();
|
||||
again.dispose();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user