IncrementDecrementWidget.squared constructor
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,
- Color? borderColor,
- Widget? incrementIcon,
- Widget? decrementIcon,
- Duration longPressInterval = const Duration(milliseconds: 100),
- 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,
);
}