icon static method

Widget icon({
  1. Key? key,
  2. double? iconSize,
  3. VisualDensity? visualDensity,
  4. EdgeInsetsGeometry? padding,
  5. EdgeInsetsGeometry? margin,
  6. AlignmentGeometry? alignment,
  7. double? splashRadius,
  8. Widget? child,
  9. Color? color,
  10. Color? focusColor,
  11. Color? hoverColor,
  12. Color? highlightColor,
  13. Color? splashColor,
  14. Color? disabledColor,
  15. VoidCallback? onPressed,
  16. MouseCursor? mouseCursor,
  17. FocusNode? focusNode,
  18. bool back = false,
  19. bool autofocus = false,
  20. bool primary = false,
  21. bool enabled = true,
  22. bool busy = false,
  23. bool mini = false,
  24. bool tintLabel = true,
  25. String? tooltip,
  26. String? label,
  27. TextStyle? labelStyle,
  28. bool? enableFeedback = true,
  29. 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()),
        ),
      );
    });