【发布时间】:2021-07-05 04:07:03
【问题描述】:
我有一个包含可拖动项目的 GridView。当一个项目被拖到屏幕的顶部/底部时,我想在那个方向滚动 GridView。
目前我将每个可拖动项目都包装在一个 Listener 中,如下所示:
Listener(
child: _wrap(widget.children[i], i),
onPointerMove: (PointerMoveEvent event) {
if (event.position.dy >= MediaQuery.of(context).size.height - 100) {
// 120 is height of your draggable.
widget.scrollController.animateTo(
widget.scrollController.offset + 120,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 200));
}if (event.position.dy <= kToolbarHeight + MediaQueryData.fromWindow(window).padding.top + 100) {
// 120 is height of your draggable.
widget.scrollController.animateTo(
widget.scrollController.offset - 120,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 200));
}
}
)
它可以工作,但滚动一点也不流畅,看起来有点迟钝。 我也需要它在网络上工作。
有人对此有更好的解决方案吗?
【问题讨论】:
-
你能在 dartpad 中分享一个演示。直接检查问题会很有帮助。我知道的一件事通常是在网络结果为零的情况下返回的位置。
标签: flutter flutter-layout flutter-web flutter-gridview