Is it possible to specify BouncingScrollPhysics for ScrollPhysics in the Flutter DraggableScrollableSheet widget?

huangapple go评论107阅读模式
英文:

Is it possible to specify BouncingScrollPhysics for ScrollPhysics in the Flutter DraggableScrollableSheet widget?

问题

根据我所研究的情况,似乎无法在DraggableScrollableSheet小部件中指定BouncingScrollPhysics作为ScrollPhysics。如果有人知道,请提供在DraggableScrollableSheet小部件中指定BouncingScrollPhysics为ScrollPhysics的操作说明。

英文:

As far as I have researched, it doesn't seem possible to specify BouncingScrollPhysics for ScrollPhysics in the DraggableScrollableSheet widget. If anyone knows, could you please provide instructions on how to specify BouncingScrollPhysics for ScrollPhysics in the DraggableScrollableSheet widget?

答案1

得分: 1

你不能将物理效果分配给DraggableScrollableSheet
你应该在DraggableScrollableSheet的构建器中使用一个可滚动的小部件,并将构建器中的scroll controller分配给可滚动小部件。请参考下面的示例代码:

DraggableScrollableSheet(
  initialChildSize: 0.1,
  minChildSize: 0.1,
  maxChildSize: 1,
  expand: false,
  builder: (_, scrollController) => ListView(
    controller: scrollController, //在这里分配控制器 
    physics: const BouncingScrollPhysics(),
  ),
);

如上所示,我有一个ListView,它使用了来自DraggableScrollableSheet的滚动控制器,并将其设置为BouncingScrollPhysics()。

英文:

You cannot assign physics to DraggableScrollableSheet.
What you should do is to have a scrollable widget in the builder of the DraggableScrollableSheet and assign the scroll controller from the builder to the scrollable. See the below snippet:

DraggableScrollableSheet(
      initialChildSize: 0.1,
      minChildSize: 0.1,
      maxChildSize: 1,
      expand: false,
      builder: (_, scrollController) => ListView(
        controller: scrollController, //assign the controller here 
        physics: const BouncingScrollPhysics(),
      ),
    );

As shown above, i have a listview that uses the scroll controller from the DraggableScrollableSheet and gave it BouncingScrollPhysics().

huangapple
  • 本文由 发表于 2023年8月10日 18:26:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76874863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定