diff --git a/packages/flutter/lib/src/material/tab_controller.dart b/packages/flutter/lib/src/material/tab_controller.dart index 244813a3e88..6390bbd3dc8 100644 --- a/packages/flutter/lib/src/material/tab_controller.dart +++ b/packages/flutter/lib/src/material/tab_controller.dart @@ -115,11 +115,10 @@ class TabController extends ChangeNotifier { /// Creates a new [TabController] with `index`, `previousIndex`, and `length` /// if they are non-null. /// - /// This will reuse the existing [_animationController]. + /// This method is used by [DefaultTabController]. /// - /// This is useful for [DefaultTabController], for example when - /// [DefaultTabController.length] is updated, this method is called so that a - /// new [TabController] is created without having to create a new [AnimationController]. + /// When [DefaultTabController.length] is updated, this method is called to + /// create a new [TabController] without creating a new [AnimationController]. TabController _copyWith({ int index, int length, int previousIndex }) { return TabController._( index: index ?? _index, @@ -138,7 +137,7 @@ class TabController extends ChangeNotifier { /// animation's value can be [offset] by +/- 1.0 to reflect [TabBarView] /// drag scrolling. /// - /// If the TabController was disposed then return null. + /// If this [TabController] was disposed, then return null. Animation get animation => _animationController?.view; AnimationController _animationController; @@ -174,9 +173,10 @@ class TabController extends ChangeNotifier { } } - /// The index of the currently selected tab. Changing the index also updates - /// [previousIndex], sets the [animation]'s value to index, resets - /// [indexIsChanging] to false, and notifies listeners. + /// The index of the currently selected tab. + /// + /// Changing the index also updates [previousIndex], sets the [animation]'s + /// value to index, resets [indexIsChanging] to false, and notifies listeners. /// /// To change the currently selected tab and play the [animation] use [animateTo]. /// @@ -188,7 +188,9 @@ class TabController extends ChangeNotifier { _changeIndex(value); } - /// The index of the previously selected tab. Initially the same as [index]. + /// The index of the previously selected tab. + /// + /// Initially the same as [index]. int get previousIndex => _previousIndex; int _previousIndex; @@ -210,8 +212,9 @@ class TabController extends ChangeNotifier { _changeIndex(value, duration: duration, curve: curve); } - /// The difference between the [animation]'s value and [index]. The offset - /// value must be between -1.0 and 1.0. + /// 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 @@ -313,8 +316,10 @@ class DefaultTabController extends StatefulWidget { assert(initialIndex >= 0 && initialIndex < length), super(key: key); - /// The total number of tabs. Typically greater than one. Must match - /// [TabBar.tabs]'s and [TabBarView.children]'s length. + /// The total number of tabs. + /// + /// Typically greater than one. Must match [TabBar.tabs]'s and + /// [TabBarView.children]'s length. final int length; /// The initial index of the selected tab. diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index b1a109abe00..5bc99f71ba9 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -45,8 +45,10 @@ enum TabBarIndicatorSize { label, } -/// A material design [TabBar] tab. If both [icon] and [text] are -/// provided, the text is displayed below the icon. +/// A material design [TabBar] tab. +/// +/// If both [icon] and [text] are provided, the text is displayed below +/// the icon. /// /// See also: /// @@ -55,9 +57,10 @@ enum TabBarIndicatorSize { /// * [TabController], which coordinates tab selection between a [TabBar] and a [TabBarView]. /// * class Tab extends StatelessWidget { - /// Creates a material design [TabBar] tab. At least one of [text], [icon], - /// and [child] must be non-null. The [text] and [child] arguments must not be - /// used at the same time. + /// Creates a material design [TabBar] tab. + /// + /// At least one of [text], [icon], and [child] must be non-null. The [text] + /// and [child] arguments must not be used at the same time. const Tab({ Key key, this.text, @@ -444,6 +447,18 @@ class _ChangeAnimation extends Animation with AnimationWithParentMixin get parent => controller.animation; + @override + void removeStatusListener(AnimationStatusListener listener) { + if (parent != null) + super.removeStatusListener(listener); + } + + @override + void removeListener(VoidCallback listener) { + if (parent != null) + super.removeListener(listener); + } + @override double get value => _indexChangeProgress(controller); } @@ -459,13 +474,13 @@ class _DragAnimation extends Animation with AnimationWithParentMixin { } } - // Add the tap handler to each tab. If the tab bar is not scrollable + // Add the tap handler to each tab. If the tab bar is not scrollable, // then give all of the tabs equal flexibility so that they each occupy // the same share of the tab bar's overall width. final int tabCount = widget.tabs.length; @@ -1086,7 +1105,9 @@ class _TabBarState extends State { } /// A page view that displays the widget which corresponds to the currently -/// selected tab. Typically used in conjunction with a [TabBar]. +/// selected tab. +/// +/// This widget is typically used in conjunction with a [TabBar]. /// /// If a [TabController] is not provided, then there must be a [DefaultTabController] /// ancestor. @@ -1353,11 +1374,13 @@ class TabPageSelectorIndicator extends StatelessWidget { } } -/// Displays a row of small circular indicators, one per tab. The selected -/// tab's indicator is highlighted. Often used in conjunction with a [TabBarView]. +/// Displays a row of small circular indicators, one per tab. /// -/// If a [TabController] is not provided, then there must be a [DefaultTabController] -/// ancestor. +/// The selected tab's indicator is highlighted. Often used in conjunction with +/// a [TabBarView]. +/// +/// If a [TabController] is not provided, then there must be a +/// [DefaultTabController] ancestor. class TabPageSelector extends StatelessWidget { /// Creates a compact widget that indicates which tab has been selected. const TabPageSelector({ @@ -1371,8 +1394,8 @@ class TabPageSelector extends StatelessWidget { /// This widget's selection and animation state. /// - /// If [TabController] is not provided, then the value of [DefaultTabController.of] - /// will be used. + /// If [TabController] is not provided, then the value of + /// [DefaultTabController.of] will be used. final TabController controller; /// The indicator circle's diameter (the default value is 12.0). @@ -1380,13 +1403,13 @@ class TabPageSelector extends StatelessWidget { /// The indicator circle's fill color for unselected pages. /// - /// If this parameter is null then the indicator is filled with [Colors.transparent]. + /// If this parameter is null, then the indicator is filled with [Colors.transparent]. final Color color; /// The indicator circle's fill color for selected pages and border color /// for all indicator circles. /// - /// If this parameter is null then the indicator is filled with the theme's + /// If this parameter is null, then the indicator is filled with the theme's /// accent color, [ThemeData.accentColor]. final Color selectedColor;