PlatformButton class
A platform-adaptive button that renders Material Design buttons on Android and Cupertino buttons on iOS.
This widget automatically selects the appropriate button type based on the target platform:
- On Android: renders Material buttons (TextButton, ElevatedButton, OutlinedButton, FilledButton)
- On iOS: renders Cupertino buttons (CupertinoButton, CupertinoButton.filled, CupertinoButton.tinted)
The button can be configured with platform-specific data through materialButtonData and cupertinoButtonData, or with common properties that work across platforms.
Example:
PlatformButton(
onPressed: () => print('Button pressed'),
child: Text('Adaptive Button'),
materialButtonVariant: MaterialButtonVariant.elevated,
cupertinoButtonVariant: CupertinoButtonVariant.filled,
)
- Inheritance
Constructors
- PlatformButton({MaterialButtonVariant materialButtonVariant = .elevated, CupertinoButtonVariant cupertinoButtonVariant = .normal, bool isEnabled = true, Key? widgetKey, Key? key, Widget? child, VoidCallback? onPressed, VoidCallback? onLongPress, MouseCursor? mouseCursor, FocusNode? focusNode, bool? autofocus = kDefaultAutofocus, MaterialButtonData? materialButtonData, CupertinoButtonData? cupertinoButtonData})
-
Creates a platform-adaptive button.
const
Properties
- autofocus → bool?
-
Whether the button should automatically focus when it's first displayed.
final
- child → Widget?
-
The widget to display as the button's label.
final
- cupertinoButtonData → CupertinoButtonData?
-
Platform-specific data for Cupertino buttons.
final
- cupertinoButtonVariant → CupertinoButtonVariant
-
The type of Cupertino button to render on iOS.
final
- focusNode → FocusNode?
-
The focus node for the button.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEnabled → bool
-
Whether the button is enabled and can be pressed.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- materialButtonData → MaterialButtonData?
-
Platform-specific data for Material Design buttons.
final
- materialButtonVariant → MaterialButtonVariant
-
The type of Material Design button to render on Android.
final
- mouseCursor → MouseCursor?
-
The cursor to display when the mouse hovers over the button.
final
- onLongPress → VoidCallback?
-
Callback that is called when the button is long-pressed.
The button is disabled when isEnabled is false, even if onLongPress is provided.
final
- onPressed → VoidCallback?
-
Callback that is called when the button is pressed.
The button is disabled when isEnabled is false, even if onPressed is provided.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- widgetKey → Key?
-
Optional key applied to the inner platform-specific widget.
finalinherited
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
inherited
-
buildCupertino(
BuildContext context) → Widget -
Builds the Cupertino (iOS) variant of this widget.
override
-
buildMaterial(
BuildContext context) → Widget -
Builds the Material Design (Android) variant of 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