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:
SliverChildListDelegate, which is a delegate that has an explicit list of children.
Fields§
§builder: NullableIndexedWidgetBuilderCalled 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: boolWhether 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: boolWhether 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: boolWhether 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: i32An initial offset to add to the semantic indexes generated by this widget.
Defaults to zero.
semantic_index_callback: SemanticIndexCallbackA 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
impl SliverChildBuilderDelegate
Sourcepub fn new(
builder: impl Fn(&mut App, BuildContext, i32) -> Option<WidgetRef> + 'static,
) -> SliverChildBuilderDelegate
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.
Sourcepub fn from_builder(
builder: NullableIndexedWidgetBuilder,
) -> SliverChildBuilderDelegate
pub fn from_builder( builder: NullableIndexedWidgetBuilder, ) -> SliverChildBuilderDelegate
Creates the delegate from a shared builder, which the builder constructors of the
sliver widgets pass on.
Sourcepub fn child_count(self, child_count: i32) -> SliverChildBuilderDelegate
pub fn child_count(self, child_count: i32) -> SliverChildBuilderDelegate
Dart SliverChildBuilderDelegate(childCount:).
Sourcepub fn add_automatic_keep_alives(
self,
value: bool,
) -> SliverChildBuilderDelegate
pub fn add_automatic_keep_alives( self, value: bool, ) -> SliverChildBuilderDelegate
Dart SliverChildBuilderDelegate(addAutomaticKeepAlives:).
Sourcepub fn add_repaint_boundaries(self, value: bool) -> SliverChildBuilderDelegate
pub fn add_repaint_boundaries(self, value: bool) -> SliverChildBuilderDelegate
Dart SliverChildBuilderDelegate(addRepaintBoundaries:).
Sourcepub fn add_semantic_indexes(self, value: bool) -> SliverChildBuilderDelegate
pub fn add_semantic_indexes(self, value: bool) -> SliverChildBuilderDelegate
Dart SliverChildBuilderDelegate(addSemanticIndexes:).
Sourcepub fn semantic_index_offset(self, value: i32) -> SliverChildBuilderDelegate
pub fn semantic_index_offset(self, value: i32) -> SliverChildBuilderDelegate
Dart SliverChildBuilderDelegate(semanticIndexOffset:).
Sourcepub fn semantic_index_callback(
self,
value: SemanticIndexCallback,
) -> SliverChildBuilderDelegate
pub fn semantic_index_callback( self, value: SemanticIndexCallback, ) -> SliverChildBuilderDelegate
Dart SliverChildBuilderDelegate(semanticIndexCallback:).
Sourcepub fn find_child_index_callback(
self,
value: ChildIndexGetter,
) -> SliverChildBuilderDelegate
pub fn find_child_index_callback( self, value: ChildIndexGetter, ) -> SliverChildBuilderDelegate
Dart SliverChildBuilderDelegate(findChildIndexCallback:).
Sourcepub fn into_delegate(self) -> SliverChildDelegateRef
pub fn into_delegate(self) -> SliverChildDelegateRef
The delegate as the shared reference a sliver widget takes.
Trait Implementations§
Source§impl Clone for SliverChildBuilderDelegate
impl Clone for SliverChildBuilderDelegate
Source§impl Debug for SliverChildBuilderDelegate
impl Debug for SliverChildBuilderDelegate
Source§impl SliverChildDelegate for SliverChildBuilderDelegate
impl SliverChildDelegate for SliverChildBuilderDelegate
Source§fn find_index_by_key(&self, key: &KeyRef) -> Option<i32>
fn find_index_by_key(&self, key: &KeyRef) -> Option<i32>
Source§fn build(
&self,
app: &mut App,
context: BuildContext,
index: i32,
) -> Option<WidgetRef>
fn build( &self, app: &mut App, context: BuildContext, index: i32, ) -> Option<WidgetRef>
Source§fn estimated_child_count(&self) -> Option<i32>
fn estimated_child_count(&self) -> Option<i32>
Source§fn should_rebuild(&self, old_delegate: &dyn SliverChildDelegate) -> bool
fn should_rebuild(&self, old_delegate: &dyn SliverChildDelegate) -> bool
Source§fn estimate_max_scroll_offset(
&self,
first_index: i32,
last_index: i32,
leading_scroll_offset: f64,
trailing_scroll_offset: f64,
) -> Option<f64>
fn estimate_max_scroll_offset( &self, first_index: i32, last_index: i32, leading_scroll_offset: f64, trailing_scroll_offset: f64, ) -> Option<f64>
Source§fn did_finish_layout(&self, first_index: i32, last_index: i32)
fn did_finish_layout(&self, first_index: i32, last_index: i32)
Source§fn delegate_type(&self) -> TypeId
fn delegate_type(&self) -> TypeId
runtimeType.Source§fn debug_fill_description(&self, description: &mut Vec<String>)
fn debug_fill_description(&self, description: &mut Vec<String>)
toString.