CalseeKey.icon constructor

CalseeKey.icon(
  1. IconData icon, {
  2. required KeyRole role,
  3. required String semanticLabel,
  4. String? label,
  5. VoidCallback? onPressed,
  6. VoidCallback? onLongPress,
  7. double sizeFactor = 0.42,
  8. bool haptics = true,
  9. Key? key,
})

A key showing icon, with an optional label under it.

Implementation

factory CalseeKey.icon(
  IconData icon, {
  required KeyRole role,
  required String semanticLabel,
  String? label,
  VoidCallback? onPressed,
  VoidCallback? onLongPress,
  double sizeFactor = 0.42,
  bool haptics = true,
  Key? key,
}) => CalseeKey(
  role: role,
  semanticLabel: semanticLabel,
  onPressed: onPressed,
  onLongPress: onLongPress,
  haptics: haptics,
  artSeed: semanticLabel.hashCode & 0x7FFFFFFF,
  key: key,
  builder: (context, style, shortSide) {
    final glyph = Icon(
      icon,
      color: style.label,
      size: shortSide * sizeFactor,
    );
    if (label == null) return glyph;
    // Some faces (Material 3 Expressive shapes) leave less than the
    // short side for content: shrink to fit, as text labels do.
    return FittedBox(
      fit: BoxFit.scaleDown,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          glyph,
          SizedBox(height: shortSide * 0.06),
          CalseeKeyLabel(label, style: style, size: shortSide * 0.14),
        ],
      ),
    );
  },
);