我有一个TabBar和TabBarView嵌套在Block中。这是因为 TabBarView 内的内容是动态的,内容的高度直到运行时才知道。
我无法将块嵌套在 TabBarView 内,因为 TabBar 之前的内容应该与 TabBarView 内容一起滚动。
图表:
代码:
new DefaultTabController(
length: 3,
child: new Block(
children: [
new Container(
height: 200.0,
decoration: new BoxDecoration(
backgroundColor: Colors.blue[500],
),
),
new TabBar(
tabs: <Widget>[
new Tab(text: '1'),
new Tab(text: '2'),
new Tab(text: '3'),
],
),
new TabBarView(
children: [
new Text('one'),
new Text('two'),
new Text('three'),
],
),
],
)
);
但是,TabBarView 的 Viewport 不受约束,需要具有有限高度约束的祖先小部件。不幸的是,一个 Block 没有给出一个有界的高度,因为它的可滚动性。
运行布局时收到此错误:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (28715): The following assertion was thrown during performLayout():
I/flutter (28715): RenderList object was given an infinite size during layout.
I/flutter (28715): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (28715): inside another render object that allows its children to pick their own size.
I/flutter (28715): The nearest ancestor providing an unbounded height constraint is: ...
关于如何最好地解决这个问题的任何想法?