listview - 在 flutter ListView 中检测焦点小部件

标签 listview flutter flutter-layout

我有一个水平的 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,
                                    ),
                                  ),
                                );
                              }),

It looks like this

最佳答案

你可以用 visibility_detector widget 包裹你的小部件,只要您的小部件在屏幕上可见,它就会触发回调。

关于listview - 在 flutter ListView 中检测焦点小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51908588/

相关文章:

javascript - Jquery 移动数据过滤器固定位置/静态

android - 使用SingleChildScrollView时的堆栈小部件错误

flutter - Flutter:ThemeData中bottomNavigationBar的常见深色和浅色主题

flutter - 如何在Flutter中设计Filter?

java - “如何删除 sqlite 数据库中正确的 ListView 项目

flutter - Flutter中的水平列表列表

flutter - 如何防止用户在Flutter Web(PWA)中使用伪造的gps

Flutter 中特定设备的 Firebase 消息通知

flutter - 如何修复工具栏中的 CircularProgressIndicator() 大小

c# - Xamarin 表格 "...DisplayAlert does not exist in the current context."