Added the ability to switch back to normal mode in the environment provider. Adjusted logic to prevent switching to a mode we're already in.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2024-09-17 12:31:47 +02:00
parent 1499fd588f
commit c5c41b9dba
2 changed files with 54 additions and 16 deletions
+9 -13
View File
@@ -11,22 +11,18 @@ class ArcaneEnvironment extends Cubit<Environment> {
ArcaneEnvironment() : super(Environment.normal);
/// Enables debug mode by setting the environment to `Environment.debug`.
///
/// If provided, [onDebugModeSet] is a callback that will be awaited before switching
/// to debug mode. This is useful for performing any setup required when enabling
/// demo mode.
///
/// Example:
/// ```dart
/// await environmentCubit.enableDebugMode(() async {
/// // Perform some setup when enabling demo mode.
/// });
/// ```
Future<void> enableDebugMode(Future<void> Function()? onDebugModeSet) async {
if (onDebugModeSet != null) await onDebugModeSet();
void enableDebugMode() {
if (state == Environment.debug) return;
emit(Environment.debug);
}
/// Disables debug mode by setting the environment to `Environment.normal`.
void disableDebugMode() {
if (state == Environment.normal) return;
emit(Environment.normal);
}
}
/// A widget that provides `ArcaneEnvironment` to the widget tree using `BlocProvider`.