Skip to content

Instantly share code, notes, and snippets.

@gppam
Created November 25, 2025 11:56
Show Gist options
  • Select an option

  • Save gppam/fd1f00b5e2f052627c58bc573314f70a to your computer and use it in GitHub Desktop.

Select an option

Save gppam/fd1f00b5e2f052627c58bc573314f70a to your computer and use it in GitHub Desktop.
Give specific background color to button style to ElevatedButton with dynamic text color based on background color
ButtonStyle style(Color color) {
Color textColor = Colors.black;
if (color.computeLuminance() < 0.5) {
Colors.white;
} else {
Colors.black;
}
return ElevatedButton.styleFrom(disabledBackgroundColor: Colors.grey, disabledForegroundColor: Colors.white70, backgroundColor: color, foregroundColor: textColor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment