简体   繁体   English

在颤动列表视图中检测焦点小部件

[英]Detect focused widget in flutter listview

I have an horizontal listview.builder widget, each child in the list is about 90℅ of the total width, how can I detect which widget is in focus.我有一个水平的 listview.builder 小部件,列表中的每个子项大约是总宽度的 90℅,我如何检测哪个小部件处于焦点。

This is my the widget.这是我的小部件。

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小部件,它会触发一个回调,只要你的控件在屏幕上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM