gpt4 book ai didi

flutter - CustomScrollView 内的 TabView

转载 作者:IT王子 更新时间:2023-10-29 07:08:33 32 4
gpt4 key购买 nike

用 SliverFillRemaining 包装 TabBarView(像 Expanded 一样填充剩余的空白空间)会产生以下错误输出。

flutter:RenderPositionedBox 需要一个 RenderBox 类型的子对象,但收到了一个类型的子对象 flutter :RenderSliv​​erList。

TabController tabContoller;
@override
void initState() {
tabContoller = new TabController(
vsync: this,
length: 3,
);


@override
Widget build(BuildContext context) {
return new Scaffold(
floatingActionButton:floatActionBtn(...),
bottomNavigationBar: bottomNavigationBar(...),
appBar: apBar(),
body: Stack(
children: <Widget>[
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
expandedHeight: 195.0,
flexibleSpace: FlexibleSpaceBar(
background: new Stack(
children: <Widget>[
...

]),
),
),
new SliverFillRemaining(
child: TabBarView(
controller: tabContoller,
children: <Widget>[
Tab(...),
Tab(...),
Tab(...)
],
),
),
],
),
],

)

最佳答案

不要忘记 DefaultTabController,这段代码工作正常:

         @override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Container(
child: CustomScrollView(slivers: <Widget>[
SliverAppBar(),
new SliverFillRemaining(
child: TabBarView(
children: <Widget>[
Text("Tab 1"),
Text("Tab 2"),
Text("Tab 3"),
],
),
),
])),
);
}

关于flutter - CustomScrollView 内的 TabView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54066604/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com