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: usizeThe total number of tabs.
Typically greater than one. Must match TabBar::tabs’s and
TabBarView::children’s length.
Implementations§
Source§impl TabController
impl TabController
Sourcepub fn new(
app: &mut App,
initial_index: usize,
animation_duration: Option<Duration>,
length: usize,
vsync: impl TickerProvider,
) -> Ref<TabController>
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).
Sourcepub fn animation(self: Handle<Self>, app: &App) -> Option<AnyAnimation<f64>>
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.
Sourcepub fn animation_duration(self: Handle<Self>, app: &App) -> Duration
pub fn animation_duration(self: Handle<Self>, app: &App) -> Duration
Controls the duration of TabController and TabBarView animations.
Defaults to K_TAB_SCROLL_DURATION.
Sourcepub fn index(self: Handle<Self>, app: &App) -> usize
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.
Sourcepub fn previous_index(self: Handle<Self>, app: &App) -> usize
pub fn previous_index(self: Handle<Self>, app: &App) -> usize
The index of the previously selected tab.
Initially the same as index.
Sourcepub fn index_is_changing(self: Handle<Self>, app: &App) -> bool
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.
Sourcepub fn animate_to(
self: Handle<Self>,
app: &mut App,
value: usize,
duration: Option<Duration>,
curve: Option<Rc<dyn Curve>>,
)
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().
Sourcepub fn offset(self: Handle<Self>, app: &App) -> f64
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.
Sourcepub fn dispose(self: Handle<Self>, app: &mut App)
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
impl ChangeNotifier for TabController
fn change_notifier_data(&self) -> &ChangeNotifierData
fn change_notifier_data_mut(&mut self) -> &mut ChangeNotifierData
Source§fn will_add_listener(self: Handle<Self>, app: &mut App)
fn will_add_listener(self: Handle<Self>, app: &mut App)
addListener that
work before super.addListener go here.Source§fn did_remove_listener(self: Handle<Self>, app: &mut App)
fn did_remove_listener(self: Handle<Self>, app: &mut App)
removeListener that
work after super.removeListener go here.