pub struct ListenableBuilder {
pub key: Option<KeyRef>,
pub listenable: Rc<dyn Listenable>,
pub builder: TransitionBuilder,
pub child: Option<WidgetRef>,
}Expand description
A general-purpose widget for building a widget subtree when a Listenable changes.
ListenableBuilder is useful for more complex widgets that wish to listen to changes in
other objects as part of a larger build function. To use ListenableBuilder, construct
the widget and pass it a builder function.
Any subtype of Listenable (such as a ChangeNotifier, ValueNotifier, or Animation)
can be used with a ListenableBuilder to rebuild only certain parts of a widget when
the Listenable notifies its listeners. Although they have identical implementations, if
an Animation is being listened to, consider using an AnimatedBuilder instead for
better readability.
§Performance optimizations
If the builder function contains a subtree that does not depend on the
listenable, it is more efficient to build that subtree once instead
of rebuilding it on every change of the listenable.
Performance is optimized by building the subtree once and passing it as the
child; the builder receives it as its third argument.
Fields§
§key: Option<KeyRef>§listenable: Rc<dyn Listenable>The Listenable supplied to the constructor.
Also accessible through animation for an AnimatedBuilder.
builder: TransitionBuilderCalled every time the listenable notifies about a change.
The child given to the builder should typically be part of the returned widget tree.
child: Option<WidgetRef>The child widget to pass to the builder.
If a builder callback’s return value contains a subtree that does
not depend on the listenable, it’s more efficient to build that subtree once instead
of rebuilding it on every change of the listenable.
If the pre-built subtree is passed as the child parameter, the
ListenableBuilder will pass it back to the builder function so
that it can be incorporated into the build.
Using this pre-built child is entirely optional, but can improve performance significantly in some cases and is therefore a good practice.
Implementations§
Source§impl ListenableBuilder
impl ListenableBuilder
Sourcepub fn new(
listenable: Rc<dyn Listenable>,
builder: impl Fn(&mut App, BuildContext, Option<&WidgetRef>) -> WidgetRef + 'static,
) -> ListenableBuilder
pub fn new( listenable: Rc<dyn Listenable>, builder: impl Fn(&mut App, BuildContext, Option<&WidgetRef>) -> WidgetRef + 'static, ) -> ListenableBuilder
Creates a builder that responds to changes in listenable.
Sourcepub fn key(self, key: KeyRef) -> ListenableBuilder
pub fn key(self, key: KeyRef) -> ListenableBuilder
Dart ListenableBuilder(key:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> ListenableBuilder
pub fn child<K>(self, child: impl IntoWidget<K>) -> ListenableBuilder
Dart ListenableBuilder(child:).
Sourcepub fn animation(&self) -> Rc<dyn Listenable>
pub fn animation(&self) -> Rc<dyn Listenable>
The Listenable supplied to the constructor (Dart’s AnimatedBuilder.animation).
Trait Implementations§
Source§impl AnimatedWidget for ListenableBuilder
impl AnimatedWidget for ListenableBuilder
Source§fn listenable(&self) -> Rc<dyn Listenable>
fn listenable(&self) -> Rc<dyn Listenable>
Listenable to which this widget is listening. Read moreSource§fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
Source§fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
AnimatedWidget.debugFillProperties, which a subclass’s own body calls where
Dart writes super.Auto Trait Implementations§
impl !RefUnwindSafe for ListenableBuilder
impl !Send for ListenableBuilder
impl !Sync for ListenableBuilder
impl !UnwindSafe for ListenableBuilder
impl Forget for ListenableBuilder
impl Freeze for ListenableBuilderwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn Listenable> is !null: Freeze,
PhantomData<RcInner<dyn Listenable>>: Freeze,
*const RcInner<dyn Fn(&mut App, AnyElement, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>>>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for ListenableBuilder
impl Unpin for ListenableBuilder
impl UnsafeUnpin for ListenableBuilderwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Listenable> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Listenable>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, AnyElement, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>>>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<AnimatedKind> for Wwhere
W: AnimatedWidget,
impl<W> IntoWidget<AnimatedKind> for Wwhere
W: AnimatedWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.