24 lines
685 B
Dart
24 lines
685 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// App-wide theme mode. `main.dart` listens to this and rebuilds MaterialApp;
|
|
/// any screen can set it. Persisting the choice is the ViewModel's job — this
|
|
/// only carries the live value.
|
|
class ThemeController {
|
|
ThemeController._();
|
|
|
|
static final ValueNotifier<ThemeMode> mode = ValueNotifier<ThemeMode>(
|
|
ThemeMode.dark,
|
|
);
|
|
|
|
/// The stored string ('dark' | 'light' | 'system') for the current mode.
|
|
static String get name => mode.value.name;
|
|
|
|
static void apply(String stored) {
|
|
mode.value = switch (stored) {
|
|
'light' => ThemeMode.light,
|
|
'system' => ThemeMode.system,
|
|
_ => ThemeMode.dark,
|
|
};
|
|
}
|
|
}
|