VThemeController class
============================================================ VThemeController — 主题切换控制器(库级别,通用)
放在 v_components 库里,所有项目都能用,零业务依赖。
技术选型:
- 用 Flutter 自带的 ChangeNotifier,零外部依赖
- 不绑定 Riverpod / GetX / Provider(那些是项目自己的选择)
- 持久化用 v_base_framework 的 SharedPreferencesBaseUtils
支持:
- light / dark / system 三种模式
- 任意多套自定义主题(橙、绿、紫...)
-
自动持久化用户选择,App 重启恢复
主题切换控制器
使用方式:
- App 启动时调用 VThemeController.instance.init()
- 在 MaterialApp 外层用 ListenableBuilder 监听变化
- 用户切换时调用 setMode() 或 setCustomTheme()
- Inheritance
-
- Object
- ChangeNotifier
- VThemeController
Properties
- customTheme → String?
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- themeMode → ThemeMode
-
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
dispose(
) → void -
Discards any resources used by the object.
inherited
-
init(
) → Future< void> - 从本地存储恢复用户上次的选择 必须在 SharedPreferencesBaseUtils.getInstance() 完成后调用
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
reset(
) → Future< void> - 重置到默认(系统跟随 + 无自定义主题)
-
setCustomTheme(
String themeKey) → Future< void> -
切换到自定义主题(比如橙色、绿色)
themeKey由项目自己定义,比如 'orange'、'green' -
setMode(
ThemeMode mode) → Future< void> - 切换主题模式(light / dark / system) 切换后自动持久化
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → VThemeController
-
单例
final