CupertinoPicker.builder constructor Null safety

  1. {Key? key,
  2. double diameterRatio,
  3. Color? backgroundColor,
  4. double offAxisFraction,
  5. bool useMagnifier,
  6. double magnification,
  7. FixedExtentScrollController? scrollController,
  8. double squeeze,
  9. required double itemExtent,
  10. required ValueChanged<int>? onSelectedItemChanged,
  11. required NullableIndexedWidgetBuilder itemBuilder,
  12. int? childCount,
  13. Widget? selectionOverlay}

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 itemBuilder argument must not be null. 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 non-null and 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.


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