刚接触Flutter,不知道如何在UI上设置大小限制,这样就不会溢出。尝试用选项卡做一点不同的用户界面,我在选项卡栏上面有一些组件。基本上我想要这样的东西:
--------------------
| Container |
--------------------
| TabBar |
--------------------
| |
| |
| TabBarView |
| |
| |
--------------------
| Container |
--------------------问题是,我不知道如何让TabBarView占用剩余的空间。我的代码示例甚至不能运行,只是给了我一个这样的错误:
I/flutter ( 3875):渲染库╞═══I/flutter (3875)捕获到══╡异常:在performResize()过程中引发了以下断言: I/flutter ( 3875):为水平视口指定了无边界高度。I/flutter ( 3875):视口在十字轴上展开以填充其容器,并约束其子项以匹配I/flutter ( 3875):其在十字轴上的范围。在这种情况下,为水平视口提供了无限量的I/flutter ( 3875):要在其中展开的垂直空间。
Widget build(BuildContext context) {
List<Tab> myTabs = <Tab>[
Tab(text: 'TAB 1'),
Tab(text: 'TAB 2'),
Tab(text: 'TAB 3'),
];
Widget topBar = Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text("TEXT 1"),
Text("TEXT 2"),
Text("TEXT 3"),
],
));
Widget bottomBar = Row(
children: <Widget>[
RaisedButton(child: Text("Cancel")),
RaisedButton(child: Text("OK")),
],
);
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text("Test"),
),
body: Column(
children: <Widget>[
topBar,
TabBar(
tabs: myTabs,
),
TabBarView(
children: myTabs.map((Tab tab) {
return Container(
color: Colors.red,
child: Text(tab.text)
);
}).toList(),
),
],
),
bottomNavigationBar: bottomBar,
),
);
}发布于 2019-05-12 05:21:15
将TabBarView放入Expanded小部件中
https://stackoverflow.com/questions/55995077
复制相似问题