IncrementDecrementWidget.squared constructor

IncrementDecrementWidget.squared({
  1. required int quantity,
  2. int? maxQuantity,
  3. int? minValue,
  4. ValueUpdate? onChanged,
  5. Color? backgroundColor,
  6. Color? iconColor,
  7. double? elevation,
  8. EdgeInsetsGeometry? margin,
  9. EdgeInsetsGeometry? valuePadding,
  10. EdgeInsetsGeometry? buttonMargin,
  11. EdgeInsetsGeometry? buttonPadding,
  12. TextStyle? quantityTextStyle,
  13. double? width,
  14. double? height,
  15. double? buttonSize,
  16. double? borderRadius,
  17. Color? borderColor,
  18. Widget? incrementIcon,
  19. Widget? decrementIcon,
  20. Duration longPressInterval = const Duration(milliseconds: 100),
  21. MainAxisAlignment? alignment,
})

Factory constructor for squared buttons with equal width and height and customizable border radius.

The squared design ensures that the increment and decrement buttons are square-shaped, with equal width and height, suitable for compact layouts.

Example usage:

IncrementDecrementWidget.squared(
  quantity: 4,
  maxQuantity: 8,
  onChanged: (newValue) {
    // Handle value change
  },
);

Implementation

factory IncrementDecrementWidget.squared({
  required int quantity,
  int? maxQuantity,
  int? minValue,
  ValueUpdate? onChanged,
  Color? backgroundColor,
  Color? iconColor,
  double? elevation,
  EdgeInsetsGeometry? margin,
  EdgeInsetsGeometry? valuePadding,
  EdgeInsetsGeometry? buttonMargin,
  EdgeInsetsGeometry? buttonPadding,
  TextStyle? quantityTextStyle,
  double? width,
  double? height,
  double? buttonSize,
  double? borderRadius, // Allow specifying border radius
  Color? borderColor,
  Widget? incrementIcon,
  Widget? decrementIcon,
  Duration longPressInterval = const Duration(milliseconds: 100),
  MainAxisAlignment? alignment,
}) {
  final double size = buttonSize ?? 50.0;
  final double effectiveBorderRadius = borderRadius ?? 10.0;
  return IncrementDecrementWidget(
    quantity: quantity,
    maxQuantity: maxQuantity,
    minValue: minValue,
    onChanged: onChanged,
    backgroundColor: backgroundColor,
    iconColor: iconColor,
    elevation: elevation ?? 0.0,
    margin: margin,
    valuePadding: valuePadding,
    buttonMargin: buttonMargin,
    buttonPadding: buttonPadding,
    quantityTextStyle: quantityTextStyle,
    width: width,
    height: height,
    buttonWidth: size,
    buttonHeight: size,
    borderColor: borderColor,
    borderRadius: effectiveBorderRadius,
    // Set the border radius
    splashColor: Colors.grey.withOpacity(0.2),
    incrementIcon: incrementIcon,
    decrementIcon: decrementIcon,
    buttonShape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(effectiveBorderRadius),
    ),
    longPressInterval: longPressInterval,
    alignment: alignment ?? MainAxisAlignment.center,
  );
}