Skip to main content

TickerMode

Struct TickerMode 

Source
pub struct TickerMode {
    pub key: Option<KeyRef>,
    pub enabled: bool,
    pub force_frames: bool,
    pub child: WidgetRef,
}
Expand description

Enables or disables tickers (and thus animation controllers) in the widget subtree.

This only works if AnimationController objects are created using widget-aware ticker providers. For example, using a TickerProviderStateMixin or a SingleTickerProviderStateMixin.

Fields§

§key: Option<KeyRef>§enabled: bool

The requested ticker mode for this subtree.

The effective ticker mode of this subtree may differ from this value if there is an ancestor TickerMode with this field set to false.

If true and all ancestor TickerModes are also enabled, then tickers in this subtree will tick.

If false, then tickers in this subtree will not tick regardless of any ancestor TickerModes. Animations driven by such tickers are not paused, they just don’t call their callbacks. Time still elapses.

§force_frames: bool

If true, tickers in this subtree will force frames even if frames would normally not be scheduled (e.g. even if the device’s screen is turned off).

Use sparingly as this will cause significantly higher battery usage when the device should be idle.

§child: WidgetRef

The widget below this widget in the tree.

Implementations§

Source§

impl TickerMode

Source

pub fn new<K>(enabled: bool, child: impl IntoWidget<K>) -> TickerMode

Creates a TickerMode; Dart’s optional named arguments are the setters.

Source

pub fn key(self, key: KeyRef) -> TickerMode

Dart TickerMode(key:).

Source

pub fn force_frames(self, force_frames: bool) -> TickerMode

Dart TickerMode(force_frames:).

Source

pub fn of(app: &mut App, context: BuildContext) -> bool

👎Deprecated:

Use TickerMode::values_of to get both enabled and force_frames. This feature was deprecated after v3.35.0-0.0.pre.

Whether tickers in the given subtree should be enabled or disabled.

This is used automatically by TickerProviderStateMixin and SingleTickerProviderStateMixin to decide if their tickers should be enabled or disabled.

In the absence of a TickerMode widget, this function defaults to true.

Typical usage is as follows:

let ticking_enabled = TickerMode::of(app, context);
Source

pub fn get_notifier( app: &App, context: BuildContext, ) -> Rc<dyn ValueListenable<bool>>

👎Deprecated:

Use TickerMode::get_values_notifier to get both enabled and force_frames. This feature was deprecated after v3.35.0-0.0.pre.

Obtains a ValueListenable from the TickerMode surrounding the context, which indicates whether tickers are enabled in the given subtree.

When that TickerMode enables or disables tickers, the listenable notifies its listeners.

While the ValueListenable is stable for the lifetime of the surrounding TickerMode, calling this method does not establish a dependency between the context and the TickerMode and the widget owning the context does not rebuild when the ticker mode changes from true to false or vice versa. This is preferable when the ticker mode does not impact what is currently rendered on screen, e.g. because it is only used to mute/unmute a Ticker. Since no dependency is established, the widget owning the context is also not informed when it is moved to a new location in the tree where it may have a different TickerMode ancestor. When this happens, the widget must manually unsubscribe from the old listenable, obtain a new one from the new ancestor TickerMode by calling this method again, and re-subscribe to it. StatefulWidgets can, for example, do this in State::activate, which is called after the widget has been moved to a new location.

Alternatively, of can be used instead of this method to create a dependency between the provided context and the ancestor TickerMode. In this case, the widget automatically rebuilds when the ticker mode changes or when it is moved to a new TickerMode ancestor, which simplifies the management cost in the widget at the expense of some potential unnecessary rebuilds.

In the absence of a TickerMode widget, this function returns a ValueListenable, whose ValueListenable::value is always true.

Source

pub fn values_of(app: &mut App, context: BuildContext) -> TickerModeData

Returns the requested ticker mode values for this subtree and establishes a dependency on the ancestor TickerMode, if any.

This is used automatically by TickerProviderStateMixin and SingleTickerProviderStateMixin to decide if their tickers should be enabled or disabled.

In the absence of a TickerMode widget, this defaults to enabled tickers that don’t force frames.

Typical usage is as follows:

let ticking_enabled = TickerMode::values_of(app, context).enabled;
Source

pub fn get_values_notifier( app: &App, context: BuildContext, ) -> Rc<dyn ValueListenable<TickerModeData>>

Obtains a ValueListenable from the TickerMode surrounding the context, which indicates whether tickers are enabled in the given subtree.

When that TickerMode enabled or disabled tickers, the listenable notifies its listeners.

While the ValueListenable is stable for the lifetime of the surrounding TickerMode, calling this method does not establish a dependency between the context and the TickerMode and the widget owning the context does not rebuild when the ticker mode data changes. This is preferable when the ticker mode does not impact what is currently rendered on screen, e.g. because it is only used to mute/unmute a Ticker. Since no dependency is established, the widget owning the context is also not informed when it is moved to a new location in the tree where it may have a different TickerMode ancestor. When this happens, the widget must manually unsubscribe from the old listenable, obtain a new one from the new ancestor TickerMode by calling this method again, and re-subscribe to it. StatefulWidgets can, for example, do this in State::activate, which is called after the widget has been moved to a new location.

Alternatively, of can be used instead of this method to create a dependency between the provided context and the ancestor TickerMode. In this case, the widget automatically rebuilds when the ticker mode changes or when it is moved to a new TickerMode ancestor, which simplifies the management cost in the widget at the expensive of some potential unnecessary rebuilds.

In the absence of a TickerMode widget, this function returns a ValueListenable, whose ValueListenable::value is TickerModeData::FALLBACK.

Every call wraps the ancestor’s notifier anew: two results for the same TickerMode are not Rc::ptr_eq, though they notify from the same object.

Trait Implementations§

Source§

impl Debug for TickerMode

Source§

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

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

impl StatefulWidget for TickerMode

Source§

type State = TickerModeState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn create_state(&self) -> TickerModeState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for TickerMode

§

impl !Send for TickerMode

§

impl !Sync for TickerMode

§

impl !UnwindSafe for TickerMode

§

impl Forget for TickerMode

§

impl Freeze for TickerMode
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for TickerMode

§

impl Unpin for TickerMode
where Rc<dyn Key>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for TickerMode
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: 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> 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<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

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

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>