listview - 在颤振列表视图中检测焦点小部件
问题描述
我有一个水平的 listview.builder 小部件,列表中的每个孩子大约是总宽度的 90℅,我如何检测哪个小部件处于焦点。
这是我的小部件。
new ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) {
return new InkWell(
onTap: () {
Navigator
.of(context)
.push(new MaterialPageRoute(
builder: (_) => new StakePage(),
));
},
child: new Card(
child: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
image: categories[index].cover,
colorFilter: new ColorFilter.mode(
Colors.black12,
BlendMode.screen),
),
),
constraints: new BoxConstraints(
maxWidth: 400.0,
maxHeight: 600.0),
height: size.height / 2,
width: size.width * 0.85,
),
),
);
}),
解决方案
你可以用 widget 包裹你的小visibility_detector
部件,一旦你的小部件在屏幕上可见,它就会触发回调。
推荐阅读
- security - 我应该如何在 Flutter 中处理访问令牌和 API 机密
- php - XML API 响应中的访问数组转换为 PHP 对象
- javascript - VUE 2+ 访问子方法
- apache-spark-xml - 使用 spark 解析 XML
- node.js - 错误:请手动安装 mysql2 包
- matlab - 在 matlab 上创建一个适合使用 viscircle 绘制的圆圈颜色的颜色条
- python - Sklearn 中的 T-SNE 给出 NaN 或 Inf 数据错误
- email - Amazon WorkMail - 转发每封电子邮件
- javascript - php - 创建自定义标头时丢失会话变量
- android - 在应用程序代码中运行 ADB 命令