Skip to main content

SliverChildBuilderDelegate

Struct SliverChildBuilderDelegate 

Source
pub struct SliverChildBuilderDelegate {
    pub builder: NullableIndexedWidgetBuilder,
    pub child_count: Option<i32>,
    pub add_automatic_keep_alives: bool,
    pub add_repaint_boundaries: bool,
    pub add_semantic_indexes: bool,
    pub semantic_index_offset: i32,
    pub semantic_index_callback: SemanticIndexCallback,
    pub find_child_index_callback: Option<ChildIndexGetter>,
}
Expand description

A delegate that supplies children for slivers using a builder callback.

Many slivers lazily construct their box children to avoid creating more children than are visible through the Viewport. This delegate provides children using a NullableIndexedWidgetBuilder callback, so that the children do not even have to be built until they are displayed.

The widgets returned from the builder callback are automatically wrapped in AutomaticKeepAlive widgets if add_automatic_keep_alives is true (the default) and in RepaintBoundary widgets if add_repaint_boundaries is true (also the default).

§Accessibility

CustomScrollView requires that its semantic children are annotated using IndexedSemantics. This is done by default in the delegate with the add_semantic_indexes parameter set to true.

If multiple delegates are used in a single scroll view, then the indexes will not be correct by default. The semantic_index_offset can be used to offset the semantic indexes of each delegate so that the indexes are monotonically increasing. For example, if a scroll view contains two delegates where the first has 10 children contributing semantics, then the second delegate should offset its children by 10.

In certain cases, only a subset of child widgets should be annotated with a semantic index. For example, in ListView.separated the separators do not have an index associated with them. This is done by providing a semantic_index_callback which returns None for separators indexes and rounds the non-separator indexes down by half.

See also:

Fields§

§builder: NullableIndexedWidgetBuilder

Called to build children for the sliver.

Will be called only for indices greater than or equal to zero and less than child_count (if it is non-None).

Should return None if asked to build a widget with a greater index than exists.

May result in an infinite loop or run out of memory if child_count is None and the builder always provides a zero-size widget (such as SizedBox::shrink()). If possible, provide children with non-zero size, return None from the builder, or set a child_count.

The delegate wraps the children returned by this builder in RepaintBoundary widgets.

§child_count: Option<i32>

The total number of children this delegate can provide.

If None, the number of children is determined by the least index for which builder returns None.

May result in an infinite loop or run out of memory if it is None and the builder always provides a zero-size widget. If possible, provide children with non-zero size, return None from the builder, or set a child count.

§add_automatic_keep_alives: bool

Whether to wrap each child in an AutomaticKeepAlive.

Typically, lazily laid out children are wrapped in AutomaticKeepAlive widgets so that the children can use KeepAliveNotifications to preserve their state when they would otherwise be garbage collected off-screen.

This feature (and add_repaint_boundaries) must be disabled if the children are going to manually maintain their KeepAlive state. It may also be more efficient to disable this feature if it is known ahead of time that none of the children will ever try to keep themselves alive.

Defaults to true.

§add_repaint_boundaries: bool

Whether to wrap each child in a RepaintBoundary.

Typically, children in a scrolling container are wrapped in repaint boundaries so that they do not need to be repainted as the list scrolls. If the children are easy to repaint (e.g., solid color blocks or a short snippet of text), it might be more efficient to not add a repaint boundary and instead always repaint the children during scrolling.

Defaults to true.

§add_semantic_indexes: bool

Whether to wrap each child in an IndexedSemantics.

Typically, children in a scrolling container must be annotated with a semantic index in order to generate the correct accessibility announcements. This should only be set to false if the indexes have already been provided by an IndexedSemantics widget.

Defaults to true.

§semantic_index_offset: i32

An initial offset to add to the semantic indexes generated by this widget.

Defaults to zero.

§semantic_index_callback: SemanticIndexCallback

A SemanticIndexCallback which is used when add_semantic_indexes is true.

Defaults to providing an index for each widget.

§find_child_index_callback: Option<ChildIndexGetter>

Called to find the new index of a child based on its key in case of reordering.

If not provided, a child widget may not map to its existing RenderObject when the order of children returned from the children builder changes. This may result in state-loss.

This callback should take an input Key, and it should return the index of the child element with that associated key, or None if not found.

Implementations§

Source§

impl SliverChildBuilderDelegate

Source

pub fn new( builder: impl Fn(&mut App, BuildContext, i32) -> Option<WidgetRef> + 'static, ) -> SliverChildBuilderDelegate

Creates a delegate that supplies children for slivers using the given builder callback.

If the order in which the builder returns children ever changes, consider providing a find_child_index_callback. This allows the delegate to find the new index for a child that was previously located at a different index to attach the existing state to the widget at its new location.

Source

pub fn from_builder( builder: NullableIndexedWidgetBuilder, ) -> SliverChildBuilderDelegate

Creates the delegate from a shared builder, which the builder constructors of the sliver widgets pass on.

Source

pub fn child_count(self, child_count: i32) -> SliverChildBuilderDelegate

Dart SliverChildBuilderDelegate(childCount:).

Source

pub fn add_automatic_keep_alives( self, value: bool, ) -> SliverChildBuilderDelegate

Dart SliverChildBuilderDelegate(addAutomaticKeepAlives:).

Source

pub fn add_repaint_boundaries(self, value: bool) -> SliverChildBuilderDelegate

Dart SliverChildBuilderDelegate(addRepaintBoundaries:).

Source

pub fn add_semantic_indexes(self, value: bool) -> SliverChildBuilderDelegate

Dart SliverChildBuilderDelegate(addSemanticIndexes:).

Source

pub fn semantic_index_offset(self, value: i32) -> SliverChildBuilderDelegate

Dart SliverChildBuilderDelegate(semanticIndexOffset:).

Source

pub fn semantic_index_callback( self, value: SemanticIndexCallback, ) -> SliverChildBuilderDelegate

Dart SliverChildBuilderDelegate(semanticIndexCallback:).

Source

pub fn find_child_index_callback( self, value: ChildIndexGetter, ) -> SliverChildBuilderDelegate

Dart SliverChildBuilderDelegate(findChildIndexCallback:).

Source

pub fn into_delegate(self) -> SliverChildDelegateRef

The delegate as the shared reference a sliver widget takes.

Trait Implementations§

Source§

impl Clone for SliverChildBuilderDelegate

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SliverChildBuilderDelegate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SliverChildDelegate for SliverChildBuilderDelegate

Source§

fn find_index_by_key(&self, key: &KeyRef) -> Option<i32>

Find index of child element with associated key. Read more
Source§

fn build( &self, app: &mut App, context: BuildContext, index: i32, ) -> Option<WidgetRef>

Returns the child with the given index. Read more
Source§

fn estimated_child_count(&self) -> Option<i32>

Returns an estimate of the number of children this delegate will build. Read more
Source§

fn should_rebuild(&self, old_delegate: &dyn SliverChildDelegate) -> bool

Called whenever a new instance of the child delegate class is provided to the sliver. Read more
Source§

fn as_any(&self) -> &dyn Any

The concrete delegate, for Dart’s oldDelegate as Foo.
Source§

fn estimate_max_scroll_offset( &self, first_index: i32, last_index: i32, leading_scroll_offset: f64, trailing_scroll_offset: f64, ) -> Option<f64>

Returns an estimate of the max scroll extent for all the children. Read more
Source§

fn did_finish_layout(&self, first_index: i32, last_index: i32)

Called at the end of layout to indicate that layout is now complete. Read more
Source§

fn delegate_type(&self) -> TypeId

The concrete delegate’s type, Dart’s runtimeType.
Source§

fn debug_fill_description(&self, description: &mut Vec<String>)

Add additional information to the given description for use by toString.

Auto Trait Implementations§

§

impl !RefUnwindSafe for SliverChildBuilderDelegate

§

impl !Send for SliverChildBuilderDelegate

§

impl !Sync for SliverChildBuilderDelegate

§

impl !UnwindSafe for SliverChildBuilderDelegate

§

impl Forget for SliverChildBuilderDelegate

§

impl Freeze for SliverChildBuilderDelegate
where *const RcInner<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>>>: Freeze, *const RcInner<dyn Fn(&Rc<dyn Widget>, i32) -> Option<i32>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&Rc<dyn Widget>, i32) -> Option<i32>>>: Freeze, *const RcInner<dyn Fn(&KeyRef) -> Option<i32>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&KeyRef) -> Option<i32>>>: Freeze,

§

impl Move for SliverChildBuilderDelegate

§

impl Unpin for SliverChildBuilderDelegate
where Rc<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>>: Unpin, Rc<dyn Fn(&Rc<dyn Widget>, i32) -> Option<i32>>: Unpin, Rc<dyn Fn(&KeyRef) -> Option<i32>>: Unpin,

§

impl UnsafeUnpin for SliverChildBuilderDelegate
where *const RcInner<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, i32) -> Option<Rc<dyn Widget>>>>: UnsafeUnpin, *const RcInner<dyn Fn(&Rc<dyn Widget>, i32) -> Option<i32>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&Rc<dyn Widget>, i32) -> Option<i32>>>: UnsafeUnpin, *const RcInner<dyn Fn(&KeyRef) -> Option<i32>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&KeyRef) -> Option<i32>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>