mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 02:19:08 +02:00
Rename ArcaneReactiveTheme to ArcaneTheme
This commit is contained in:
+9
-18
@@ -19,7 +19,7 @@ Future<void> 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,
|
||||
|
||||
@@ -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";
|
||||
|
||||
+2
-2
@@ -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.
|
||||
///
|
||||
|
||||
+7
-8
@@ -32,14 +32,14 @@ class _ArcaneThemeSwitcherState extends State<ArcaneThemeSwitcher>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListenableBuilder(
|
||||
listenable: ArcaneReactiveTheme.I.themeChanges,
|
||||
listenable: ArcaneTheme.I.themeChanges,
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return ValueListenableBuilder<ThemeData>(
|
||||
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<ArcaneThemeSwitcher>
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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.
|
||||
///
|
||||
+16
-16
@@ -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
|
||||
@@ -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<ArcaneFeatureFlags>()));
|
||||
expect(services, contains(isA<ArcaneAuthenticationService>()));
|
||||
expect(services, contains(isA<ArcaneReactiveTheme>()));
|
||||
expect(services, contains(isA<ArcaneTheme>()));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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", () {
|
||||
|
||||
Reference in New Issue
Block a user