getSystemUiOverlayStyleForGradient method

SystemUiOverlayStyle getSystemUiOverlayStyleForGradient({
  1. required BuildContext context,
  2. required LinearGradient gradient,
})

Implementation

SystemUiOverlayStyle getSystemUiOverlayStyleForGradient({
  required BuildContext context,
  required LinearGradient gradient,
}) {
  final luminances = gradient.colors.map(
    (Color color) => color.computeLuminance(),
  );

  final averageLuminance =
      luminances.reduce((a, b) => a + b) / luminances.length;

  return averageLuminance > 0.5
      ? SystemUiOverlayStyle.dark
      : SystemUiOverlayStyle.light;
}