Commit 8469ef03 authored by Ian Hickson's avatar Ian Hickson Committed by Adam Barth

Trivial tabs-related fixes (#9191)

Add some commentary around DefaultTabController.initialIndex.
Fix typo (nuull) in TabBar.
Make some asserts more detailed.
parent fbcade59
...@@ -221,6 +221,8 @@ class DefaultTabController extends StatefulWidget { ...@@ -221,6 +221,8 @@ class DefaultTabController extends StatefulWidget {
/// Creates a default tab controller for the given [child] widget. /// Creates a default tab controller for the given [child] widget.
/// ///
/// The [length] argument must be great than one. /// The [length] argument must be great than one.
///
/// The [initialIndex] argument must not be null.
DefaultTabController({ DefaultTabController({
Key key, Key key,
@required this.length, @required this.length,
...@@ -232,6 +234,8 @@ class DefaultTabController extends StatefulWidget { ...@@ -232,6 +234,8 @@ class DefaultTabController extends StatefulWidget {
final int length; final int length;
/// The initial index of the selected tab. /// The initial index of the selected tab.
///
/// Defaults to zero.
final int initialIndex; final int initialIndex;
/// This widget's child. Often a [Scaffold] whose [AppBar] includes a [TabBar]. /// This widget's child. Often a [Scaffold] whose [AppBar] includes a [TabBar].
......
...@@ -353,7 +353,7 @@ class _DragAnimation extends Animation<double> with AnimationWithParentMixin<dou ...@@ -353,7 +353,7 @@ class _DragAnimation extends Animation<double> with AnimationWithParentMixin<dou
class TabBar extends StatefulWidget implements AppBarBottomWidget { class TabBar extends StatefulWidget implements AppBarBottomWidget {
/// Creates a material design tab bar. /// Creates a material design tab bar.
/// ///
/// The [tabs] argument must not be nuull and must have more than one widget. /// The [tabs] argument must not be null and must have more than one widget.
/// ///
/// If a [TabController] is not provided, then there must be a /// If a [TabController] is not provided, then there must be a
/// [DefaultTabController] ancestor. /// [DefaultTabController] ancestor.
...@@ -446,6 +446,18 @@ class _TabBarState extends State<TabBar> { ...@@ -446,6 +446,18 @@ class _TabBarState extends State<TabBar> {
void _updateTabController() { void _updateTabController() {
final TabController newController = config.controller ?? DefaultTabController.of(context); final TabController newController = config.controller ?? DefaultTabController.of(context);
assert(() {
if (newController == null) {
throw new FlutterError(
'No TabController for ${config.runtimeType}.\n'
'When creating a ${config.runtimeType}, you must either provide an explicit '
'TabController using the "controller" property, or you must ensure that there '
'is a DefaultTabController above the ${config.runtimeType}.\n'
'In this case, there was neither an explicit controller nor a default controller.'
);
}
return true;
});
if (newController == _controller) if (newController == _controller)
return; return;
...@@ -700,6 +712,18 @@ class _TabBarViewState extends State<TabBarView> { ...@@ -700,6 +712,18 @@ class _TabBarViewState extends State<TabBarView> {
void _updateTabController() { void _updateTabController() {
final TabController newController = config.controller ?? DefaultTabController.of(context); final TabController newController = config.controller ?? DefaultTabController.of(context);
assert(() {
if (newController == null) {
throw new FlutterError(
'No TabController for ${config.runtimeType}.\n'
'When creating a ${config.runtimeType}, you must either provide an explicit '
'TabController using the "controller" property, or you must ensure that there '
'is a DefaultTabController above the ${config.runtimeType}.\n'
'In this case, there was neither an explicit controller nor a default controller.'
);
}
return true;
});
if (newController == _controller) if (newController == _controller)
return; return;
...@@ -876,7 +900,18 @@ class TabPageSelector extends StatelessWidget { ...@@ -876,7 +900,18 @@ class TabPageSelector extends StatelessWidget {
final ColorTween selectedColor = new ColorTween(begin: Colors.transparent, end: color); final ColorTween selectedColor = new ColorTween(begin: Colors.transparent, end: color);
final ColorTween previousColor = new ColorTween(begin: color, end: Colors.transparent); final ColorTween previousColor = new ColorTween(begin: color, end: Colors.transparent);
final TabController tabController = controller ?? DefaultTabController.of(context); final TabController tabController = controller ?? DefaultTabController.of(context);
assert(tabController != null); assert(() {
if (tabController == null) {
throw new FlutterError(
'No TabController for $runtimeType.\n'
'When creating a $runtimeType, you must either provide an explicit TabController '
'using the "controller" property, or you must ensure that there is a '
'DefaultTabController above the $runtimeType.\n'
'In this case, there was neither an explicit controller nor a default controller.'
);
}
return true;
});
final Animation<double> animation = new CurvedAnimation( final Animation<double> animation = new CurvedAnimation(
parent: tabController.animation, parent: tabController.animation,
curve: Curves.fastOutSlowIn, curve: Curves.fastOutSlowIn,
......
...@@ -9,7 +9,9 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -9,7 +9,9 @@ import 'package:flutter_test/flutter_test.dart';
Widget buildSliverAppBarApp({ bool floating, bool pinned, double expandedHeight }) { Widget buildSliverAppBarApp({ bool floating, bool pinned, double expandedHeight }) {
return new Scaffold( return new Scaffold(
body: new CustomScrollView( body: new DefaultTabController(
length: 3,
child: new CustomScrollView(
primary: true, primary: true,
slivers: <Widget>[ slivers: <Widget>[
new SliverAppBar( new SliverAppBar(
...@@ -29,6 +31,7 @@ Widget buildSliverAppBarApp({ bool floating, bool pinned, double expandedHeight ...@@ -29,6 +31,7 @@ Widget buildSliverAppBarApp({ bool floating, bool pinned, double expandedHeight
), ),
], ],
), ),
),
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment