foregroundColorFor function

Color foregroundColorFor(
  1. Color background, {
  2. required BuildContext context,
})

Returns an appropriate foreground color for the given background color.

The color should have enough contrast to be visible on the background.

Return colors will be based on the inverse surface colors in the surrounding color scheme

Implementation

Color foregroundColorFor(Color background, {required BuildContext context}) {
  final brightness = ThemeData.estimateBrightnessForColor(background);
  return context.theme.brightness == brightness
      ? context.colorScheme.inverseSurface
      : context.colorScheme.onInverseSurface;
}