import 'package:flutter/material.dart'; import '../my_load_image.dart'; import 'package:cs_resources/constants/color_constants.dart'; //设置颜色兼容黑色模式 class DarkThemeUtil { /// 默认黑暗模式下的颜色为[ColorConstants.darkScaffoldBackgroundColor]. /// 如果想自定义黑暗模式下的颜色 static Color? multiColors(BuildContext context, Color? lightColor, {Color? darkColor}) { Color? color; if (MediaQuery.of(context).platformBrightness == Brightness.dark) { color = darkColor ?? ColorConstants.darkScaffoldBackgroundColor; } else { color = lightColor; } return color; } /// 默认黑暗模式下的颜色不变. /// 如果想自定义黑暗模式下的图标颜色填充颜色就行 static MyAssetImage multiImageColorFit(BuildContext context, String imgPath, {double? width, double? height, Color? darkColor, BoxFit? fit}) { return MyAssetImage( imgPath, width: width, height: height, color: MediaQuery.of(context).platformBrightness == Brightness.dark ? darkColor : null, fit: fit, ); } /// 默认黑暗模式下的图片资源不变 /// 如果想自定义黑暗模式下的图片资源,可以直接替换图片 static MyAssetImage multiImagePath(BuildContext context, String imgPath, {double? width, double? height, String? darkImagePath}) { return MyAssetImage( MediaQuery.of(context).platformBrightness == Brightness.dark && darkImagePath != null ? darkImagePath : imgPath, width: width, height: height, ); } }