mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 10:29:06 +02:00
Moved platform brightness checking from ArcaneApp to ArcaneThemeSwitcher, where it is more appropriate
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -15,13 +15,17 @@ class ArcaneThemeSwitcher extends StatefulWidget {
|
||||
State<ArcaneThemeSwitcher> createState() => _ArcaneThemeSwitcherState();
|
||||
}
|
||||
|
||||
class _ArcaneThemeSwitcherState extends State<ArcaneThemeSwitcher> {
|
||||
class _ArcaneThemeSwitcherState extends State<ArcaneThemeSwitcher>
|
||||
with WidgetsBindingObserver {
|
||||
late final StreamSubscription<ThemeMode> _themeModeSubscription;
|
||||
late final StreamSubscription<ThemeData> _themeSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Register as an observer to detect system theme changes
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
||||
_themeModeSubscription = ArcaneReactiveTheme.I.themeModeChanges.listen((_) {
|
||||
setState(() {});
|
||||
});
|
||||
@@ -34,6 +38,8 @@ class _ArcaneThemeSwitcherState extends State<ArcaneThemeSwitcher> {
|
||||
void dispose() {
|
||||
_themeModeSubscription.cancel();
|
||||
_themeSubscription.cancel();
|
||||
// Clean up the observer when the widget is disposed
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -46,4 +52,19 @@ class _ArcaneThemeSwitcherState extends State<ArcaneThemeSwitcher> {
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangePlatformBrightness() {
|
||||
// When system brightness changes, find the current builder context
|
||||
// and use it to check the system theme
|
||||
if (mounted) {
|
||||
// Use the current context from the key to check system theme
|
||||
if (ArcaneReactiveTheme.I.isFollowingSystemTheme) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ArcaneReactiveTheme.I.followSystemTheme(context);
|
||||
});
|
||||
}
|
||||
}
|
||||
super.didChangePlatformBrightness();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user