ensureReadableTextOn static method
Returns either preferredText or a high-contrast black/white fallback for
drawing text over fill.
Implementation
static Color ensureReadableTextOn(Color preferredText, Color fill) {
if (contrastRatio(preferredText, fill) >= 3.0) return preferredText;
return contrastRatio(Colors.white, fill) >=
contrastRatio(Colors.black, fill)
? Colors.white
: Colors.black;
}