【发布时间】:2021-09-22 06:55:42
【问题描述】:
所以基本上我正在尝试在 CustomScrollView 小部件中实现 TabBar and TabBarView 并引发此错误:
RenderBox 未布置:_RenderScrollSemantics#ab91d relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': 断言失败:第 1930 行第 12 行:'hasSize'
问题肯定是 TabBarView 及其高度。
有效的小部件:
SliverToBoxAdapter(
child: Container(
height: size.height,
child: TabBarView(
controller: this._controller,
children: [
Center(
child: Text("Hello"),
),
Center(
child: Text("Hello"),
),
Center(
child: Text("Hello"),
),
],
),
),
)
小部件不起作用
SliverToBoxAdapter(
child: Container(
child: TabBarView(
controller: this._controller,
children: [
Center(
child: Text("Hello"),
),
Center(
child: Text("Hello"),
),
Center(
child: Text("Hello"),
),
],
),
),
)
我不只使用工作小部件的原因是因为我不想固定高度。我希望它的孩子们需要它。这就是为什么我尝试使用 Expanded 但它会引发同样的错误。
我在这里做错了什么?
如果有帮助,这里是整个小部件树:
Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: size.height * 0.45,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
background: MyImage(),
centerTitle: true,
title: Text("-_-");,
),
),
SliverToBoxAdapter(
child: Column(
children: [
SizedBox(height: 20),
MyInfo(),
SizedBox(height: 10),
],
),
),
SliverToBoxAdapter(
child: Container(
child: TabBar(
controller: this._controller,
indicatorColor: primaryCScheme,
tabs: [
Tab(
icon: Icon(CupertinoIcons.add),
),
Tab(
icon: Icon(CupertinoIcons.scissors),
),
Tab(
icon: Icon(CupertinoIcons.film),
),
],
),
),
),
SliverToBoxAdapter(
child: Container(
height: size.height, // here is the issue
color: Colors.red,
child: TabBarView(
controller: this._controller,
children: [
Center(
child: Text("Hello"),
),
Center(
child: Text("Hello"),
),
Center(
child: Text("Hello"),
),
],
),
),
),
],
),
)
【问题讨论】: