【发布时间】:2020-07-30 10:34:34
【问题描述】:
- 我有一个页面,其中包含一个 TabBar、一些其他小部件和一个与上述 TabBar 相关的 TabBarView。构建实现如下所示。
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(color: defaultBackgroundColor),
child: Stack(children: [
Image.asset(
'assets/background/around.jpg',
width: MediaQuery.of(context).size.width,
height: 400,
fit: BoxFit.fill,
),
SingleChildScrollView(
child: Column(
children: <Widget>[
AroundHeader(),
TabBar(
controller: _tabController,
unselectedLabelColor: Colors.white,
indicatorSize: TabBarIndicatorSize.tab,
labelColor: Colors.blue,
indicator: BoxDecoration(
color: Colors.transparent,
border:
Border(bottom: BorderSide(color: Colors.blue, width: 3)),
),
tabs: [
...data.map(
(item) => Tab(
child: Container(
child: Align(
alignment: Alignment.center,
child: Text(item, style: titleStyle),
),
),
),
),
],
),
SizedBox(height: 10),
Padding(
padding: const EdgeInsets.symmetric(vertical: commonMargin),
child: Container(
height: MediaQuery.of(context).size.height + 300,
width: MediaQuery.of(context).size.width - 2 * commonMargin,
child: TabBarView(
controller: _tabController,
children: <Widget>[
AroundRecommend1(),
AroundRecommend2(),
AroundRecommend3(),
AroundRecommend4(),
],
),
),
),
],
),
),
]),
);
}
- 由于 TabBarView 中的内容可能高度可变,例如,AroundRecommend 是从 Column 构建的。
- 现在我必须手动计算 TabBarView 子项的最大高度。
- 我尝试用
Explanded或SizedBox.expand或IntrinsicHeight等替换受约束的容器,但都失败了,但没有提供高度等异常。
【问题讨论】:
标签: flutter