Dart 颤振-如何控制ListView生成器的速度?

Dart 颤振-如何控制ListView生成器的速度?,dart,flutter,Dart,Flutter,我有一个ListView.builder,我想在ListView中控制滚动的速度,但除了扩展模拟之外,我找不到解决方案,在那里我覆盖了速度,然后扩展了ScrollingPhysics类并从那里提供速度。但我不知道该怎么做 您有其他解决方案或示例吗?如果您需要类似android的滚动行为,请查看的构造函数参数摩擦。对于滚动物理,它是滚动减速系数。摩擦力越大,滚动视图停止滚动的时间越早 您可以在自定义滚动物理类中控制摩擦力: class CustomScrollPhysics extends Scr

我有一个ListView.builder,我想在ListView中控制滚动的速度,但除了扩展模拟之外,我找不到解决方案,在那里我覆盖了速度,然后扩展了ScrollingPhysics类并从那里提供速度。但我不知道该怎么做


您有其他解决方案或示例吗?

如果您需要类似android的滚动行为,请查看的构造函数参数
摩擦
。对于滚动物理,它是滚动减速系数。摩擦力越大,滚动视图停止滚动的时间越早

您可以在自定义滚动物理类中控制摩擦力:

class CustomScrollPhysics extends ScrollPhysics {
  const ChartScrollPhysics({ScrollPhysics parent}) : super(parent: parent);

  @override
  CustomScrollPhysics applyTo(ScrollPhysics ancestor) {
    return CustomScrollPhysics(parent: buildParent(ancestor));
  }

  ...

  @override
  Simulation createBallisticSimulation(
      ScrollMetrics position, double velocity) {
    final tolerance = this.tolerance;
    if ((velocity.abs() < tolerance.velocity) ||
        (velocity > 0.0 && position.pixels >= position.maxScrollExtent) ||
        (velocity < 0.0 && position.pixels <= position.minScrollExtent)) {
      return null;
    }
    return ClampingScrollSimulation(
      position: position.pixels,
      velocity: velocity,
      friction: 0.5,    // <--- HERE
      tolerance: tolerance,
    );
  }
}


检查@RaoufRahiche谢谢!但这创造了一个无限的卷轴。我如何才能将滚动限制为列表中的最后一项和第一项?你所说的限制滚动是什么意思?我不明白我希望滚动停止,并且在我到达列表中的最后一项或第一项时无法再滚动。你找到解决方法了吗@P.Lorand
ListView.builder(
  physics: CustomScrollPhysics(), 
  itemBuilder: (context, index) {
    ...
})