Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter CustomScrollView中的多个滑动应用栏_Flutter_Flutter Sliver - Fatal编程技术网

Flutter CustomScrollView中的多个滑动应用栏

Flutter CustomScrollView中的多个滑动应用栏,flutter,flutter-sliver,Flutter,Flutter Sliver,我需要有多个SliverAppBar,每个SliverList都在一个视图中。目前只有第一个滑动应用条正确响应 当然,我已经在SO和Google上进行了扩展搜索,但还没有找到解决方案 @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Details'), ), body: Cu

我需要有多个SliverAppBar,每个SliverList都在一个视图中。目前只有第一个滑动应用条正确响应

当然,我已经在SO和Google上进行了扩展搜索,但还没有找到解决方案

  @override
  Widget build(BuildContext context) {
     return Scaffold(
        appBar: AppBar(
          title: Text('Details'),
        ),
        body: CustomScrollView(
          slivers: <Widget>[
            new SliverAppBar(
              floating: true,
              automaticallyImplyLeading: false,
              title: Text('1'),
            ),
            new SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) => ListTile(title: Text('Text 1')),
                childCount: 20,
              ),
            ),
            new SliverAppBar(
              automaticallyImplyLeading: false,
              title: Text('2'),
              floating: true,
            ),
            new SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) => ListTile(title: Text('Text 2')),
                childCount: 20,
              ),
            ),
          ],
        ),
      );
  }
@覆盖
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“细节”),
),
正文:自定义滚动视图(
条子:[
新滑杆(
浮动:是的,
自动嵌入:false,
标题:文本(“1”),
),
新名单(
代表:SliverChildBuilderDelegate(
(上下文,索引)=>ListTile(标题:Text('Text 1')),
儿童人数:20,
),
),
新滑杆(
自动嵌入:false,
标题:文本(“2”),
浮动:是的,
),
新名单(
代表:SliverChildBuilderDelegate(
(上下文,索引)=>ListTile(标题:Text('Text 2')),
儿童人数:20,
),
),
],
),
);
}

如果您确实滚动,我希望在滚动列表时看到标题“2”也会浮动。

这似乎是
CustomScrollView
的一个限制。解决这个问题是可能的,但这是非常棘手的,除非您有固定高度的项目和固定长度的列表。如果是这样,您可以假设整个会话的高度(
AppBar
height+每个列表项的高度)

看一看:

class Foo扩展StatefulWidget{
@凌驾
_FooState createState()=>\u FooState();
}
类_FooState扩展了状态{
静态常数双listItemHeight=50;
静态常量int listItemCount=15;
static const double sessionHeight=kToolbarHeight+(listItemCount*listItemHeight);
int floatingAppBarIndex;
滚动控制器;
@凌驾
void initState(){
super.initState();
浮动ppbarindex=0;
控制器=ScrollController()…addListener(onScroll);
}
void onScroll(){
双滚动偏移=controller.offset;
int sessionscrolled=0;
while(滚动偏移>会话高度){
scrollOffset-=会话高度;
sessionscrolled++;
}
if(sessionscrolled!=floatingAppBarIndex){
设置状态(){
floatingAppBarIndex=会话已滚动;
});
}
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“细节”),
),
正文:自定义滚动视图(
控制器:控制器,
条子:[
新滑杆(
浮动:浮动AppBarIndex==0,
自动嵌入:false,
标题:文本(“1”),
),
新名单(
代表:SliverChildBuilderDelegate(
(上下文、索引){
返回大小框(
高度:listItemHeight,
孩子:ListTile(
标题:文本(“文本1”),
),
);
},
childCount:listItemCount,
),
),
新滑杆(
浮动:浮动AppBarIndex==1,
自动嵌入:false,
标题:文本(“2”),
),
新名单(
代表:SliverChildBuilderDelegate(
(上下文、索引){
返回大小框(
高度:listItemHeight,
孩子:ListTile(
标题:文本(“文本2”),
),
);
},
childCount:listItemCount,
),
),
],
),
);
}
}
正如我所说,您仍然可以在具有可变值(项目高度和列表长度)的列表中执行此操作,但这将非常棘手。如果这是您的情况,我建议使用以下插件之一:

您应该试试下面的一个:谢谢!这正是我想要的我认为你的问题是相关的。我会正确回答,这样对其他人有用,好吗?