contrast_gate library

The contrast floors the kit holds, as a function every app's test can call with its own themes (F6). ui_core's contrast_gate_test.dart runs it over PortalThemeCatalog; each app runs it over the scheme it hand-writes, so a hand-tuned value cannot drift under the floor again.

Pure Dart on purpose — no flutter_test — so it can live in lib/ beside kit_export.dart. The caller does the asserting:

test('finance schemes clear the contrast floors', () {
  final failures = portalContrastFailures(
    app: 'finance', light: AppTheme.light(), dark: AppTheme.dark(),
  );
  expect(failures, isEmpty, reason: describeContrastFailures(failures));
});

Classes

ContrastFailure
One pair that reads under its floor. Fix it in the palette it came from — never by lowering the floor here.

Constants

kPortalNonTextContrast → const double
An icon, outline, focus ring or control border reads at 3:1 against the surface behind it (WCAG 1.4.11).
kPortalTextContrast → const double
Text reads at 4.5:1 (WCAG AA for body sizes).
portalWellContrast → const double
How far a selection capsule must stand off the pill it sits on. The capsule is reinforcement, not a slab, so it only needs to clear this — not full text contrast.

Functions

categoryColors(BuildContext context, Color c) → (Color, Color)
(fill, glyph) for a category colour c: c tinted over the surface, and a glyph from c toward onSurface in tenths until it holds _glyphContrast (non-text contrast) on that tint.
describeContrastFailures(List<ContrastFailure> failures) → String
A reason string for expect(failures, isEmpty, reason: …).
neutralFill(BuildContext context) → Color
A neutral fill (secondary button, neutral badge, neutral prompt): the high tone, or the card's where the surface under it is already high — a grouped light page draws neutral fills on portal.card.
portalContrastFailures({required String app, required ThemeData light, required ThemeData dark}) → List<ContrastFailure>
portalThemeContrastFailures over an app's light and dark themes.
portalContrastRatio(Color fg, Color bg) → double
WCAG 2.x contrast ratio between two opaque colours.
portalNotDone(Color pending, Color done, Color accent, Color plain) → Color
A fill for a state that is not done, guaranteed not to be read as done. done is the hue to steer away from; accent stands in when pending is too alike, and plain (a neutral fill) when accent is too.
portalReadable(Color fg, Color bg, Color toward) → Color
fg kept readable on bg: drawn as is when it already clears AA text (kPortalTextContrast), else stepped toward toward (the page ink) until it does. A brand primary that is fine on a button (3.9:1 on a grey page) is too light for a text-only action.
portalThemeContrastFailures(ThemeData theme, {required String scheme}) → List<ContrastFailure>
Every pair in theme that reads under its floor, named scheme in the messages. Pairs whose extension is absent are skipped, not failed.
portalTooAlike(Color a, Color b) → bool
True when two fills would be taken for each other at badge size: the same hue family, near enough in tone. Hue is what carries the meaning here, so it is the hue that is compared.
portalWellOn(Color pill, Color mark) → Color
A selection capsule that can actually be seen on pill: a wash of mark, deepened until it clears portalWellContrast.