Flutter 如何使TabBar不在SliverAppBar中移动?

Flutter 如何使TabBar不在SliverAppBar中移动?,flutter,tabs,tabbar,sliverappbar,Flutter,Tabs,Tabbar,Sliverappbar,这是我的第一个问题。我目前正在使用tabbar开发sliverAppBar。我能做些什么使tabbar保持在顶部,并且在我向下拖动棉条时不会向下移动?这是我的代码: @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(primaryColor: Colors.green[700]), home: DefaultTabController( lengt

这是我的第一个问题。我目前正在使用tabbar开发sliverAppBar。我能做些什么使tabbar保持在顶部,并且在我向下拖动棉条时不会向下移动?这是我的代码:

@override
Widget build(BuildContext context) {
  return MaterialApp(
    theme: ThemeData(primaryColor: Colors.green[700]),
    home: DefaultTabController(
      length: 3,
      child: Scaffold(
        body: CustomScrollView(
          slivers: <Widget>[
            SliverAppBar(
              expandedHeight: 450,
              pinned: true,
              bottom: TabBar( 
                tabs: [
                  Tab(icon: Icon(Icons.directions_car)),
                  Tab(icon: Icon(Icons.directions_transit)),
                  Tab(icon: Icon(Icons.directions_bike)),
                ],
              ),
              backgroundColor: Colors.green[700],
              flexibleSpace: FlexibleSpaceBar(
                background: Image.asset(
                  'images/green.png',
                fit: BoxFit.cover,
                ),
              ),
            ),
            SliverFillRemaining(
                child: Container(
              child: Column(
                children: List<int>.generate(12, (index) => index)
                    .map((index) => Container(
                          height: 40,
                          margin: EdgeInsets.symmetric(vertical: 10),
                          color: Colors.grey[300],
                          alignment: Alignment.center,
                          child: Text('$index item'),
                        ))
                    .toList(),
              ),
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(15),
                    topRight: Radius.circular(15),
                  )),
            ))
          ],
        ),
      ),
    ),
  );
}
}
@覆盖
小部件构建(构建上下文){
返回材料PP(
主题:主题数据(原色:Colors.green[700]),
主页:DefaultTabController(
长度:3,
孩子:脚手架(
正文:自定义滚动视图(
条子:[
滑杆(
扩展高度:450,
对,,
底部:TabBar(
选项卡:[
选项卡(图标:图标(图标方向车)),
选项卡(图标:图标(图标方向和交通)),
选项卡(图标:图标(图标方向)),
],
),
背景颜色:颜色。绿色[700],
flexibleSpace:FlexibleSpaceBar(
背景:Image.asset(
“images/green.png”,
适合:BoxFit.cover,
),
),
),
剩余碎片(
子:容器(
子:列(
子项:List.generate(12,(索引)=>index)
.map((索引)=>容器(
身高:40,
边缘:边缘组。对称(垂直:10),
颜色:颜色。灰色[300],
对齐:对齐.center,
子项:文本(“$index item”),
))
.toList(),
),
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:仅限borderRadius(
左上:半径。圆形(15),
右上角:半径。圆形(15),
)),
))
],
),
),
),
);
}
}

编辑:我仍然希望条子的功能能够向下拖动,但我希望选项卡保持在顶部且不移动

您必须使用堆栈包装您的
自定义滚动视图
,并将
选项卡栏
放置在其上方

@覆盖
小部件构建(构建上下文){
返回材料PP(
主题:主题数据(原色:Colors.green[700]),
主页:DefaultTabController(
长度:3,
孩子:脚手架(
主体:堆栈(
儿童:[
自定义滚动视图(
条子:[
滑杆(
扩展高度:450,
对,,
背景颜色:颜色。绿色[700],
),
剩余碎片(
哈斯克罗博迪:错,
子:容器(
子:列(
子项:List.generate(12,(索引)=>index)
.map((索引)=>容器(
身高:40,
边缘:边缘组。对称(垂直:10),
颜色:颜色。灰色[300],
对齐:对齐.center,
子项:文本(“$index item”),
))
.toList(),
),
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:仅限borderRadius(
左上:半径。圆形(15),
右上角:半径。圆形(15),
)),
))
],
),
///你的标签上有图标
定位(
top:MediaQuery.of(context).padding.top,
子:容器(
宽度:MediaQuery.of(context).size.width,
身高:60.0,
颜色:颜色。绿色[700],
孩子:TabBar(
选项卡:[
选项卡(图标:图标(图标方向车)),
选项卡(图标:图标(图标方向和交通)),
选项卡(图标:图标(图标方向)),
],
),
),
),
],
),
),
),
);
}
这不会修复底部tho上的溢出。如果您也想解决这个问题,只需将此
hasScrollBody:false,
添加到您的
SliverFillRemaining
中,如下所示:

sliverfill剩余(
哈斯克罗博迪:错,
子项:容器(…),
),

我仍然希望条子的功能能够向下拖动,但我希望标签保持在顶部,而不是移动。我已经更新了答案。如果这就是你想要的,请告诉我