如何获取ListTile中的行ID或行号?

Kiro777

如果我的列表标题很长,那么如何获取行号..是否有行标识符?

没有要显示的代码。这只是一个普遍的问题。

在给我反对票之前,请重新考虑。.我将失去使用StackOverview的权限,并且我已经结交了很多朋友。

加布

您可以ListView.builder完成此操作。示例代码如下所示:

List<...> items = ... //fill in whatever you need
ListView.builder(
    itemBuilder: (context, index) {
                        return buildRow(index);
                  },
)

然后在您的buildRow方法中,您将拥有此onTapStatement

Widget buildRow(int index) {
    return ListTile(
        title: ..., //whatever you want, you can get data from sample list by
                   //doing items[index]
        onTap: () {
            //do what you want and your row number is index.
        } 
    );
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章