Trivial tabs-related fixes (#9191)
Add some commentary around DefaultTabController.initialIndex. Fix typo (nuull) in TabBar. Make some asserts more detailed.
This commit is contained in:
parent
fbcade5900
commit
8469ef03d8
@ -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 {
|
|||||||
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
|
|||||||
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> {
|
|||||||
|
|
||||||
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> {
|
|||||||
|
|
||||||
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 {
|
|||||||
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,25 +9,28 @@ 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(
|
||||||
primary: true,
|
length: 3,
|
||||||
slivers: <Widget>[
|
child: new CustomScrollView(
|
||||||
new SliverAppBar(
|
primary: true,
|
||||||
title: new Text('AppBar Title'),
|
slivers: <Widget>[
|
||||||
floating: floating,
|
new SliverAppBar(
|
||||||
pinned: pinned,
|
title: new Text('AppBar Title'),
|
||||||
expandedHeight: expandedHeight,
|
floating: floating,
|
||||||
bottom: new TabBar(
|
pinned: pinned,
|
||||||
tabs: <String>['A','B','C'].map((String t) => new Tab(text: 'TAB $t')).toList(),
|
expandedHeight: expandedHeight,
|
||||||
|
bottom: new TabBar(
|
||||||
|
tabs: <String>['A','B','C'].map((String t) => new Tab(text: 'TAB $t')).toList(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
new SliverToBoxAdapter(
|
||||||
new SliverToBoxAdapter(
|
child: new Container(
|
||||||
child: new Container(
|
height: 1200.0,
|
||||||
height: 1200.0,
|
color: Colors.orange[400],
|
||||||
color: Colors.orange[400],
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user