diff --git a/example/lib/main.dart b/example/lib/main.dart index f4340e1..a238090 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -19,7 +19,7 @@ Future main() async { // Add some persistent metadata to be used in every future log message Arcane.logger.addPersistentMetadata({ - "demo": "This message will be included in all log messages.", + "demo": "Hello, World!", }); // Register the authentication interface @@ -383,30 +383,21 @@ class ArcaneThemeExample extends StatelessWidget { ); }, child: Container( - key: Key( - "${colors[index]}-${Arcane.theme.currentThemeMode}"), decoration: BoxDecoration( color: colors[index], - border: Arcane.theme.currentTheme.colorScheme - .primary.name == + border: Theme.of(context) + .colorScheme + .primary + .name == colors[index].name ? Border.all( width: 2, - color: Colors.white, + color: Theme.of(context).brightness == + Brightness.dark + ? Colors.white + : Colors.black, ) : null, - boxShadow: Arcane.theme.currentTheme.colorScheme - .primary.name == - colors[index].name - ? [ - const BoxShadow( - color: Colors.black, - spreadRadius: 1, - blurRadius: 1, - offset: Offset(0, 0), - ), - ] - : null, ), width: 20, height: 20, diff --git a/lib/arcane_framework.dart b/lib/arcane_framework.dart index 6ca32ec..85eda55 100644 --- a/lib/arcane_framework.dart +++ b/lib/arcane_framework.dart @@ -14,7 +14,7 @@ /// `ArcaneFeatureFlags`. /// - **Logging**: Flexible logging with different severity levels /// (`debug`, `info`, `error`, etc.). -/// - **Theming**: Easy light/dark mode switching with `ArcaneReactiveTheme`. +/// - **Theming**: Easy light/dark mode switching with `ArcaneTheme`. /// - **Authentication**: Manage user login, sign up, and token-based /// authentication. /// @@ -44,6 +44,6 @@ export "package:arcane_framework/src/providers/service/arcane_service.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/reactive_theme_service.dart"; -export "package:arcane_framework/src/services/reactive_theme/reactive_theme_switcher.dart"; +export "package:arcane_framework/src/services/theme/reactive_theme_switcher.dart"; +export "package:arcane_framework/src/services/theme/theme_service.dart"; export "package:result_monad/result_monad.dart"; diff --git a/lib/src/arcane.dart b/lib/src/arcane.dart index 3ebe1a0..1ee4ca7 100644 --- a/lib/src/arcane.dart +++ b/lib/src/arcane.dart @@ -26,9 +26,9 @@ abstract class Arcane { /// Provides access to the singleton instance of the theme management service. /// - /// `ArcaneReactiveTheme` allows switching between light and dark themes and + /// `ArcaneTheme` allows switching between light and dark themes and /// customizing them. - static ArcaneReactiveTheme get theme => ArcaneReactiveTheme.I; + static ArcaneTheme get theme => ArcaneTheme.I; /// Returns a list of all services available in the Arcane framework. /// diff --git a/lib/src/services/reactive_theme/reactive_theme_switcher.dart b/lib/src/services/theme/reactive_theme_switcher.dart similarity index 83% rename from lib/src/services/reactive_theme/reactive_theme_switcher.dart rename to lib/src/services/theme/reactive_theme_switcher.dart index 00dc363..ef8f835 100644 --- a/lib/src/services/reactive_theme/reactive_theme_switcher.dart +++ b/lib/src/services/theme/reactive_theme_switcher.dart @@ -32,14 +32,14 @@ class _ArcaneThemeSwitcherState extends State @override Widget build(BuildContext context) { return ListenableBuilder( - listenable: ArcaneReactiveTheme.I.themeChanges, + listenable: ArcaneTheme.I.themeChanges, builder: (BuildContext context, Widget? child) { return ValueListenableBuilder( - valueListenable: ArcaneReactiveTheme.I.themeDataChanges, + valueListenable: ArcaneTheme.I.themeDataChanges, builder: (BuildContext context, ThemeData themeData, Widget? child) { return _ArcaneTheme( - themeMode: ArcaneReactiveTheme.I.currentThemeMode, - followSystem: ArcaneReactiveTheme.I.isFollowingSystemTheme, + themeMode: ArcaneTheme.I.currentThemeMode, + followSystem: ArcaneTheme.I.isFollowingSystemTheme, theme: themeData, child: widget.child, ); @@ -55,9 +55,9 @@ class _ArcaneThemeSwitcherState extends State // 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) { + if (ArcaneTheme.I.isFollowingSystemTheme) { WidgetsBinding.instance.addPostFrameCallback((_) { - ArcaneReactiveTheme.I.followSystemTheme(context); + ArcaneTheme.I.followSystemTheme(context); }); } } @@ -92,7 +92,6 @@ class _ArcaneTheme extends InheritedWidget { extension ArcaneThemeContext on BuildContext { /// Get the current theme mode from the nearest ArcaneThemeInherited widget ThemeMode get themeMode { - return _ArcaneTheme.of(this)?.themeMode ?? - ArcaneReactiveTheme.I.currentThemeMode; + return _ArcaneTheme.of(this)?.themeMode ?? ArcaneTheme.I.currentThemeMode; } } diff --git a/lib/src/services/reactive_theme/reactive_theme_extensions.dart b/lib/src/services/theme/theme_extensions.dart similarity index 94% rename from lib/src/services/reactive_theme/reactive_theme_extensions.dart rename to lib/src/services/theme/theme_extensions.dart index edb18f6..10065b8 100644 --- a/lib/src/services/reactive_theme/reactive_theme_extensions.dart +++ b/lib/src/services/theme/theme_extensions.dart @@ -1,4 +1,4 @@ -part of "reactive_theme_service.dart"; +part of "theme_service.dart"; /// An extension on `BuildContext` to check the current system dark mode setting. /// diff --git a/lib/src/services/reactive_theme/reactive_theme_service.dart b/lib/src/services/theme/theme_service.dart similarity index 90% rename from lib/src/services/reactive_theme/reactive_theme_service.dart rename to lib/src/services/theme/theme_service.dart index 3c75e36..a52218f 100644 --- a/lib/src/services/reactive_theme/reactive_theme_service.dart +++ b/lib/src/services/theme/theme_service.dart @@ -2,20 +2,20 @@ import "package:arcane_framework/arcane_framework.dart"; import "package:flutter/foundation.dart"; import "package:flutter/material.dart"; -part "reactive_theme_extensions.dart"; +part "theme_extensions.dart"; /// A singleton service that manages theme switching and customization for the application. /// -/// `ArcaneReactiveTheme` allows switching between light and dark themes and provides +/// `ArcaneTheme` allows switching between light and dark themes and provides /// methods to customize the themes. The current theme mode can be accessed, and the /// theme can be switched at runtime. /// /// System theme changes are detected by the `ArcaneApp` widget, which ensures /// theme updates happen automatically when the device theme changes. -class ArcaneReactiveTheme extends ArcaneService { - ArcaneReactiveTheme._internal(); - static final ArcaneReactiveTheme _instance = ArcaneReactiveTheme._internal(); - static ArcaneReactiveTheme get I => _instance; +class ArcaneTheme extends ArcaneService { + ArcaneTheme._internal(); + static final ArcaneTheme _instance = ArcaneTheme._internal(); + static ArcaneTheme get I => _instance; // ************************************************************************ // // * MARK: System theme @@ -39,7 +39,7 @@ class ArcaneReactiveTheme extends ArcaneService { // ************************************************************************ // // * MARK: ThemeMode // ************************************************************************ // - /// Returns the current `ThemeMode` being used by `ArcaneReactiveTheme`. + /// Returns the current `ThemeMode` being used by `ArcaneTheme`. /// Will automatically update when the theme changes. ThemeMode currentModeOf(BuildContext context) => context.themeMode; @@ -119,13 +119,13 @@ class ArcaneReactiveTheme extends ArcaneService { /// /// Example: /// ```dart - /// ArcaneReactiveTheme.I.switchTheme(); + /// ArcaneTheme.I.switchTheme(); /// // or - /// ArcaneReactiveTheme.I.switchTheme(themeMode: ThemeMode.dark); + /// ArcaneTheme.I.switchTheme(themeMode: ThemeMode.dark); /// // or /// Arcane.theme.switchTheme(themeMode: ThemeMode.light); /// ``` - ArcaneReactiveTheme switchTheme({ThemeMode? themeMode}) { + ArcaneTheme switchTheme({ThemeMode? themeMode}) { _followingSystemTheme = false; _followingSystemThemeNotifier.value = false; @@ -148,11 +148,11 @@ class ArcaneReactiveTheme extends ArcaneService { /// /// Example: /// ```dart - /// ArcaneReactiveTheme.I.followSystemTheme(context); + /// ArcaneTheme.I.followSystemTheme(context); /// // or /// Arcane.theme.followSystemTheme(context); /// ``` - ArcaneReactiveTheme followSystemTheme(BuildContext context) { + ArcaneTheme followSystemTheme(BuildContext context) { _followingSystemTheme = true; _followingSystemThemeNotifier.value = true; @@ -171,9 +171,9 @@ class ArcaneReactiveTheme extends ArcaneService { /// /// Example: /// ```dart - /// ArcaneReactiveTheme.I.setDarkTheme(customDarkTheme); + /// ArcaneTheme.I.setDarkTheme(customDarkTheme); /// ``` - ArcaneReactiveTheme setDarkTheme(ThemeData theme) { + ArcaneTheme setDarkTheme(ThemeData theme) { _darkTheme.value = theme; // Only update current theme if we're currently in dark mode @@ -193,9 +193,9 @@ class ArcaneReactiveTheme extends ArcaneService { /// /// Example: /// ```dart - /// ArcaneReactiveTheme.I.setLightTheme(customLightTheme); + /// ArcaneTheme.I.setLightTheme(customLightTheme); /// ``` - ArcaneReactiveTheme setLightTheme(ThemeData theme) { + ArcaneTheme setLightTheme(ThemeData theme) { _lightTheme.value = theme; // Only update current theme if we're currently in light mode diff --git a/test/arcane_test.dart b/test/arcane_test.dart index a1c30ac..e52557c 100644 --- a/test/arcane_test.dart +++ b/test/arcane_test.dart @@ -8,7 +8,7 @@ void main() { setUpAll(() { ArcaneFeatureFlags.I.reset(); ArcaneAuthenticationService.I.reset(); - ArcaneReactiveTheme.I.reset(); + ArcaneTheme.I.reset(); }); group("Arcane", () { @@ -16,7 +16,7 @@ void main() { final services = Arcane.services; expect(services, contains(isA())); expect(services, contains(isA())); - expect(services, contains(isA())); + expect(services, contains(isA())); }); }); } diff --git a/test/services/reactive_theme/reactive_theme_service_test.dart b/test/services/reactive_theme/reactive_theme_service_test.dart index cae7cec..79d0d28 100644 --- a/test/services/reactive_theme/reactive_theme_service_test.dart +++ b/test/services/reactive_theme/reactive_theme_service_test.dart @@ -3,11 +3,11 @@ import "package:flutter/material.dart"; import "package:flutter_test/flutter_test.dart"; void main() { - group("ArcaneReactiveTheme", () { - late ArcaneReactiveTheme theme; + group("ArcaneTheme", () { + late ArcaneTheme theme; setUp(() { - theme = ArcaneReactiveTheme.I; + theme = ArcaneTheme.I; theme.reset(); }); @@ -16,7 +16,7 @@ void main() { }); test("singleton instance is consistent", () { - expect(identical(ArcaneReactiveTheme.I, theme), true); + expect(identical(ArcaneTheme.I, theme), true); }); group("theme mode", () {