NuntioStateButton.icon constructor

NuntioStateButton.icon(
  1. BuildContext context, {
  2. required Map<ButtonState, IconedButton> iconedButtons,
  3. Function? onPressed,
  4. ButtonState? state = ButtonState.idle,
  5. Function? animationEnd,
  6. dynamic maxWidth = 170.0,
  7. dynamic minWidth = 58.0,
  8. dynamic height = 53.0,
  9. dynamic radius = 100.0,
  10. dynamic progressIndicatorSize = 35.0,
  11. double iconPadding = 5.0,
  12. TextStyle? textStyle,
  13. CircularProgressIndicator? progressIndicator,
  14. MainAxisAlignment? progressIndicatorAlignment,
  15. EdgeInsets padding = EdgeInsets.zero,
  16. List<ButtonState> minWidthStates = const <ButtonState>[ButtonState.loading],
})

Implementation

factory NuntioStateButton.icon(
  BuildContext context, {
  required Map<ButtonState, IconedButton> iconedButtons,
  Function? onPressed,
  ButtonState? state = ButtonState.idle,
  Function? animationEnd,
  maxWidth: 170.0,
  minWidth: 58.0,
  height: 53.0,
  radius: 100.0,
  progressIndicatorSize: 35.0,
  double iconPadding: 5.0,
  TextStyle? textStyle,
  CircularProgressIndicator? progressIndicator,
  MainAxisAlignment? progressIndicatorAlignment,
  EdgeInsets padding = EdgeInsets.zero,
  List<ButtonState> minWidthStates = const <ButtonState>[ButtonState.loading],
}) {
  assert(
    iconedButtons.keys.toSet().containsAll(ButtonState.values.toSet()),
    'Must be non-null widgets provided in map of stateWidgets. Missing keys => ${ButtonState.values.toSet().difference(iconedButtons.keys.toSet())}',
  );

  if (textStyle == null) {
    textStyle = TextStyle(
        color: Theme.of(context).brightness == Brightness.light
            ? Colors.white
            : Colors.black,
        fontWeight: FontWeight.w600,
        fontSize: 16);
  }

  Map<ButtonState, Widget> stateWidgets = {
    ButtonState.idle: buildChildWithIcon(
        context, iconedButtons[ButtonState.idle]!, iconPadding, textStyle),
    ButtonState.loading: Column(),
    ButtonState.fail: buildChildWithIcon(
        context, iconedButtons[ButtonState.fail]!, iconPadding, textStyle),
    ButtonState.success: buildChildWithIcon(
        context, iconedButtons[ButtonState.success]!, iconPadding, textStyle)
  };

  Map<ButtonState, Color> stateColors = {
    ButtonState.idle: iconedButtons[ButtonState.idle]!.color,
    ButtonState.loading: iconedButtons[ButtonState.loading]!.color,
    ButtonState.fail: iconedButtons[ButtonState.fail]!.color,
    ButtonState.success: iconedButtons[ButtonState.success]!.color,
  };

  return NuntioStateButton(
    stateWidgets: stateWidgets,
    stateColors: stateColors,
    state: state,
    onPressed: onPressed,
    onAnimationEnd: animationEnd,
    maxWidth: maxWidth,
    minWidth: minWidth,
    progressIndicatorSize: progressIndicatorSize,
    progressIndicatorAlignment: MainAxisAlignment.center,
    progressIndicator: progressIndicator,
    minWidthStates: minWidthStates,
  );
}