您好,我正在我的 flutter 应用程序中使用 PageView。我想检测用户何时过度滚动并超出页面。我如何实现它
我的PageView的代码:
PageView(
controller: _controller,
children: widget.imagePaths,
),
Run Code Online (Sandbox Code Playgroud)
像这样把你的PageView里面包裹起来NotificationListener<OverscrollIndicatorNotification>。然后,每当用户向任一方向过度滚动时,onNotification都会调用该函数。
return NotificationListener<
OverscrollIndicatorNotification>(
onNotification: (overscroll) {
print("overscrolled"); //do whatever you need to do when overscroll
},
child: PageView(
controller: _controller,
children: widget.imagePaths,
),
);
Run Code Online (Sandbox Code Playgroud)
完整脚本文件
import 'package:flutter/material.dart';
class Test extends StatefulWidget {
@override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
Widget build(BuildContext context) {
return NotificationListener<OverscrollIndicatorNotification>(
onNotification: (overscroll) {
print("overscrolled");
},
child: PageView(
children: [
Container(color: Colors.red),
Container(color: Colors.green)
],
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1763 次 |
| 最近记录: |