IconButton constructor Null safety

const IconButton(
  1. {Key? key,
  2. double? iconSize,
  3. VisualDensity? visualDensity,
  4. EdgeInsetsGeometry? padding,
  5. AlignmentGeometry? alignment,
  6. double? splashRadius,
  7. Color? color,
  8. Color? focusColor,
  9. Color? hoverColor,
  10. Color? highlightColor,
  11. Color? splashColor,
  12. Color? disabledColor,
  13. required VoidCallback? onPressed,
  14. MouseCursor? mouseCursor,
  15. FocusNode? focusNode,
  16. bool autofocus = false,
  17. String? tooltip,
  18. bool? enableFeedback,
  19. BoxConstraints? constraints,
  20. ButtonStyle? style,
  21. bool? isSelected,
  22. Widget? selectedIcon,
  23. required Widget icon}
)

Creates an icon button.

Icon buttons are commonly used in the AppBar.actions field, but they can be used in many other places as well.

Requires one of its ancestors to be a Material widget. This requirement no longer exists if ThemeData.useMaterial3 is set to true.

autofocus argument must not be null (though it has default value).

The icon argument must be specified, and is typically either an Icon or an ImageIcon.

Implementation

const IconButton({
  super.key,
  this.iconSize,
  this.visualDensity,
  this.padding,
  this.alignment,
  this.splashRadius,
  this.color,
  this.focusColor,
  this.hoverColor,
  this.highlightColor,
  this.splashColor,
  this.disabledColor,
  required this.onPressed,
  this.mouseCursor,
  this.focusNode,
  this.autofocus = false,
  this.tooltip,
  this.enableFeedback,
  this.constraints,
  this.style,
  this.isSelected,
  this.selectedIcon,
  required this.icon,
}) : assert(splashRadius == null || splashRadius > 0),
     assert(autofocus != null),
     assert(icon != null);