|
1 | 1 | part of 'app_bloc.dart';
|
2 | 2 |
|
3 |
| -/// Represents the application's authentication status. |
4 |
| -enum AppStatus { |
5 |
| - /// The application is initializing and the status is unknown. |
6 |
| - initial, |
| 3 | +/// Defines the various statuses of the application's overall state. |
| 4 | +/// |
| 5 | +/// This enum helps manage the application's flow, especially during startup |
| 6 | +/// and critical operations like fetching remote configuration or handling |
| 7 | +/// authentication changes. |
| 8 | +enum AppLifeCycleStatus { |
| 9 | + /// The application is in the initial phase of bootstrapping, |
| 10 | + /// fetching remote configuration and user settings. |
| 11 | + initializing, |
| 12 | + |
| 13 | + /// The user is not authenticated. |
| 14 | + unauthenticated, |
7 | 15 |
|
8 |
| - /// The user is authenticated. |
| 16 | + /// The user is authenticated (e.g., standard user). |
9 | 17 | authenticated,
|
10 | 18 |
|
11 |
| - /// The user is unauthenticated. |
12 |
| - unauthenticated, |
13 |
| - |
14 |
| - /// The user is anonymous (signed in using an anonymous provider). |
| 19 | + /// The user is anonymous (e.g., guest user). |
15 | 20 | anonymous,
|
16 | 21 |
|
17 |
| - /// Fetching the essential RemoteConfig. |
| 22 | + /// The application is currently fetching remote configuration. |
| 23 | + /// This status is used for re-fetching or background checks, not initial load. |
18 | 24 | configFetching,
|
19 | 25 |
|
20 |
| - /// Fetching the essential RemoteConfig failed. |
| 26 | + /// The application failed to fetch remote configuration. |
21 | 27 | configFetchFailed,
|
22 | 28 |
|
23 |
| - /// A new version of the app is required. |
24 |
| - updateRequired, |
25 |
| - |
26 |
| - /// The app is currently under maintenance. |
| 29 | + /// The application is currently under maintenance. |
27 | 30 | underMaintenance,
|
| 31 | + |
| 32 | + /// A mandatory update is required for the application. |
| 33 | + updateRequired, |
28 | 34 | }
|
29 | 35 |
|
| 36 | +/// {@template app_state} |
| 37 | +/// Represents the overall state of the application. |
| 38 | +/// |
| 39 | +/// This state includes authentication status, user settings, remote |
| 40 | +/// configuration, and UI-related preferences. |
| 41 | +/// {@endtemplate} |
30 | 42 | class AppState extends Equatable {
|
31 | 43 | /// {@macro app_state}
|
32 | 44 | const AppState({
|
| 45 | + required this.status, |
33 | 46 | required this.settings,
|
34 |
| - required this.selectedBottomNavigationIndex, |
35 |
| - this.themeMode = ThemeMode.system, |
36 |
| - this.appTextScaleFactor = AppTextScaleFactor.medium, |
37 |
| - this.flexScheme = FlexScheme.material, |
38 |
| - this.fontFamily, |
39 |
| - this.status = AppStatus.initial, // Changed from AppStatus |
| 47 | + required this.environment, |
40 | 48 | this.user,
|
41 |
| - this.locale = const Locale('en'), // Default to English |
42 | 49 | this.remoteConfig,
|
43 |
| - this.environment, |
| 50 | + this.themeMode = ThemeMode.system, |
| 51 | + this.flexScheme = FlexScheme.blue, |
| 52 | + this.fontFamily, |
| 53 | + this.appTextScaleFactor = AppTextScaleFactor.medium, |
| 54 | + this.selectedBottomNavigationIndex = 0, |
| 55 | + this.locale, |
44 | 56 | });
|
45 | 57 |
|
46 |
| - /// The index of the currently selected item in the bottom navigation bar. |
47 |
| - final int selectedBottomNavigationIndex; |
| 58 | + /// The current status of the application. |
| 59 | + final AppLifeCycleStatus status; |
48 | 60 |
|
49 |
| - /// The overall theme mode (light, dark, system). |
50 |
| - final ThemeMode themeMode; |
| 61 | + /// The currently authenticated or anonymous user. |
| 62 | + final User? user; |
51 | 63 |
|
52 |
| - /// The text scale factor for the app's UI. |
53 |
| - final AppTextScaleFactor appTextScaleFactor; |
| 64 | + /// The user's application settings, including display preferences. |
| 65 | + final UserAppSettings settings; |
54 | 66 |
|
55 |
| - /// The active color scheme defined by FlexColorScheme. |
| 67 | + /// The remote configuration fetched from the backend. |
| 68 | + final RemoteConfig? remoteConfig; |
| 69 | + |
| 70 | + /// The current theme mode (light, dark, or system). |
| 71 | + final ThemeMode themeMode; |
| 72 | + |
| 73 | + /// The current FlexColorScheme scheme for accent colors. |
56 | 74 | final FlexScheme flexScheme;
|
57 | 75 |
|
58 |
| - /// The active font family name (e.g., from Google Fonts). |
59 |
| - /// Null uses the default font family defined in the FlexColorScheme theme. |
| 76 | + /// The currently selected font family. |
60 | 77 | final String? fontFamily;
|
61 | 78 |
|
62 |
| - /// The current authentication status of the application. |
63 |
| - final AppStatus status; |
64 |
| - |
65 |
| - /// The current user details. Null if unauthenticated. |
66 |
| - final User? user; |
| 79 | + /// The current text scale factor. |
| 80 | + final AppTextScaleFactor appTextScaleFactor; |
67 | 81 |
|
68 |
| - /// User-specific application settings. |
69 |
| - final UserAppSettings settings; |
| 82 | + /// The currently selected index for bottom navigation. |
| 83 | + final int selectedBottomNavigationIndex; |
70 | 84 |
|
71 |
| - /// The current application locale. |
72 |
| - final Locale locale; |
| 85 | + /// The current application environment. |
| 86 | + final local_config.AppEnvironment environment; |
73 | 87 |
|
74 |
| - /// The global application configuration (remote config). |
75 |
| - final RemoteConfig? remoteConfig; |
| 88 | + /// The currently selected locale for localization. |
| 89 | + final Locale? locale; |
76 | 90 |
|
77 |
| - /// The current application environment (e.g., production, development, demo). |
78 |
| - final local_config.AppEnvironment? environment; |
| 91 | + @override |
| 92 | + List<Object?> get props => [ |
| 93 | + status, |
| 94 | + user, |
| 95 | + settings, |
| 96 | + remoteConfig, |
| 97 | + themeMode, |
| 98 | + flexScheme, |
| 99 | + fontFamily, |
| 100 | + appTextScaleFactor, |
| 101 | + selectedBottomNavigationIndex, |
| 102 | + environment, |
| 103 | + locale, |
| 104 | + ]; |
79 | 105 |
|
80 |
| - /// Creates a copy of the current state with updated values. |
| 106 | + /// Creates a copy of this [AppState] with the given fields replaced with |
| 107 | + /// the new values. |
81 | 108 | AppState copyWith({
|
82 |
| - int? selectedBottomNavigationIndex, |
| 109 | + AppLifeCycleStatus? status, |
| 110 | + User? user, |
| 111 | + UserAppSettings? settings, |
| 112 | + RemoteConfig? remoteConfig, |
| 113 | + bool clearAppConfig = false, |
83 | 114 | ThemeMode? themeMode,
|
84 | 115 | FlexScheme? flexScheme,
|
85 | 116 | String? fontFamily,
|
86 | 117 | AppTextScaleFactor? appTextScaleFactor,
|
87 |
| - AppStatus? status, // Changed from AppStatus |
88 |
| - User? user, |
89 |
| - UserAppSettings? settings, |
90 |
| - Locale? locale, |
91 |
| - RemoteConfig? remoteConfig, |
| 118 | + int? selectedBottomNavigationIndex, |
92 | 119 | local_config.AppEnvironment? environment,
|
93 |
| - bool clearFontFamily = false, |
94 |
| - bool clearAppConfig = false, |
95 |
| - bool clearEnvironment = false, |
| 120 | + Locale? locale, |
96 | 121 | }) {
|
97 | 122 | return AppState(
|
98 |
| - selectedBottomNavigationIndex: |
99 |
| - selectedBottomNavigationIndex ?? this.selectedBottomNavigationIndex, |
100 |
| - themeMode: themeMode ?? this.themeMode, |
101 |
| - flexScheme: flexScheme ?? this.flexScheme, |
102 |
| - fontFamily: clearFontFamily ? null : fontFamily ?? this.fontFamily, |
103 |
| - appTextScaleFactor: appTextScaleFactor ?? this.appTextScaleFactor, |
104 | 123 | status: status ?? this.status,
|
105 | 124 | user: user ?? this.user,
|
106 | 125 | settings: settings ?? this.settings,
|
107 |
| - locale: locale ?? this.locale, |
108 | 126 | remoteConfig: clearAppConfig ? null : remoteConfig ?? this.remoteConfig,
|
109 |
| - environment: clearEnvironment ? null : environment ?? this.environment, |
| 127 | + themeMode: themeMode ?? this.themeMode, |
| 128 | + flexScheme: flexScheme ?? this.flexScheme, |
| 129 | + fontFamily: fontFamily ?? this.fontFamily, |
| 130 | + appTextScaleFactor: appTextScaleFactor ?? this.appTextScaleFactor, |
| 131 | + selectedBottomNavigationIndex: |
| 132 | + selectedBottomNavigationIndex ?? this.selectedBottomNavigationIndex, |
| 133 | + environment: environment ?? this.environment, |
| 134 | + locale: locale ?? this.locale, |
110 | 135 | );
|
111 | 136 | }
|
112 |
| - |
113 |
| - @override |
114 |
| - List<Object?> get props => [ |
115 |
| - selectedBottomNavigationIndex, |
116 |
| - themeMode, |
117 |
| - flexScheme, |
118 |
| - fontFamily, |
119 |
| - appTextScaleFactor, |
120 |
| - status, |
121 |
| - user, |
122 |
| - settings, |
123 |
| - locale, |
124 |
| - remoteConfig, |
125 |
| - environment, |
126 |
| - ]; |
127 | 137 | }
|
0 commit comments