CupertinoPicker.builder constructor

CupertinoPicker.builder({
  1. Key? key,
  2. double diameterRatio = _kDefaultDiameterRatio,
  3. Color? backgroundColor,
  4. double offAxisFraction = 0.0,
  5. bool useMagnifier = false,
  6. double magnification = 1.0,
  7. FixedExtentScrollController? scrollController,
  8. double squeeze = _kSqueeze,
  9. required double itemExtent,
  10. required ValueChanged<int>? onSelectedItemChanged,
  11. required NullableIndexedWidgetBuilder itemBuilder,
  12. int? childCount,
  13. Widget? selectionOverlay = const CupertinoPickerDefaultSelectionOverlay(),
})

Creates a picker from an IndexedWidgetBuilder callback where the builder is dynamically invoked during layout.

A child is lazily created when it starts becoming visible in the viewport. All of the children provided by the builder are cached and reused, so normally the builder is only called once for each index (except when rebuilding - the cache is cleared).

The childCount argument reflects the number of children that will be provided by the itemBuilder. If non-null, childCount is the maximum number of children that can be provided, and children are available from 0 to childCount - 1.

If null, then the lower and upper limit are not known. However the builder must provide children for a contiguous segment. If the builder returns null at some index, the segment terminates there.

The itemExtent argument must be positive.

The backgroundColor defaults to null, which disables background painting entirely. (i.e. the picker is going to have a completely transparent background), to match the native UIPicker and UIDatePicker.

Implementation

CupertinoPicker.builder({
  super.key,
  this.diameterRatio = _kDefaultDiameterRatio,
  this.backgroundColor,
  this.offAxisFraction = 0.0,
  this.useMagnifier = false,
  this.magnification = 1.0,
  this.scrollController,
  this.squeeze = _kSqueeze,
  required this.itemExtent,
  required this.onSelectedItemChanged,
  required NullableIndexedWidgetBuilder itemBuilder,
  int? childCount,
  this.selectionOverlay = const CupertinoPickerDefaultSelectionOverlay(),
}) : assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage),
     assert(magnification > 0),
     assert(itemExtent > 0),
     assert(squeeze > 0),
     childDelegate = ListWheelChildBuilderDelegate(builder: itemBuilder, childCount: childCount);