Skip to main content

TabController

Struct TabController 

Source
pub struct TabController {
    pub length: usize,
    /* private fields */
}
Expand description

Coordinates tab selection between a TabBar and a TabBarView.

The index property is the index of the selected tab and the animation represents the current scroll positions of the tab bar and the tab bar view. The selected tab’s index can be changed with animate_to.

A stateful widget that builds a TabBar or a TabBarView can create a TabController and share it directly.

When the TabBar and TabBarView don’t have a convenient stateful ancestor, a TabController can be shared by providing a DefaultTabController inherited widget.

A disposed controller stays in the arena, as a Dart object outlives its dispose while something still holds it: a TabBar rebuilt with a new controller reads the old one’s animation, None, to learn it was disposed. It is freed once nothing holds it.

Fields§

§length: usize

The total number of tabs.

Typically greater than one. Must match TabBar::tabs’s and TabBarView::children’s length.

Implementations§

Source§

impl TabController

Source

pub fn new( app: &mut App, initial_index: usize, animation_duration: Option<Duration>, length: usize, vsync: impl TickerProvider, ) -> Ref<TabController>

Creates an object that manages the state required by TabBar and a TabBarView.

The length is typically a value greater than one, i.e. typically there are two or more tabs. The length must match TabBar::tabs’s and TabBarView::children’s length.

The initial_index must be valid given length. If length is zero, then initial_index must be 0 (Dart’s default).

Source

pub fn animation(self: Handle<Self>, app: &App) -> Option<AnyAnimation<f64>>

An animation whose value represents the current position of the TabBar’s selected tab indicator as well as the scrollOffsets of the TabBar and TabBarView.

The animation’s value ranges from 0.0 to length - 1.0. After the selected tab is changed, the animation’s value equals index. The animation’s value can be offset by +/- 1.0 to reflect TabBarView drag scrolling.

If this TabController was disposed, then return None.

Source

pub fn animation_duration(self: Handle<Self>, app: &App) -> Duration

Controls the duration of TabController and TabBarView animations.

Defaults to K_TAB_SCROLL_DURATION.

Source

pub fn length(self: Handle<Self>, app: &App) -> usize

The total number of tabs; see length.

Source

pub fn index(self: Handle<Self>, app: &App) -> usize

The index of the currently selected tab.

Changing the index also updates previous_index, sets the animation’s value to index, resets index_is_changing to false, and notifies listeners.

To change the currently selected tab and play the animation use animate_to.

The value of index must be valid given length. If length is zero, then index will also be zero.

Source

pub fn set_index(self: Handle<Self>, app: &mut App, value: usize)

Sets index.

Source

pub fn previous_index(self: Handle<Self>, app: &App) -> usize

The index of the previously selected tab.

Initially the same as index.

Source

pub fn index_is_changing(self: Handle<Self>, app: &App) -> bool

True while we’re animating from previous_index to index as a consequence of calling animate_to.

This value is true during the animate_to animation that’s triggered when the user taps a TabBar tab. It is false when offset is changing as a consequence of the user dragging (and “flinging”) the TabBarView.

Source

pub fn animate_to( self: Handle<Self>, app: &mut App, value: usize, duration: Option<Duration>, curve: Option<Rc<dyn Curve>>, )

Immediately sets index and previous_index and then plays the animation from its current value to index.

While the animation is running index_is_changing is true. When the animation completes offset will be 0.0.

Dart’s defaults: duration the controller’s animation_duration, curve Curves::ease().

Source

pub fn offset(self: Handle<Self>, app: &App) -> f64

The difference between the animation’s value and index.

The offset value must be between -1.0 and 1.0.

This property is typically set by the TabBarView when the user drags left or right. A value between -1.0 and 0.0 implies that the TabBarView has been dragged to the left. Similarly a value between 0.0 and 1.0 implies that the TabBarView has been dragged to the right.

Source

pub fn set_offset(self: Handle<Self>, app: &mut App, value: f64)

Sets offset.

Source

pub fn dispose(self: Handle<Self>, app: &mut App)

Discards the controller’s animation; Dart’s dispose.

The disposed animation controller lives on, as Dart’s outlives its dispose: a tab bar’s indicator painter and its tabs’ animations still hold it, and take their listeners off it only when they are replaced.

Trait Implementations§

Source§

impl ChangeNotifier for TabController

Source§

fn change_notifier_data(&self) -> &ChangeNotifierData

Source§

fn change_notifier_data_mut(&mut self) -> &mut ChangeNotifierData

Source§

fn will_add_listener(self: Handle<Self>, app: &mut App)

Runs before the listener is stored. Dart overrides of addListener that work before super.addListener go here.
Source§

fn did_remove_listener(self: Handle<Self>, app: &mut App)

Runs after the listener is removed. Dart overrides of removeListener that work after super.removeListener go here.

Auto Trait Implementations§

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<T> ListenableObject for T
where T: ChangeNotifier,

Source§

fn add_listener(self: Handle<T>, app: &mut App, listener: Listener)

Register a closure to be called when the object notifies its listeners.
Source§

fn remove_listener(self: Handle<T>, app: &mut App, listener: &Listener)

Remove a previously registered closure from the list of closures that the object notifies.
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>