showMaterialNumberPicker function

Future<int?> showMaterialNumberPicker({
  1. required BuildContext context,
  2. String? title,
  3. required int minNumber,
  4. required int maxNumber,
  5. int? selectedNumber,
  6. int step = 1,
  7. Color? headerColor,
  8. TextStyle? headerTextStyle,
  9. Color? backgroundColor,
  10. Color? bottomBorderColor,
  11. TextStyle? confirmTextStyle,
  12. TextStyle? cancelTextStyle,
  13. TextStyle? scrollItemTextStyle,
  14. TextStyle? selectedItemTextStyle,
  15. String? confirmText,
  16. String? cancelText,
  17. double? maxLongSide,
  18. double? maxShortSide,
  19. ValueChanged<int>? onChanged,
  20. VoidCallback? onConfirmed,
  21. VoidCallback? onCancelled,
})

Implementation

Future<int?> showMaterialNumberPicker({
  required BuildContext context,
  String? title,
  required final int minNumber,
  required final int maxNumber,
  final int? selectedNumber,
  final int step = 1,
  Color? headerColor,
  TextStyle? headerTextStyle,
  Color? backgroundColor,
  Color? bottomBorderColor,
  TextStyle? confirmTextStyle,
  TextStyle? cancelTextStyle,
  TextStyle? scrollItemTextStyle,
  TextStyle? selectedItemTextStyle,
  String? confirmText,
  String? cancelText,
  double? maxLongSide,
  double? maxShortSide,
  ValueChanged<int>? onChanged,
  VoidCallback? onConfirmed,
  VoidCallback? onCancelled,
}) {
  List<int> items = [];

  for (int i = minNumber; i <= maxNumber; i += step) {
    items.add(i);
  }

  return showDialog<int>(
    context: context,
    builder: (BuildContext context) {
      return ScrollPickerDialog<int>(
        items: items,
        title: title,
        selectedItem: selectedNumber,
        headerColor: headerColor,
        backgroundColor: backgroundColor,
        bottomBorderColor: bottomBorderColor,
        headerTextStyle: headerTextStyle,
        confirmTextStyle: confirmTextStyle,
        scrollItemTextStyle: scrollItemTextStyle,
        selectedItemTextStyle: selectedItemTextStyle,
        cancelTextStyle: cancelTextStyle,
        confirmText: confirmText,
        cancelText: cancelText,
        maxLongSide: maxLongSide,
        maxShortSide: maxLongSide,
      );
    },
  ).then((selection) {
    if (selection != null) {
      onChanged?.call(selection);
      onConfirmed?.call();
    } else {
      onCancelled?.call();
    }
    return selection;
  });
}