fluent2FieldFace function

Fluent2FieldFace fluent2FieldFace(
  1. Fluent2ThemeData t,
  2. Fluent2InputAppearance appearance, {
  3. required bool enabled,
  4. bool hover = false,
  5. bool active = false,
  6. bool invalid = false,
})

The face of a field in appearance at rest, under the pointer (hover), focused or pressed (active), disabled, or invalid, as Fluent's Input styles step them.

Implementation

Fluent2FieldFace fluent2FieldFace(
  Fluent2ThemeData t,
  Fluent2InputAppearance appearance, {
  required bool enabled,
  bool hover = false,
  bool active = false,
  bool invalid = false,
}) {
  final c = t.colors;
  final underline = appearance == Fluent2InputAppearance.underline;
  if (!enabled) {
    return (
      fill: c.transparentBackground,
      side: underline
          ? c.transparentStroke
          : fluent2Step(t, c.neutralStrokeDisabled),
      bottom: fluent2Step(t, c.neutralStrokeDisabled),
    );
  }
  final red = t.sharedColors.paletteRedBorder2;
  switch (appearance) {
    case Fluent2InputAppearance.outline:
      if (invalid && !active) {
        return (fill: c.neutralBackground1, side: red, bottom: red);
      }
      return (
        fill: c.neutralBackground1,
        side: active
            ? c.neutralStroke1Pressed
            : hover
            ? c.neutralStroke1Hover
            : c.neutralStroke1,
        bottom: active
            ? c.neutralStrokeAccessiblePressed
            : hover
            ? c.neutralStrokeAccessibleHover
            : c.neutralStrokeAccessible,
      );
    case Fluent2InputAppearance.underline:
      return (
        fill: c.transparentBackground,
        side: c.transparentStroke,
        bottom: invalid && !active
            ? red
            : active
            ? c.neutralStrokeAccessiblePressed
            : hover
            ? c.neutralStrokeAccessibleHover
            : c.neutralStrokeAccessible,
      );
    case Fluent2InputAppearance.filledDarker:
    case Fluent2InputAppearance.filledLighter:
      // Filled darker: Fluent's grey laid over the ground the field stands
      // on, so it shows on the tinted page as on a card.
      final fill = appearance == Fluent2InputAppearance.filledDarker
          ? fluent2FieldWell(t)
          : c.neutralBackground1;
      if (invalid && !active) return (fill: fill, side: red, bottom: red);
      final stroke = hover || active
          ? c.transparentStrokeInteractive
          : c.transparentStroke;
      return (fill: fill, side: stroke, bottom: stroke);
  }
}