ProgressButton.icon constructor

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

Implementation

factory ProgressButton.icon({
  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: 4.0,
  TextStyle? textStyle,
  CircularProgressIndicator? progressIndicator,
  MainAxisAlignment? progressIndicatorAlignment,
  EdgeInsets padding = EdgeInsets.zero,
  List<ButtonState> minWidthStates = const <ButtonState>[ButtonState.loading],
}) {
  assert(
    iconedButtons != null &&
        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: Colors.white, fontWeight: FontWeight.w500);
  }

  Map<ButtonState, Widget> stateWidgets = {
    ButtonState.idle: buildChildWithIcon(
        iconedButtons[ButtonState.idle]!, iconPadding, textStyle),
    ButtonState.loading: Column(),
    ButtonState.fail: buildChildWithIcon(
        iconedButtons[ButtonState.fail]!, iconPadding, textStyle),
    ButtonState.success: buildChildWithIcon(
        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 ProgressButton(
    stateWidgets: stateWidgets,
    stateColors: stateColors,
    state: state,
    onPressed: onPressed,
    onAnimationEnd: animationEnd,
    maxWidth: maxWidth,
    minWidth: minWidth,
    radius: radius,
    height: height,
    progressIndicatorSize: progressIndicatorSize,
    progressIndicatorAlignment: MainAxisAlignment.center,
    progressIndicator: progressIndicator,
    minWidthStates: minWidthStates,
  );
}