build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Builds the Fab widget, applying responsive layout logic based on screen width and menu configuration while integrating with Glass for blur effects, Card for surface styling, GhostButton for interactive behavior, and Tooltip for content display on small screens.

Determines the effective press handler: if menu is non-empty, shows a DropdownMenu via showDropdown; otherwise, invokes onPressed. On screens narrower than threshold with a leading icon, displays only the leading icon and uses Tooltip to reveal the main child on hover or long press. Automatically styles child if it's a Text or Icon using extension methods like large(). Applies blurIn animation for visual enhancement.

Implementation

@override
Widget build(BuildContext context) {
  VoidCallback? effectiveOnPressed;
  if (menu.isNotEmpty) {
    effectiveOnPressed = () => showDropdown(
          context: context,
          builder: (context) => DropdownMenu(children: menu),
        );
  } else {
    effectiveOnPressed = onPressed;
  }

  double width = MediaQuery.of(context).size.width;
  if (leading == null || width >= threshold) {
    final theme = Theme.of(context);
    final compTheme = ComponentTheme.maybeOf<CardTheme>(context);
    final borderRadius = styleValue(
      themeValue: compTheme?.borderRadius,
      defaultValue: theme.borderRadiusLg,
    );
    return PaddingAll(
      padding: 8,
      child: Glass(
        borderRadius: borderRadius?.resolve(TextDirection.ltr) ??
            BorderRadius.circular(0),
        tint: Theme.of(context)
            .colorScheme
            .background
            .withOpacity(Theme.of(context).surfaceOpacity ?? 0.5),
        ignoreContextSignals: true,
        child: Card(
          surfaceOpacity: 0,
          surfaceBlur: 0,
          padding: EdgeInsets.zero,
          child: GhostButton(
            density: ButtonDensity.iconComfortable,
            leading: leading,
            onPressed: effectiveOnPressed,
            child: child is Text
                ? (child as Text).large()
                : child is Icon
                    ? (child as Icon).large()
                    : child,
          ),
        ),
      ),
    ).blurIn;
  } else {
    return Tooltip(
      child: Fab(
        onPressed: effectiveOnPressed,
        threshold: threshold,
        menu: menu,
        child: leading!,
      ),
      tooltip: (context) => child,
    );
  }
}