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
|
// Add some persistent metadata to be used in every future log message
|
||||||
Arcane.logger.addPersistentMetadata({
|
Arcane.logger.addPersistentMetadata({
|
||||||
"demo": "This message will be included in all log messages.",
|
"demo": "Hello, World!",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register the authentication interface
|
// Register the authentication interface
|
||||||
@@ -383,30 +383,21 @@ class ArcaneThemeExample extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
key: Key(
|
|
||||||
"${colors[index]}-${Arcane.theme.currentThemeMode}"),
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: colors[index],
|
color: colors[index],
|
||||||
border: Arcane.theme.currentTheme.colorScheme
|
border: Theme.of(context)
|
||||||
.primary.name ==
|
.colorScheme
|
||||||
|
.primary
|
||||||
|
.name ==
|
||||||
colors[index].name
|
colors[index].name
|
||||||
? Border.all(
|
? Border.all(
|
||||||
width: 2,
|
width: 2,
|
||||||
color: Colors.white,
|
color: Theme.of(context).brightness ==
|
||||||
|
Brightness.dark
|
||||||
|
? Colors.white
|
||||||
|
: Colors.black,
|
||||||
)
|
)
|
||||||
: null,
|
: 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,
|
width: 20,
|
||||||
height: 20,
|
height: 20,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
/// `ArcaneFeatureFlags`.
|
/// `ArcaneFeatureFlags`.
|
||||||
/// - **Logging**: Flexible logging with different severity levels
|
/// - **Logging**: Flexible logging with different severity levels
|
||||||
/// (`debug`, `info`, `error`, etc.).
|
/// (`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**: Manage user login, sign up, and token-based
|
||||||
/// authentication.
|
/// 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/authentication/authentication_service.dart";
|
||||||
export "package:arcane_framework/src/services/feature_flags/feature_flags_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/logging/logging_service.dart";
|
||||||
export "package:arcane_framework/src/services/reactive_theme/reactive_theme_service.dart";
|
export "package:arcane_framework/src/services/theme/reactive_theme_switcher.dart";
|
||||||
export "package:arcane_framework/src/services/reactive_theme/reactive_theme_switcher.dart";
|
export "package:arcane_framework/src/services/theme/theme_service.dart";
|
||||||
export "package:result_monad/result_monad.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.
|
/// 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.
|
/// 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.
|
/// Returns a list of all services available in the Arcane framework.
|
||||||
///
|
///
|
||||||
|
|||||||
+7
-8
@@ -32,14 +32,14 @@ class _ArcaneThemeSwitcherState extends State<ArcaneThemeSwitcher>
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListenableBuilder(
|
return ListenableBuilder(
|
||||||
listenable: ArcaneReactiveTheme.I.themeChanges,
|
listenable: ArcaneTheme.I.themeChanges,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
return ValueListenableBuilder<ThemeData>(
|
return ValueListenableBuilder<ThemeData>(
|
||||||
valueListenable: ArcaneReactiveTheme.I.themeDataChanges,
|
valueListenable: ArcaneTheme.I.themeDataChanges,
|
||||||
builder: (BuildContext context, ThemeData themeData, Widget? child) {
|
builder: (BuildContext context, ThemeData themeData, Widget? child) {
|
||||||
return _ArcaneTheme(
|
return _ArcaneTheme(
|
||||||
themeMode: ArcaneReactiveTheme.I.currentThemeMode,
|
themeMode: ArcaneTheme.I.currentThemeMode,
|
||||||
followSystem: ArcaneReactiveTheme.I.isFollowingSystemTheme,
|
followSystem: ArcaneTheme.I.isFollowingSystemTheme,
|
||||||
theme: themeData,
|
theme: themeData,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
@@ -55,9 +55,9 @@ class _ArcaneThemeSwitcherState extends State<ArcaneThemeSwitcher>
|
|||||||
// and use it to check the system theme
|
// and use it to check the system theme
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
// Use the current context from the key to check system theme
|
// Use the current context from the key to check system theme
|
||||||
if (ArcaneReactiveTheme.I.isFollowingSystemTheme) {
|
if (ArcaneTheme.I.isFollowingSystemTheme) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
ArcaneReactiveTheme.I.followSystemTheme(context);
|
ArcaneTheme.I.followSystemTheme(context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,6 @@ class _ArcaneTheme extends InheritedWidget {
|
|||||||
extension ArcaneThemeContext on BuildContext {
|
extension ArcaneThemeContext on BuildContext {
|
||||||
/// Get the current theme mode from the nearest ArcaneThemeInherited widget
|
/// Get the current theme mode from the nearest ArcaneThemeInherited widget
|
||||||
ThemeMode get themeMode {
|
ThemeMode get themeMode {
|
||||||
return _ArcaneTheme.of(this)?.themeMode ??
|
return _ArcaneTheme.of(this)?.themeMode ?? ArcaneTheme.I.currentThemeMode;
|
||||||
ArcaneReactiveTheme.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.
|
/// 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/foundation.dart";
|
||||||
import "package:flutter/material.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.
|
/// 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
|
/// methods to customize the themes. The current theme mode can be accessed, and the
|
||||||
/// theme can be switched at runtime.
|
/// theme can be switched at runtime.
|
||||||
///
|
///
|
||||||
/// System theme changes are detected by the `ArcaneApp` widget, which ensures
|
/// System theme changes are detected by the `ArcaneApp` widget, which ensures
|
||||||
/// theme updates happen automatically when the device theme changes.
|
/// theme updates happen automatically when the device theme changes.
|
||||||
class ArcaneReactiveTheme extends ArcaneService {
|
class ArcaneTheme extends ArcaneService {
|
||||||
ArcaneReactiveTheme._internal();
|
ArcaneTheme._internal();
|
||||||
static final ArcaneReactiveTheme _instance = ArcaneReactiveTheme._internal();
|
static final ArcaneTheme _instance = ArcaneTheme._internal();
|
||||||
static ArcaneReactiveTheme get I => _instance;
|
static ArcaneTheme get I => _instance;
|
||||||
|
|
||||||
// ************************************************************************ //
|
// ************************************************************************ //
|
||||||
// * MARK: System theme
|
// * MARK: System theme
|
||||||
@@ -39,7 +39,7 @@ class ArcaneReactiveTheme extends ArcaneService {
|
|||||||
// ************************************************************************ //
|
// ************************************************************************ //
|
||||||
// * MARK: ThemeMode
|
// * 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.
|
/// Will automatically update when the theme changes.
|
||||||
ThemeMode currentModeOf(BuildContext context) => context.themeMode;
|
ThemeMode currentModeOf(BuildContext context) => context.themeMode;
|
||||||
|
|
||||||
@@ -119,13 +119,13 @@ class ArcaneReactiveTheme extends ArcaneService {
|
|||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// ArcaneReactiveTheme.I.switchTheme();
|
/// ArcaneTheme.I.switchTheme();
|
||||||
/// // or
|
/// // or
|
||||||
/// ArcaneReactiveTheme.I.switchTheme(themeMode: ThemeMode.dark);
|
/// ArcaneTheme.I.switchTheme(themeMode: ThemeMode.dark);
|
||||||
/// // or
|
/// // or
|
||||||
/// Arcane.theme.switchTheme(themeMode: ThemeMode.light);
|
/// Arcane.theme.switchTheme(themeMode: ThemeMode.light);
|
||||||
/// ```
|
/// ```
|
||||||
ArcaneReactiveTheme switchTheme({ThemeMode? themeMode}) {
|
ArcaneTheme switchTheme({ThemeMode? themeMode}) {
|
||||||
_followingSystemTheme = false;
|
_followingSystemTheme = false;
|
||||||
_followingSystemThemeNotifier.value = false;
|
_followingSystemThemeNotifier.value = false;
|
||||||
|
|
||||||
@@ -148,11 +148,11 @@ class ArcaneReactiveTheme extends ArcaneService {
|
|||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// ArcaneReactiveTheme.I.followSystemTheme(context);
|
/// ArcaneTheme.I.followSystemTheme(context);
|
||||||
/// // or
|
/// // or
|
||||||
/// Arcane.theme.followSystemTheme(context);
|
/// Arcane.theme.followSystemTheme(context);
|
||||||
/// ```
|
/// ```
|
||||||
ArcaneReactiveTheme followSystemTheme(BuildContext context) {
|
ArcaneTheme followSystemTheme(BuildContext context) {
|
||||||
_followingSystemTheme = true;
|
_followingSystemTheme = true;
|
||||||
_followingSystemThemeNotifier.value = true;
|
_followingSystemThemeNotifier.value = true;
|
||||||
|
|
||||||
@@ -171,9 +171,9 @@ class ArcaneReactiveTheme extends ArcaneService {
|
|||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// ArcaneReactiveTheme.I.setDarkTheme(customDarkTheme);
|
/// ArcaneTheme.I.setDarkTheme(customDarkTheme);
|
||||||
/// ```
|
/// ```
|
||||||
ArcaneReactiveTheme setDarkTheme(ThemeData theme) {
|
ArcaneTheme setDarkTheme(ThemeData theme) {
|
||||||
_darkTheme.value = theme;
|
_darkTheme.value = theme;
|
||||||
|
|
||||||
// Only update current theme if we're currently in dark mode
|
// Only update current theme if we're currently in dark mode
|
||||||
@@ -193,9 +193,9 @@ class ArcaneReactiveTheme extends ArcaneService {
|
|||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// ArcaneReactiveTheme.I.setLightTheme(customLightTheme);
|
/// ArcaneTheme.I.setLightTheme(customLightTheme);
|
||||||
/// ```
|
/// ```
|
||||||
ArcaneReactiveTheme setLightTheme(ThemeData theme) {
|
ArcaneTheme setLightTheme(ThemeData theme) {
|
||||||
_lightTheme.value = theme;
|
_lightTheme.value = theme;
|
||||||
|
|
||||||
// Only update current theme if we're currently in light mode
|
// Only update current theme if we're currently in light mode
|
||||||
@@ -8,7 +8,7 @@ void main() {
|
|||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
ArcaneFeatureFlags.I.reset();
|
ArcaneFeatureFlags.I.reset();
|
||||||
ArcaneAuthenticationService.I.reset();
|
ArcaneAuthenticationService.I.reset();
|
||||||
ArcaneReactiveTheme.I.reset();
|
ArcaneTheme.I.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
group("Arcane", () {
|
group("Arcane", () {
|
||||||
@@ -16,7 +16,7 @@ void main() {
|
|||||||
final services = Arcane.services;
|
final services = Arcane.services;
|
||||||
expect(services, contains(isA<ArcaneFeatureFlags>()));
|
expect(services, contains(isA<ArcaneFeatureFlags>()));
|
||||||
expect(services, contains(isA<ArcaneAuthenticationService>()));
|
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";
|
import "package:flutter_test/flutter_test.dart";
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group("ArcaneReactiveTheme", () {
|
group("ArcaneTheme", () {
|
||||||
late ArcaneReactiveTheme theme;
|
late ArcaneTheme theme;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
theme = ArcaneReactiveTheme.I;
|
theme = ArcaneTheme.I;
|
||||||
theme.reset();
|
theme.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("singleton instance is consistent", () {
|
test("singleton instance is consistent", () {
|
||||||
expect(identical(ArcaneReactiveTheme.I, theme), true);
|
expect(identical(ArcaneTheme.I, theme), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
group("theme mode", () {
|
group("theme mode", () {
|
||||||
|
|||||||
Reference in New Issue
Block a user