control static method

Widget control(
  1. String label, {
  2. required bool enabled,
  3. bool primary = false,
  4. IconData? icon,
  5. bool focused = false,
})

A control that reads as one: padded, bordered, and dimmed when it does nothing.

Pass enabled: false for an action with nothing to do — Undo with no history, Publish while publishing — so that it says so rather than looking identical to one that works.

Implementation

static Widget control(
  String label, {
  required bool enabled,
  bool primary = false,
  IconData? icon,
  bool focused = false,
}) {
  final Color foreground = !enabled
      ? faint
      : primary
          ? const Color(0xFFFFFFFF)
          : ink;
  return Container(
    height: 32,
    padding: const .symmetric(horizontal: space3),
    decoration: BoxDecoration(
      color: !enabled
          ? const Color(0xFFF4F4F7)
          : primary
              ? accent
              : surface,
      // The focus ring, drawn here rather than left to the theme's
      // `focusColor`: a control that is only outlined by a platform
      // highlight is a control a switch-control user cannot follow on a
      // screen where that highlight is not drawn at all.
      border: focused
          ? Border.all(color: accent, width: 2)
          : Border.all(
              color: !enabled
                  ? line
                  : primary
                      ? accent
                      : lineStrong,
            ),
      borderRadius: .circular(radiusSmall),
    ),
    child: Row(
      mainAxisSize: .min,
      children: <Widget>[
        if (icon != null) ...<Widget>[
          Icon(icon, size: 15, color: foreground),
          const SizedBox(width: 6),
        ],
        // Flexible and one line, so a control given less room than its
        // label cuts the label short with an ellipsis rather than
        // overflowing, and is exactly as wide as before where there is room.
        Flexible(
          child: DVText(label).modifier(
            const DVModifier()
                .fontSize(13)
                .color(foreground)
                .fontWeight(primary ? FontWeight.w600 : FontWeight.w500)
                .maxLines(1),
          ),
        ),
      ],
    ),
  );
}