Button

Displays a button or a widget that looks like a button.

Loading preview...

Installation

flutcn_ui add button

Usage

main.dart
import '../widgets/button.dart';
 
Button.primary(
  text: 'Click me',
  onPressed: () {},
)

Properties

PropertyTypeDefaultDescription
textString?nullLabel text displayed on the button.
iconIconData?nullLeading icon displayed before the text.
onPressedVoidCallback?nullCallback triggered on tap. Pass null to disable.
variantButtonVariantprimaryStyle variant of the button.
sizeButtonSizemdSize preset controlling height, padding, and font size.
isLoadingboolfalseWhen true, replaces content with a circular spinner.
isDisabledboolfalseWhen true, disables interaction and dims the button.
iconOnlyboolfalseWhen true, renders only the icon without text.
childWidget?nullCustom child widget. Overrides text and icon.
backgroundColorColor?Override the background color.
foregroundColorColor?Override the text and icon color.
hoverBackgroundColorColor?Background color on hover.
pressedBackgroundColorColor?Background color on press.
disabledBackgroundColorColor?Background color when disabled.
disabledForegroundColorColor?Text color when disabled.
loadingIndicatorColorColor?Color of the loading spinner.
borderColorColor?Border color (effective with outline or custom variant).
borderWidthdouble?Border stroke width.
elevationdouble?0Shadow elevation.
hoverElevationdouble?Elevation on hover.
pressedElevationdouble?Elevation on press.
disabledElevationdouble?Elevation when disabled.
borderRadiusdouble?8.0Corner radius in logical pixels.
widthdouble?Fixed width.
heightdouble?Fixed height.
minWidthdouble?Minimum width.
minHeightdouble?Minimum height.
fontSizedouble?Font size of the label text.
iconSizedouble?Size of the icon.
fontWeightFontWeight?w600Font weight of the label text.
paddingEdgeInsetsGeometry?Inner padding override.
animationDurationDuration?200msDuration of the press animation.
animationCurveCurve?easeInOutCurve of the press animation.
shapeBoxShape?Set to BoxShape.circle for a circular button.
gradientGradient?Gradient fill (only applied in custom variant).
boxShadowList<BoxShadow>?Custom box shadow (only applied in custom variant).
loadingSizedouble?Size of the loading spinner.
overlayColorColor?Ripple/overlay color on interaction.
contentAlignmentMainAxisAlignment?centerAlignment of the row containing icon and text.
textStyleTextStyle?Full text style override.

Variants

FlutButton provides several variants. Choose the one that best communicates the intent of the action.

Primary

The default variant. Use for the most important action on a screen.

button.dart
Button.primary(
  text: 'Get Started',
  onPressed: () {},
)

Secondary

Use for secondary or supporting actions alongside a primary button.

button.dart
Button.secondary(
  text: 'Cancel',
  onPressed: () {},
)

Outline

A bordered button with a transparent background. Use for less prominent actions.

button.dart
Button.outline(
  text: 'Learn More',
  onPressed: () {},
)

Ghost

No background or border. Useful for toolbar actions and inline controls.

button.dart
Button.ghost(
  text: 'Edit',
  onPressed: () {},
)

Styled like a hyperlink with an underline. Use for navigational actions.

button.dart
Button.link(
  text: 'View docs',
  onPressed: () {},
)

Destructive

Red-toned button for irreversible actions like deleting or removing.

button.dart
Button.destructive(
  text: 'Delete account',
  onPressed: () {},
)

Custom

Full control over colors, shape, gradient, and shadows.

button.dart
Button.custom(
  text: 'Custom',
  backgroundColor: Colors.teal,
  foregroundColor: Colors.white,
  borderRadius: 20,
  onPressed: () {},
)

Sizes

Sm

Height of 32, font size 14. For compact UIs or inline actions.

button.dart
Button.primary(
  text: 'Small',
  size: ButtonSize.sm,
  onPressed: () {},
)

Md

Height of 40, font size 16. The default size.

button.dart
Button.primary(
  text: 'Medium',
  size: ButtonSize.md,
  onPressed: () {},
)

Lg

Height of 48, font size 18. For prominent call-to-action buttons.

button.dart
Button.primary(
  text: 'Large',
  size: ButtonSize.lg,
  onPressed: () {},
)

Icon

Square button at 40×40, designed for icon-only buttons.

button.dart
Button.icon(
  icon: Icons.search,
  onPressed: () {},
)

Custom

Fully control the height, width, font size, and padding.

button.dart
Button.custom(
  text: 'Custom size',
  height: 56,
  width: 200,
  fontSize: 20,
  onPressed: () {},
)

With Icons

Add a leading icon alongside text using the icon parameter.

button.dart
Button.primary(
  text: 'Save',
  icon: Icons.save,
  onPressed: () {},
)

For icon-only buttons, use Button.icon():

button.dart
Button.icon(
  icon: Icons.settings,
  onPressed: () {},
)

Loading State

Set isLoading: true to replace the button content with a spinner. The button remains non-interactive while loading.

button.dart
Button.primary(
  text: 'Submitting...',
  isLoading: true,
  onPressed: () {},
)

Disabled State

Set isDisabled: true to prevent interaction. The button appears dimmed.

button.dart
Button.primary(
  text: 'Not available',
  isDisabled: true,
  onPressed: () {},
)

Gradient Button

Use Button.gradient() to apply a linear or radial gradient fill.

button.dart
Button.gradient(
  text: 'Get Premium',
  gradient: LinearGradient(
    colors: [Colors.purple, Colors.blue],
  ),
  onPressed: () {},
)

Circular Button

Use Button.circular() for a perfectly round icon button.

button.dart
Button.circular(
  icon: Icons.add,
  size: 56,
  onPressed: () {},
)

Helper Class

The Button helper class provides named constructors for each variant and style combination.

button.dart
Button.primary(text: 'Primary', onPressed: () {})
Button.secondary(text: 'Secondary', onPressed: () {})
Button.outline(text: 'Outline', onPressed: () {})
Button.ghost(text: 'Ghost', onPressed: () {})
Button.link(text: 'Link', onPressed: () {})
Button.destructive(text: 'Delete', onPressed: () {})
Button.icon(icon: Icons.settings, onPressed: () {})
Button.gradient(
  text: 'Gradient',
  gradient: LinearGradient(colors: [Colors.pink, Colors.orange]),
  onPressed: () {},
)
Button.circular(icon: Icons.add, size: 50, onPressed: () {})
Button.custom(
  text: 'Custom',
  backgroundColor: Colors.teal,
  foregroundColor: Colors.white,
  onPressed: () {},
)

On this page