ElevatedButton.icon constructor

ElevatedButton.icon({
  1. Key? key,
  2. required VoidCallback? onPressed,
  3. VoidCallback? onLongPress,
  4. ValueChanged<bool>? onHover,
  5. ValueChanged<bool>? onFocusChange,
  6. ButtonStyle? style,
  7. FocusNode? focusNode,
  8. bool? autofocus,
  9. Clip? clipBehavior,
  10. MaterialStatesController? statesController,
  11. Widget? icon,
  12. required Widget label,
  13. IconAlignment iconAlignment = IconAlignment.start,
})

Create an elevated button from a pair of widgets that serve as the button's icon and label.

The icon and label are arranged in a row and padded by 12 logical pixels at the start, and 16 at the end, with an 8 pixel gap in between.

If icon is null, will create an ElevatedButton instead.

Determines the alignment of the icon within the widgets such as:

The effect of iconAlignment depends on TextDirection. If textDirection is TextDirection.ltr then IconAlignment.start and IconAlignment.end align the icon on the left or right respectively. If textDirection is TextDirection.rtl the the alignments are reversed.

Defaults to IconAlignment.start.

This sample demonstrates how to use iconAlignment to align the button icon to the start or the end of the button.
link

To create a local project with this code sample, run:
flutter create --sample=material.IconAlignment.1 mysample

Implementation

factory ElevatedButton.icon({
  Key? key,
  required VoidCallback? onPressed,
  VoidCallback? onLongPress,
  ValueChanged<bool>? onHover,
  ValueChanged<bool>? onFocusChange,
  ButtonStyle? style,
  FocusNode? focusNode,
  bool? autofocus,
  Clip? clipBehavior,
  MaterialStatesController? statesController,
  Widget? icon,
  required Widget label,
  IconAlignment iconAlignment = IconAlignment.start,
}) {
  if (icon == null) {
    return ElevatedButton(
      key: key,
      onPressed: onPressed,
      onLongPress: onLongPress,
      onHover: onHover,
      onFocusChange: onFocusChange,
      style: style,
      focusNode: focusNode,
      autofocus: autofocus ?? false,
      clipBehavior: clipBehavior ?? Clip.none,
      statesController: statesController,
      child: label,
    );
  }
  return _ElevatedButtonWithIcon(
    key: key,
    onPressed: onPressed,
    onLongPress: onLongPress,
    onHover: onHover,
    onFocusChange: onFocusChange,
    style: style,
    focusNode: focusNode,
    autofocus: autofocus ?? false,
    clipBehavior: clipBehavior ?? Clip.none,
    statesController: statesController,
    icon: icon,
    label: label,
    iconAlignment: iconAlignment,
  );
}