diff --git a/packages/flutter/lib/src/material/tab_controller.dart b/packages/flutter/lib/src/material/tab_controller.dart index ff2f18b024..039950d2ed 100644 --- a/packages/flutter/lib/src/material/tab_controller.dart +++ b/packages/flutter/lib/src/material/tab_controller.dart @@ -221,6 +221,8 @@ class DefaultTabController extends StatefulWidget { /// Creates a default tab controller for the given [child] widget. /// /// The [length] argument must be great than one. + /// + /// The [initialIndex] argument must not be null. DefaultTabController({ Key key, @required this.length, @@ -232,6 +234,8 @@ class DefaultTabController extends StatefulWidget { final int length; /// The initial index of the selected tab. + /// + /// Defaults to zero. final int initialIndex; /// This widget's child. Often a [Scaffold] whose [AppBar] includes a [TabBar]. diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index e644113bb1..79318323a7 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -353,7 +353,7 @@ class _DragAnimation extends Animation with AnimationWithParentMixin { void _updateTabController() { 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) return; @@ -700,6 +712,18 @@ class _TabBarViewState extends State { void _updateTabController() { 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) return; @@ -876,7 +900,18 @@ class TabPageSelector extends StatelessWidget { final ColorTween selectedColor = new ColorTween(begin: Colors.transparent, end: color); final ColorTween previousColor = new ColorTween(begin: color, end: Colors.transparent); 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 animation = new CurvedAnimation( parent: tabController.animation, curve: Curves.fastOutSlowIn, diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index 5456e10443..82d2d75675 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -9,25 +9,28 @@ import 'package:flutter_test/flutter_test.dart'; Widget buildSliverAppBarApp({ bool floating, bool pinned, double expandedHeight }) { return new Scaffold( - body: new CustomScrollView( - primary: true, - slivers: [ - new SliverAppBar( - title: new Text('AppBar Title'), - floating: floating, - pinned: pinned, - expandedHeight: expandedHeight, - bottom: new TabBar( - tabs: ['A','B','C'].map((String t) => new Tab(text: 'TAB $t')).toList(), + body: new DefaultTabController( + length: 3, + child: new CustomScrollView( + primary: true, + slivers: [ + new SliverAppBar( + title: new Text('AppBar Title'), + floating: floating, + pinned: pinned, + expandedHeight: expandedHeight, + bottom: new TabBar( + tabs: ['A','B','C'].map((String t) => new Tab(text: 'TAB $t')).toList(), + ), ), - ), - new SliverToBoxAdapter( - child: new Container( - height: 1200.0, - color: Colors.orange[400], + new SliverToBoxAdapter( + child: new Container( + height: 1200.0, + color: Colors.orange[400], + ), ), - ), - ], + ], + ), ), ); }