mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 02:19:08 +02:00
Fixes bug with following/unfollowing system theme
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -44,6 +44,6 @@ export "package:arcane_framework/src/providers/service_provider.dart";
|
||||
export "package:arcane_framework/src/services/authentication/authentication_service.dart";
|
||||
export "package:arcane_framework/src/services/feature_flags/feature_flags_service.dart";
|
||||
export "package:arcane_framework/src/services/logging/logging_service.dart";
|
||||
export "package:arcane_framework/src/services/reactive_theme/arcane_theme.dart";
|
||||
export "package:arcane_framework/src/services/reactive_theme/reactive_theme_service.dart";
|
||||
export "package:arcane_framework/src/services/reactive_theme/reactive_theme_wrapper.dart";
|
||||
export "package:result_monad/result_monad.dart";
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
class ArcaneTheme extends InheritedWidget {
|
||||
final ThemeMode themeMode;
|
||||
final bool followSystem;
|
||||
|
||||
const ArcaneTheme({
|
||||
required this.themeMode,
|
||||
required this.followSystem,
|
||||
required super.child,
|
||||
super.key,
|
||||
});
|
||||
|
||||
static ArcaneTheme? of(BuildContext context) {
|
||||
return context.dependOnInheritedWidgetOfExactType<ArcaneTheme>();
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(ArcaneTheme oldWidget) {
|
||||
return themeMode != oldWidget.themeMode ||
|
||||
followSystem != oldWidget.followSystem;
|
||||
}
|
||||
}
|
||||
@@ -16,31 +16,27 @@ class ArcaneThemeSwitcher extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ArcaneThemeSwitcherState extends State<ArcaneThemeSwitcher> {
|
||||
late final StreamSubscription<ThemeMode> _themeModeSubscription;
|
||||
ThemeMode _currentThemeMode = ArcaneReactiveTheme.I.currentTheme;
|
||||
late final StreamSubscription<ThemeMode> _subscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_themeModeSubscription =
|
||||
ArcaneReactiveTheme.I.themeChanges.listen((ThemeMode newMode) {
|
||||
if (mounted)
|
||||
setState(() {
|
||||
_currentThemeMode = newMode;
|
||||
});
|
||||
_subscription = ArcaneReactiveTheme.I.themeChanges.listen((_) {
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_themeModeSubscription.cancel();
|
||||
_subscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ArcaneTheme(
|
||||
themeMode: _currentThemeMode,
|
||||
themeMode: ArcaneReactiveTheme.I.currentTheme,
|
||||
followSystem: ArcaneReactiveTheme.I.isFollowingSystemTheme,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import "dart:async";
|
||||
|
||||
import "package:arcane_framework/src/services/reactive_theme/reactive_theme_service.dart";
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
class ArcaneTheme extends InheritedWidget {
|
||||
final ThemeMode themeMode;
|
||||
|
||||
const ArcaneTheme({
|
||||
required this.themeMode,
|
||||
required super.child,
|
||||
super.key,
|
||||
});
|
||||
|
||||
static ArcaneTheme? of(BuildContext context) {
|
||||
return context.dependOnInheritedWidgetOfExactType<ArcaneTheme>();
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(ArcaneTheme oldWidget) {
|
||||
return themeMode != oldWidget.themeMode;
|
||||
}
|
||||
|
||||
static ArcaneReactiveTheme get service => ArcaneReactiveTheme.I;
|
||||
static bool get isFollowingSystemTheme => service.isFollowingSystemTheme;
|
||||
static Stream<ThemeMode> get themeChanges => service.themeChanges;
|
||||
static ThemeMode get currentTheme => service.currentTheme;
|
||||
static ThemeMode get systemTheme => service.systemTheme;
|
||||
static ThemeData get dark => service.dark;
|
||||
static ValueNotifier<ThemeData> get darkTheme => service.darkTheme;
|
||||
static ThemeData get light => service.light;
|
||||
static ValueNotifier<ThemeData> get lightTheme => service.lightTheme;
|
||||
|
||||
static ArcaneReactiveTheme Function({ThemeMode? themeMode}) get switchTheme =>
|
||||
service.switchTheme;
|
||||
static ArcaneReactiveTheme Function(BuildContext context)
|
||||
get followSystemTheme => service.followSystemTheme;
|
||||
static ArcaneReactiveTheme Function(ThemeData theme) get setDarkTheme =>
|
||||
service.setDarkTheme;
|
||||
static ArcaneReactiveTheme Function(ThemeData theme) get setLightTheme =>
|
||||
service.setLightTheme;
|
||||
}
|
||||
Reference in New Issue
Block a user