add assert if length of TabController and number of tabs do not match (#29332)

This commit is contained in:
Shi-Hao Hong
2019-03-15 14:25:56 -07:00
committed by GitHub
parent 87e6beecad
commit 2a21c1a188

View File

@@ -778,6 +778,17 @@ class _TabBarState extends State<TabBar> {
}
return true;
}());
assert(() {
if (newController.length != widget.tabs.length) {
throw FlutterError(
'Controller\'s length property (${newController.length}) does not match the \n'
'number of tab elements (${widget.tabs.length}) present in TabBar\'s tabs property.'
);
}
return true;
}());
if (newController == _controller)
return;
@@ -1122,6 +1133,17 @@ class _TabBarViewState extends State<TabBarView> {
}
return true;
}());
assert(() {
if (newController.length != widget.children.length) {
throw FlutterError(
'Controller\'s length property (${newController.length}) does not match the \n'
'number of elements (${widget.children.length}) present in TabBarView\'s children property.'
);
}
return true;
}());
if (newController == _controller)
return;