Skip to content

Commit

Permalink
Tab Animation Sample Video (#32177)
Browse files Browse the repository at this point in the history
* Improve tabs documentation regarding matching lengths

* Add Tabs animation to docs
  • Loading branch information
Shi-Hao Hong committed May 13, 2019
1 parent c4d5271 commit 9545c5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
28 changes: 23 additions & 5 deletions packages/flutter/lib/src/material/tab_controller.dart
Expand Up @@ -21,6 +21,8 @@ import 'constants.dart';
/// ancestor, a [TabController] can be shared by providing a
/// [DefaultTabController] inherited widget.
///
/// {@animation 700 540 https://flutter.github.io/assets-for-api-docs/assets/material/tabs.mp4}
///
/// {@tool sample}
///
/// This widget introduces a [Scaffold] with an [AppBar] and a [TabBar].
Expand Down Expand Up @@ -64,7 +66,13 @@ import 'constants.dart';
/// body: TabBarView(
/// controller: _tabController,
/// children: myTabs.map((Tab tab) {
/// return Center(child: Text(tab.text));
/// final String label = tab.text.toLowerCase();
/// return Center(
/// child: Text(
/// 'This is the $label tab',
/// style: const TextStyle(fontSize: 36),
/// ),
/// );
/// }).toList(),
/// ),
/// );
Expand All @@ -76,7 +84,7 @@ class TabController extends ChangeNotifier {
/// Creates an object that manages the state required by [TabBar] and a
/// [TabBarView].
///
/// The [length] must not be null or negative. Typically its a value greater
/// The [length] must not be null or negative. Typically it's 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.
///
Expand Down Expand Up @@ -134,8 +142,10 @@ class TabController extends ChangeNotifier {
Animation<double> get animation => _animationController?.view;
AnimationController _animationController;

/// 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;

void _changeIndex(int value, { Duration duration, Curve curve }) {
Expand Down Expand Up @@ -251,6 +261,8 @@ class _TabControllerScope extends InheritedWidget {
/// widgets are created by a stateless parent widget or by different parent
/// widgets.
///
/// {@animation 700 540 https://flutter.github.io/assets-for-api-docs/assets/material/tabs.mp4}
///
/// ```dart
/// class MyDemo extends StatelessWidget {
/// final List<Tab> myTabs = <Tab>[
Expand All @@ -270,7 +282,13 @@ class _TabControllerScope extends InheritedWidget {
/// ),
/// body: TabBarView(
/// children: myTabs.map((Tab tab) {
/// return Center(child: Text(tab.text));
/// final String label = tab.text.toLowerCase();
/// return Center(
/// child: Text(
/// 'This is the $label tab',
/// style: const TextStyle(fontSize: 36),
/// ),
/// );
/// }).toList(),
/// ),
/// ),
Expand Down
4 changes: 3 additions & 1 deletion packages/flutter/lib/src/material/tabs.dart
Expand Up @@ -1115,7 +1115,9 @@ class TabBarView extends StatefulWidget {
/// will be used.
final TabController controller;

/// One widget per tab. Its length must match the length of the [TabBar.tabs]
/// One widget per tab.
///
/// Its length must match the length of the [TabBar.tabs]
/// list, as well as the [controller]'s [TabController.length].
final List<Widget> children;

Expand Down

0 comments on commit 9545c5d

Please sign in to comment.