showMaterialScrollPicker<T> function

Future<T?> showMaterialScrollPicker<T>({
  1. required BuildContext context,
  2. String? title,
  3. required List<T> items,
  4. required T selectedItem,
  5. bool showDivider = true,
  6. Color? headerColor,
  7. Color? headerTextColor,
  8. Color? backgroundColor,
  9. Color? buttonTextColor,
  10. String? confirmText,
  11. bool cancellable = true,
  12. String? cancelText,
  13. double? maxLongSide,
  14. double? maxShortSide,
  15. ValueChanged<T>? onChanged,
  16. VoidCallback? onConfirmed,
  17. VoidCallback? onCancelled,
  18. Transformer<T>? transformer,
})

Allows selection of a string via a slot machine carousel

Implementation

Future<T?> showMaterialScrollPicker<T>({
  required BuildContext context,

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

  /// The list of items to use with the picker
  required List<T> items,

  /// The item that will be initially selected
  required T selectedItem,

  /// flag to show or hide divider lines
  bool showDivider = true,

  /// 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<T>? 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<T>? transformer,
}) {
  return showDialog<T>(
    context: context,
    builder: (BuildContext context) {
      return ScrollPickerDialog<T>(
        items: items,
        title: title,
        selectedItem: selectedItem,
        headerColor: headerColor,
        headerTextColor: headerTextColor,
        backgroundColor: backgroundColor,
        buttonTextColor: buttonTextColor,
        confirmText: confirmText,
        cancelButtonVisible: cancellable,
        cancelText: cancelText,
        maxLongSide: maxLongSide,
        maxShortSide: maxLongSide,
        showDivider: showDivider,
        transformer: transformer,
      );
    },
  ).then((selection) {
    if (onChanged != null && selection != null) onChanged(selection);
    if (onCancelled != null && selection == null) onCancelled();
    if (onConfirmed != null && selection != null) onConfirmed();
    return selection;
  });
}