|
1 | | -import 'package:flutter/foundation.dart'; |
2 | | -import 'package:flutter/material.dart'; |
3 | | - |
4 | | -/// A singleton utility class that provides commonly used constants and configurations. |
5 | | -/// |
6 | | -/// This class ensures a single instance throughout the application lifecycle. |
7 | | -/// It includes logging configurations, UI-related properties, and utility values. |
8 | | -class FlutterExKit { |
9 | | - /// Private static variable holding the single instance of [FlutterExKit]. |
10 | | - static final FlutterExKit _instance = FlutterExKit._internal(); |
11 | | - |
12 | | - /// Private constructor to prevent external instantiation. |
13 | | - FlutterExKit._internal(); |
14 | | - |
15 | | - /// Factory constructor that returns the single instance of [FlutterExKit]. |
16 | | - factory FlutterExKit() { |
17 | | - return _instance; |
| 1 | +part of 'flutter_ex_kit.dart'; |
| 2 | +/// Defines the theme configuration and global settings. |
| 3 | +class ExKitTheme { |
| 4 | + static final ExKitTheme _instance = ExKitTheme._internal(); // ✅ Instance initialized immediately |
| 5 | + |
| 6 | + /// A prefix emoji string used in logs or debug outputs. |
| 7 | + final String logStartEmoji; |
| 8 | + |
| 9 | + /// A suffix emoji string used in logs or debug outputs. |
| 10 | + final String logEndEmoji; |
| 11 | + |
| 12 | + /// A font-family string used in logs or debug outputs. |
| 13 | + final String fontFamily; |
| 14 | + |
| 15 | + /// Enables or disables logging globally. |
| 16 | + final bool logEnable; |
| 17 | + |
| 18 | + /// The default text color used throughout the application. |
| 19 | + final Color textColor; |
| 20 | + |
| 21 | + /// The default color for loading images. |
| 22 | + final Color loadingImageColor; |
| 23 | + |
| 24 | + /// Private constructor for singleton implementation. |
| 25 | + ExKitTheme._internal({ |
| 26 | + this.logStartEmoji = '🔥🔥🔥🔥🔥', |
| 27 | + this.logEndEmoji = '🔥🔥🔥🔥🔥', |
| 28 | + this.fontFamily = 'Euclid_Circular', |
| 29 | + this.textColor = Colors.black, |
| 30 | + this.loadingImageColor = Colors.black, |
| 31 | + this.logEnable = true, |
| 32 | + }); |
| 33 | + |
| 34 | + /// Factory constructor to return the singleton instance. |
| 35 | + factory ExKitTheme() => _instance; |
| 36 | + |
| 37 | + /// Returns a **new modified instance** of `ExKitTheme` without breaking immutability. |
| 38 | + ExKitTheme copyWith({ |
| 39 | + String? logStartEmoji, |
| 40 | + String? logEndEmoji, |
| 41 | + String? fontFamily, |
| 42 | + Color? textColor, |
| 43 | + Color? loadingImageColor, |
| 44 | + bool? logEnable, |
| 45 | + }) { |
| 46 | + return ExKitTheme._internal( |
| 47 | + logStartEmoji: logStartEmoji ?? this.logStartEmoji, |
| 48 | + logEndEmoji: logEndEmoji ?? this.logEndEmoji, |
| 49 | + textColor: textColor ?? this.textColor, |
| 50 | + fontFamily: fontFamily ?? this.fontFamily, |
| 51 | + loadingImageColor: loadingImageColor ?? this.loadingImageColor, |
| 52 | + logEnable: logEnable ?? this.logEnable, |
| 53 | + ); |
18 | 54 | } |
| 55 | +} |
| 56 | + |
| 57 | +/// Singleton class to manage global theme |
| 58 | +class ExKitThemeManager { |
| 59 | + static final ExKitThemeManager _instance = ExKitThemeManager._internal(); |
| 60 | + |
| 61 | + /// Notifier to update the theme across the app |
| 62 | + final ValueNotifier<ExKitTheme> themeNotifier = ValueNotifier(ExKitTheme()); |
| 63 | + |
| 64 | + /// Private constructor |
| 65 | + ExKitThemeManager._internal(); |
19 | 66 |
|
20 | | - /// A log emoji used for debugging messages. |
21 | | - /// |
22 | | - /// Example usage: |
23 | | - /// ```dart |
24 | | - /// print('${FlutterExKit().logEmoji} Debug message'); |
25 | | - /// ``` |
26 | | - String get logEmoji => '💢💢💢💢💢💢'; |
27 | | - |
28 | | - /// A secondary log emoji used for emphasizing logs. |
29 | | - /// |
30 | | - /// Example usage: |
31 | | - /// ```dart |
32 | | - /// print('${FlutterExKit().logEmojiDown} Error message'); |
33 | | - /// ``` |
34 | | - String get logEmojiDown => '💯💯💯💯💯💯'; |
35 | | - |
36 | | - /// Determines whether logging is enabled. |
37 | | - /// |
38 | | - /// Logs are enabled only in debug mode (`kDebugMode`). |
39 | | - bool get logEnable => kDebugMode; |
40 | | - |
41 | | - /// The default color used for image loaders. |
42 | | - /// |
43 | | - /// The color is set to black (`0xff000000`). |
44 | | - Color get imageLoader => const Color(0xff000000); |
| 67 | + /// Factory constructor to get the singleton instance |
| 68 | + factory ExKitThemeManager() => _instance; |
| 69 | + |
| 70 | + /// Update theme globally |
| 71 | + void updateTheme(ExKitTheme newTheme) { |
| 72 | + themeNotifier.value = newTheme; |
| 73 | + } |
45 | 74 | } |
| 75 | + |
| 76 | +/// Update theme globally |
| 77 | +final exKit = ExKitThemeManager(); |
| 78 | + |
| 79 | +/// ✅ Always use exKit.themeNotifier.value instead of a fixed copy |
| 80 | +ExKitTheme get exKitTheme => exKit.themeNotifier.value; |
0 commit comments