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. Color? headerTextColor,
  9. Color? backgroundColor,
  10. Color? buttonTextColor,
  11. String? confirmText,
  12. bool cancellable = true,
  13. String? cancelText,
  14. double? maxLongSide,
  15. double? maxShortSide,
  16. ValueChanged<int>? onChanged,
  17. VoidCallback? onConfirmed,
  18. VoidCallback? onCancelled,
  19. Transformer<int>? transformer,

Allows selection of a number via a slot machine carousel


Future<int?> showMaterialNumberPicker({
  required BuildContext context,

  /// The title for the dialog box
  String? title,

  /// The lowest or starting number for the selections
  required final int minNumber,

  /// The highest or max number for the selections
  required final int maxNumber,

  /// The number to begin on
  final int? selectedNumber,

  /// The number step, in case you don't to skip ranges.
  final int step = 1,

  /// The dialog header color (overrides theme)
  Color? headerColor,

  /// The dialog header text color (overrides theme)
  Color? headerTextColor,

  /// The dialog background color (overrides theme)
  Color? backgroundColor,

  /// The button text color (overrides theme)
  Color? buttonTextColor,

  /// Text to display in the confirm button
  String? confirmText,

  /// Whether to display a cancel button
  bool cancellable = true,

  /// Text to display in the cancel button
  String? cancelText,

  /// Used to restrict how tall the dialog can be.
  double? maxLongSide,

  /// Used to restrict how wide the dialog can be.
  double? maxShortSide,

  /// Function that gets called when the value is changed
  ValueChanged<int>? onChanged,

  /// Function that gets called when the confirm button is pressed
  VoidCallback? onConfirmed,

  /// Function that gets called when the cancel button is pressed
  VoidCallback? onCancelled,

  /// Function that is called when each items renders which can be used to transform the content
  /// This is helpful, for example, to provide translations to other languages
  Transformer<int>? transformer,
}) {
  List<int> items = [];

  for (int i = minNumber; i <= maxNumber; i += step) {

  return showDialog<int>(
    context: context,
    barrierDismissible: cancellable,
    builder: (BuildContext context) {
      return ScrollPickerDialog<int>(
        items: items,
        title: title,
        selectedItem: selectedNumber,
        headerColor: headerColor,
        headerTextColor: headerTextColor,
        backgroundColor: backgroundColor,
        buttonTextColor: buttonTextColor,
        confirmText: confirmText,
        cancelText: cancelText,
        cancelButtonVisible: cancellable,
        maxLongSide: maxLongSide,
        maxShortSide: maxLongSide,
  ).then((selection) {
    if (selection != null) {
    } else {
    return selection;