theme_model.dart 560 B

1234567891011121314151617181920
  1. import 'package:flutter/material.dart';
  2. import 'profile.dart';
  3. import '../common/global.dart';
  4. class ThemeModel extends ProfileChangeNotifier {
  5. // 获取当前主题,如果为设置主题,则默认使用蓝色主题
  6. MaterialColor get theme => Global.themes
  7. .firstWhere((e) => e.value == profile.theme, orElse: () => Colors.blue);
  8. // 主题改变后,通知其依赖项,新主题会立即生效
  9. set theme(MaterialColor color) {
  10. if (color != theme) {
  11. profile.theme = color.shade500.value;
  12. notifyListeners();
  13. }
  14. }
  15. }