dark_theme_util.dart 1.4 KB

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