appBarContrastColor function

Color appBarContrastColor(
  1. BuildContext context
)

计算反差色

Implementation

Color appBarContrastColor(BuildContext context) {
  final appBarColor = Theme.of(context).appBarTheme.backgroundColor;

// 计算导航栏颜色的亮度
  final appBarBrightness = appBarColor!.computeLuminance() > 0.5
      ? Brightness.light
      : Brightness.dark;

  return appBarBrightness == Brightness.light ? Colors.black : Colors.white;
}