FluentButton class

A Fluent 2 button.

FluentButton(
  appearance: FluentButtonAppearance.primary,
  icon: const Icon(FluentIcons.add_20_regular),
  onPressed: () {},
  child: const Text('Add'),
)

Pass onPressed: null to disable it — disabled is a real state here, not a visual treatment: the button stops reporting hover and press, refuses focus, and never invokes the callback.

Customisation follows the same three rungs Microsoft documents for the React original. style is merged last and wins; FluentButtonTheme restyles a subtree; and for anything further, resolveFluentButtonState, resolveFluentButtonStyle and buildFluentButton are public so any one of them can be replaced without forking this widget.

Inheritance

Constructors

FluentButton({Key? key, required Widget? child, VoidCallback? onPressed, FluentButtonAppearance appearance = FluentButtonAppearance.secondary, FluentButtonSize size = FluentButtonSize.medium, FluentButtonShape shape = FluentButtonShape.rounded, FluentButtonIconPosition iconPosition = FluentButtonIconPosition.before, Widget? icon, Widget? activeIcon, Widget? menuIcon, FluentButtonStyle? style, FocusNode? focusNode, bool autofocus = false, String? semanticLabel})
Creates a button with an optional icon and a child label.
const
FluentButton.icon({Key? key, required Widget icon, required String semanticLabel, Widget? activeIcon, VoidCallback? onPressed, FluentButtonAppearance appearance = FluentButtonAppearance.secondary, FluentButtonSize size = FluentButtonSize.medium, FluentButtonShape shape = FluentButtonShape.rounded, FluentButtonStyle? style, FocusNode? focusNode, bool autofocus = false})
Creates an icon-only button.
const

Properties

activeIcon → Widget?
Shown in place of icon while a subtle or transparent button is hovered or pressed — upstream's bundleIcon, which swaps the Regular glyph for its Filled one there. Pass the filled counterpart of icon:
final
appearance → FluentButtonAppearance
Fill and outline treatment.
final
autofocus → bool
Whether to take focus on mount.
final
child → Widget?
The label. Null for an icon-only button.
final
focusNode → FocusNode?
Focus node to use. One is created internally when omitted.
final
hashCode → int
The hash code for this object.
no setterinherited
icon → Widget?
Optional leading or trailing icon.
final
iconPosition → FluentButtonIconPosition
Which side of the label the icon sits on.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
A menu affordance after the label, which makes this upstream's MenuButton:
final
onPressed → VoidCallback?
Invoked on tap and on Space or Enter. Null disables the button.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
semanticLabel → String?
Announced by assistive technology.
final
shape → FluentButtonShape
Corner treatment.
final
size → FluentButtonSize
Height and type ramp.
final
style → FluentButtonStyle?
Overrides layered over the theme defaults. Merged last, so it wins.
final

Methods

build(BuildContext context) → Widget
Describes the part of the user interface represented by this widget.
override
createElement() → StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited