flutter - 如果在 Flutter 中禁用滚动,如何连续检测?
问题描述
我想不断检查是否无法滚动。
@override
void initState() {
super.initState();
WidgetsBinding.instance!.addPostFrameCallback((duration) {
print("${_scrollViewController.position.maxScrollExtent}");
// prints true if scrollable else false
print("isScrollable = ${_scrollViewController.position.maxScrollExtent != 0}");
});
}
我试过这段代码,但它只检测到一次,而不是连续检测到。我该怎么办?
解决方案
使用NotificationListener
小部件。
例子:
NotificationListener<ScrollNotification>(
child: ListView(
children: MyListChilren()),
onNotification: (ScrollNotification scrollNotif) {
print(scrollNotif.metrics.maxScrollExtent);
},
);
推荐阅读
- html - 边距底部引导程序
- python - 如果 Anaconda 带有 pip,为什么说明会建议安装它?
- python - 蛮力稳定婚姻,如何实现两个列表之间所有可能的配对?
- excel - 将多个链接的 Excel 图表粘贴到 Word 返回运行时错误 5345 Word 无法获取数据
- swift - 延迟谷歌云功能
- reactjs - 我该如何解决这个 webpack 或 babel 错误?
- javascript - 如何更新由 REACTJS 中的数组映射呈现的输入文本
- azure - 将大型 DataFrame 从 PySpark 写入 Kafka 遇到超时
- python - 基于日期时间索引的屏蔽数据框列
- sql - Oracle:如何选择特定日期的时间戳值