icon static method
Widget
icon({
- Key? key,
- double? iconSize,
- VisualDensity? visualDensity,
- EdgeInsetsGeometry? padding,
- EdgeInsetsGeometry? margin,
- AlignmentGeometry? alignment,
- double? splashRadius,
- Widget? child,
- Color? color,
- Color? focusColor,
- Color? hoverColor,
- Color? highlightColor,
- Color? splashColor,
- Color? disabledColor,
- VoidCallback? onPressed,
- MouseCursor? mouseCursor,
- FocusNode? focusNode,
- bool back = false,
- bool autofocus = false,
- bool primary = false,
- bool enabled = true,
- bool busy = false,
- bool mini = false,
- bool tintLabel = true,
- String? tooltip,
- String? label,
- TextStyle? labelStyle,
- bool? enableFeedback = true,
- BoxConstraints? constraints,
Create an icon button.
Implementation
static Widget icon({
Key? key,
double? iconSize,
VisualDensity? visualDensity,
EdgeInsetsGeometry? padding,
EdgeInsetsGeometry? margin,
AlignmentGeometry? alignment,
double? splashRadius,
Widget? child,
Color? color,
Color? focusColor,
Color? hoverColor,
Color? highlightColor,
Color? splashColor,
Color? disabledColor,
VoidCallback? onPressed,
MouseCursor? mouseCursor,
FocusNode? focusNode,
bool back = false,
bool autofocus = false,
bool primary = false,
bool enabled = true,
bool busy = false,
bool mini = false,
bool tintLabel = true,
String? tooltip,
String? label,
TextStyle? labelStyle,
bool? enableFeedback = true,
BoxConstraints? constraints,
}) =>
ThemeBuilder((context) {
final _tooltip = tooltip ?? label;
final labeled = label != null;
final labeledOrMini = labeled || mini == true;
final _color = color ??
(primary == true
? context.primaryActionIconColor
: context.iconColor);
final _iconSize = iconSize ??
(labeledOrMini
? 20.0
: primary == true
? context.primaryActionIconTheme.size
: context.iconTheme.size) ??
24.0;
return Container(
padding: margin,
child: IconButton(
key: key,
iconSize: _iconSize,
visualDensity: visualDensity,
padding: padding ??
(labeled
? EdgeInsets.symmetric(vertical: mini ? 4 : 8)
: const EdgeInsets.symmetric(horizontal: 8)),
alignment: alignment ?? Alignment.center,
splashRadius: splashRadius ?? (labeled ? 24 : 18),
icon: labeled
? Column(
children: [
SizedBox(
height: iconSize == null
? (mini ? 2 : 4)
: ((mini ? 22 : 24) - iconSize).abs(),
),
busy
? CircularProgress.small(color: _color)
.sizedCenter(_iconSize)
: child!,
SizedBox(height: mini ? 2 : 2.5),
Expanded(
child: Text(
label,
style: labelStyle ??
TextStyle(
fontSize: 9,
color: enabled
? (tintLabel == true ? _color : null)
: _color?.subbed,
),
),
),
],
)
: busy
? CircularProgress.small(color: _color)
: (child ?? const SizedBox()),
color: _color,
focusColor: focusColor,
hoverColor: hoverColor,
highlightColor: highlightColor,
splashColor: splashColor,
disabledColor: disabledColor ?? _color?.hinted,
onPressed: enabled
? busy
? () {}
: () {
onPressed?.call();
if (back) Get.back();
}
: null,
mouseCursor: mouseCursor ?? SystemMouseCursors.click,
focusNode: focusNode,
autofocus: autofocus,
tooltip: _tooltip,
enableFeedback: enableFeedback ?? true,
constraints: constraints ??
(labeled
? const BoxConstraints.expand(width: 40)
: const BoxConstraints()),
),
);
});