floatingActionButtonTheme static method

FloatingActionButtonThemeData floatingActionButtonTheme({
  1. double? radius,
  2. bool useShape = true,
})

An opinionated FloatingActionButtonThemeData with custom border radius.

The border radius defaults to kDefaultRadius = 16, the new M3 default. https://m3.material.io/components/floating-action-button/specs

By setting useShape to false, it is possible to opt out of all shape theming on FABs and keep their M2 defaults, while still eg. keeping M3 defaults on other widgets or changing their border radius with the shared global value.

You may want to continue to keep the FAB circular and extended FAB stadium (pill) shaped as before, despite otherwise using a rounder or M3 design. The circular M2 FAB goes well with those designs too and is more familiar.

Implementation

static FloatingActionButtonThemeData floatingActionButtonTheme({
  /// Corner radius of FAB.
  ///
  /// Defaults to [kDefaultRadius] = 16.
  final double? radius,

  /// Set to false, to not apply Shape theming to the FAB. It will then keep
  /// using its M2 default round shape and stadium shape for extended FAB.
  final bool useShape = true,
}) =>
    FloatingActionButtonThemeData(
      shape: useShape
          ? RoundedRectangleBorder(
              borderRadius: BorderRadius.all(
                Radius.circular(radius ?? kDefaultRadius),
              ),
            )
          : null,
    );