build method

  1. @override
Widget build(
  1. BuildContext context,
  2. ToolbarItemDisplayMode displayMode
)
override

Builds the final widget for this display mode for this item. Sub-classes implement this to build the widget that is appropriate for the given display mode (in toolbar or overflowed).

Implementation

@override
Widget build(BuildContext context, ToolbarItemDisplayMode displayMode) {
  final brightness = MacosTheme.of(context).brightness;
  if (displayMode == ToolbarItemDisplayMode.inToolbar) {
    Widget iconButton = MacosIconButton(
      disabledColor: Colors.transparent,
      icon: MacosIconTheme(
        data: MacosTheme.of(context).iconTheme.copyWith(
              color: brightness.resolve(
                const Color.fromRGBO(0, 0, 0, 0.5),
                const Color.fromRGBO(255, 255, 255, 0.5),
              ),
              size: showLabel ? 16.0 : 20.0,
            ),
        child: icon,
      ),
      onPressed: onPressed,
      boxConstraints: BoxConstraints(
        minHeight: showLabel ? 20 : 26,
        minWidth: 20,
        maxWidth: 48,
        maxHeight: 38,
      ),
      padding: const EdgeInsets.symmetric(horizontal: 12.0),
    );

    if (showLabel) {
      iconButton = Padding(
        padding: const EdgeInsets.fromLTRB(6.0, 6.0, 6.0, 0.0),
        child: Column(
          children: [
            iconButton,
            Padding(
              padding: const EdgeInsets.only(top: 4.0),
              child: Text(
                label,
                style: const TextStyle(
                  fontSize: 11.0,
                  color: MacosColors.systemGrayColor,
                ),
              ),
            ),
          ],
        ),
      );
    }

    if (tooltipMessage != null) {
      iconButton = MacosTooltip(
        message: tooltipMessage!,
        child: iconButton,
      );
    }
    return iconButton;
  } else {
    return ToolbarOverflowMenuItem(
      label: label,
      onPressed: onPressed,
    );
  }
}