【问题标题】:Detect focused widget in flutter listview在颤振列表视图中检测焦点小部件
【发布时间】:2019-01-25 06:36:47
【问题描述】:

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

【问题讨论】:

标签: listview flutter flutter-layout


【解决方案1】:

您可以使用visibility_detector widget 包装您的小部件,一旦您的小部件在屏幕上可见,它将触发回调。

【讨论】:

    猜你喜欢
    • 2019-01-13
    • 2020-02-05
    • 2020-11-16
    • 2019-11-15
    • 1970-01-01
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    相关资源
    最近更新 更多