theme.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * @Author: XianKaiQun
  3. * @Date: 2020-09-08 11:18:16
  4. * @LastEditors: XianKaiQun
  5. * @LastEditTime: 2020-09-08 16:13:03
  6. * @Description:
  7. */
  8. import 'package:flutter/widgets.dart';
  9. import 'package:wisdom_cli/wisdom_ui.dart';
  10. ///主题
  11. class WTheme extends InheritedTheme {
  12. final WThemeData? data;
  13. final Widget child;
  14. WTheme({Key? key, this.data, required this.child}) : super(key: key, child: child);
  15. static WThemeData of(BuildContext context) {
  16. final WThemeData themeData =
  17. _getInheritedWThemeData(context).resolve(context);
  18. return themeData;
  19. }
  20. @override
  21. bool updateShouldNotify(WTheme oldWidget) {
  22. return oldWidget.data != data;
  23. }
  24. @override
  25. Widget wrap(BuildContext context, Widget child) {
  26. final WTheme? theme = context.findAncestorWidgetOfExactType<WTheme>();
  27. return identical(this, theme) ? child : WTheme(data: data, child: child);
  28. }
  29. static WThemeData _getInheritedWThemeData(BuildContext context) {
  30. final WTheme? theme = context.dependOnInheritedWidgetOfExactType<WTheme>();
  31. return theme?.data ?? WThemeData.fallback();
  32. }
  33. }