dark_theme_util.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../my_load_image.dart';
  4. import 'package:cs_resources/constants/color_constants.dart';
  5. //设置颜色兼容黑色模式
  6. class DarkThemeUtil {
  7. /// 默认黑暗模式下的颜色为[ColorConstants.darkScaffoldBackgroundColor].
  8. /// 如果想自定义黑暗模式下的颜色
  9. static Color? multiColors(Color? lightColor, {Color? darkColor}) {
  10. Color? color;
  11. if (Get.isDarkMode) {
  12. color = darkColor ?? ColorConstants.darkScaffoldBackgroundColor;
  13. } else {
  14. color = lightColor;
  15. }
  16. return color;
  17. }
  18. /// 默认黑暗模式下的颜色不变.
  19. /// 如果想自定义黑暗模式下的图标颜色填充颜色就行
  20. static MyAssetImage multiImageColorFit(String imgPath, {double? width, double? height, Color? darkColor, BoxFit? fit}) {
  21. return MyAssetImage(imgPath, width: width, height: height, color: Get.isDarkMode ? darkColor : null, fit: fit);
  22. }
  23. /// 默认黑暗模式下的图片资源不变
  24. /// 如果想自定义黑暗模式下的图片资源,可以直接替换图片
  25. static MyAssetImage multiImagePath(String imgPath, {double? width, double? height, String? darkImagePath}) {
  26. return MyAssetImage(
  27. Get.isDarkMode && darkImagePath != null ? darkImagePath : imgPath,
  28. width: width,
  29. height: height,
  30. );
  31. }
  32. }