glossKeyFace function

GlossFace glossKeyFace(
  1. GlossThemeData theme,
  2. Set<WidgetState> states, {
  3. required GlossKeyKind kind,
  4. bool destructive = false,
  5. GlossStyle? style,
})

The face of a key of kind in states: gel (ruby when destructive) or pearl, style over its part theme.

Implementation

GlossFace glossKeyFace(
  GlossThemeData theme,
  Set<WidgetState> states, {
  required GlossKeyKind kind,
  bool destructive = false,
  GlossStyle? style,
}) {
  final c = theme.colors;
  final layered = DesignStyleOf([style, glossKeyTheme(theme, kind)], states);
  final disabled = states.contains(WidgetState.disabled);
  final pressed = states.contains(WidgetState.pressed);
  final focus = glossFocusOf(c, focused: states.contains(WidgetState.focused));
  if (disabled) {
    // Clouded, not lit: a gel key off keeps a faint cast of its gel, so
    // it still reads as the screen's action and apart from a pearl key.
    final rest = GlossFace.pearl(c);
    final clouded = kind == GlossKeyKind.gel
        ? GlossFace.lerp(
            rest,
            destructive ? GlossFace.ruby(c) : GlossFace.gel(c),
            0.2,
          )
        : rest;
    // By night a key off sinks halfway to the page, so it reads as off
    // beside a lit pearl and its clouded words still read on it.
    final night = c.brightness == Brightness.dark;
    Color dim(Color v) => night ? Color.lerp(v, c.page, 0.5)! : v;
    return clouded.copyWith(
      top: dim(clouded.top),
      middle: dim(clouded.middle),
      bottom: dim(clouded.bottom),
      foreground: layered.foreground ?? c.inkDisabled,
      edge: rest.edge,
      lens: night ? 0 : 0.25,
      lift: 0.3,
      glow: const Color(0x00000000),
    );
  }
  var face = switch (kind) {
    GlossKeyKind.gel => destructive ? GlossFace.ruby(c) : GlossFace.gel(c),
    _ => GlossFace.pearl(
      c,
    ).copyWith(foreground: destructive ? c.danger : c.ink),
  };
  final fill = layered.fill;
  if (fill != null) face = face.glazed(fill);
  final edge = layered.edge ?? layered.side?.color;
  return face.copyWith(
    foreground: layered.foreground,
    edge: edge,
    travel: pressed ? 1 : 0,
    focus: focus,
  );
}