Flutter SliverPersistentHeader和ListViewBuilder导致奇怪的滚动问题

Flutter SliverPersistentHeader和ListViewBuilder导致奇怪的滚动问题,flutter,dart,Flutter,Dart,您可以在此gif中看到问题: 下面是代码和示例: 我在我的应用程序中有相同的设置,当用户向下滚动然后再向上滚动然后向下滚动时,它会导致问题(不等待反弹解决) 非常感谢您的帮助。找到了解决方案: 此问题是由于在狭缝下使用ListViewBuilder造成的。它是通过使用SliverList小部件修复的,您可以在这里看到区别: 之前: NestedScrollView( headerSliverBuilder: (BuildContext context, bool innerB

您可以在此gif中看到问题:

下面是代码和示例:

我在我的应用程序中有相同的设置,当用户向下滚动然后再向上滚动然后向下滚动时,它会导致问题(不等待反弹解决)

非常感谢您的帮助。

找到了解决方案:

此问题是由于在狭缝下使用ListViewBuilder造成的。它是通过使用SliverList小部件修复的,您可以在这里看到区别:

之前:

NestedScrollView(
  headerSliverBuilder:
      (BuildContext context, bool innerBoxIsScrolled) {
    return <Widget>[
      SliverPersistentHeader(
        pinned: true,
        //? M7: this was true
        //floating: false, // useless if pinned is true.
        delegate: ContestTabHeader(
            (MediaQuery.of(context).size.width * 1)),
        //(MediaQuery.of(context).size.width * 1.3)),
      ),
    ];
  },
  body: Container(
    color: AppTheme.getTheme().backgroundColor,
    child: ListView.builder(
      itemCount: 4,
      padding: EdgeInsets.only(top: 32, bottom: 16),
      scrollDirection: Axis.vertical,
      itemBuilder: (context, index) {
        var count = 4;
        var animation = Tween(begin: 0.0, end: 1.0).animate(
          CurvedAnimation(
            parent: widget.animationController,
            curve: Interval((1 / count) * index, 1.0,
                curve: Curves.fastOutSlowIn),
          ),
        );
        if (index == 0) {
          return TitleView(
            titleTxt: 'المواضيع',
            subTxt: '',
            animation: animation,
            animationController: widget.animationController,
          );
        } else if (index == 1) {
          return Padding(
            padding: const EdgeInsets.only(top: 8),
            child: PopularListView(
              animationController:
                  widget.animationController,
              callBack: (index) {},
            ),
          );
        } else if (index == 2) {
          return TitleView(
            titleTxt: 'ننصحك بهذه الدروس',
            subTxt: 'View all',
            animation: animation,
            isLeftButton: true,
            animationController: widget.animationController,
          );
        } else {
          return getDealListView(index);
        }
      },
    ),
  ),
),
NestedScrollView(
班主任:
(BuildContext上下文,boolInnerBoxIsCrowled){
返回[
滑冰机(
对,,
//这是真的
//floating:false,//如果pinted为true则无效。
代表:标题(
(MediaQuery.of(context.size.width*1)),
//(MediaQuery.of(context.size.width*1.3)),
),
];
},
主体:容器(
颜色:AppTheme.getTheme().backgroundColor,
子项:ListView.builder(
物品计数:4,
填充:仅限边缘设置(顶部:32,底部:16),
滚动方向:轴垂直,
itemBuilder:(上下文,索引){
var计数=4;
var animation=Tween(开始:0.0,结束:1.0)。设置动画(
曲线化(
父项:widget.animationController,
曲线:区间((1/计数)*指数,1.0,
曲线:曲线。快速输出),
),
);
如果(索引==0){
返回标题视图(
标题文字:'الواضيع',
潜台词:",,
动画:动画,
animationController:widget.animationController,
);
}else if(索引==1){
返回填充(
填充:仅限常量边集(顶部:8),
子:PopularListView(
animationController:
widget.animationController,
回调:(索引){},
),
);
}else if(索引==2){
返回标题视图(
标题文本:“ننكبهبهالدوس”,
潜台词:“查看全部”,
动画:动画,
isLeftButton:正确,
animationController:widget.animationController,
);
}否则{
返回getDealListView(索引);
}
},
),
),
),
然后在修复之后:

CustomScrollView(
  slivers: <Widget>[
    SliverPersistentHeader(
      pinned: false,
      // floating: false,
      delegate: ContestTabHeader((MediaQuery.of(context).size.width * 1)),
    ),
    SliverPadding(
      padding: EdgeInsets.only(top: 20),
                              sliver: SliverList(
        delegate: SliverChildBuilderDelegate(
          (context, index) {
            var count = 4;
            var animation = Tween(begin: 0.0, end: 1.0).animate(
              CurvedAnimation(
                parent: widget.animationController,
                curve: Interval((1 / count) * index, 1.0, curve: Curves.fastOutSlowIn),
              ),
            );
            if (index == 0) {
              return TitleView(
                titleTxt: 'المواضيع',
                subTxt: '',
                animation: animation,
                animationController: widget.animationController,
              );
            } else if (index == 1) {
              return Padding(
                padding: const EdgeInsets.only(top: 8),
                child: PopularListView(
                  animationController: widget.animationController,
                  callBack: (index) {},
                ),
              );
            } else if (index == 2) {
              return TitleView(
                titleTxt: 'ننصحك بهذه الدروس',
                subTxt: 'View all',
                animation: animation,
                isLeftButton: true,
                animationController: widget.animationController,
              );
            } else {
              return getDealListView(index);
            }
          },
          childCount: 4,
        ),
      ),
    ),
  ],
),
CustomScrollView(
条子:[
滑冰机(
错,,
//浮动:假,
委托:ContestTabHeader((MediaQuery.of(context.size.width*1)),
),
填缝料(
填充:仅限边缘设置(顶部:20),
银条:银条列表(
代表:SliverChildBuilderDelegate(
(上下文、索引){
var计数=4;
var animation=Tween(开始:0.0,结束:1.0)。设置动画(
曲线化(
父项:widget.animationController,
曲线:区间((1/计数)*指数,1.0,曲线:曲线。快速输出),
),
);
如果(索引==0){
返回标题视图(
标题文字:'الواضيع',
潜台词:",,
动画:动画,
animationController:widget.animationController,
);
}else if(索引==1){
返回填充(
填充:仅限常量边集(顶部:8),
子:PopularListView(
animationController:widget.animationController,
回调:(索引){},
),
);
}else if(索引==2){
返回标题视图(
标题文本:“ننكبهبهالدوس”,
潜台词:“查看全部”,
动画:动画,
isLeftButton:正确,
animationController:widget.animationController,
);
}否则{
返回getDealListView(索引);
}
},
儿童人数:4,
),
),
),
],
),
希望这能帮助那些面临同样问题的人