Android 如何获取TextWidget onTap的文本

Android 如何获取TextWidget onTap的文本,android,ios,flutter,Android,Ios,Flutter,我有一个ListView,它在文本小部件中显示日期。点击文本小部件,我希望文本为字符串。我怎么能得到这个 这是myCode children: <Widget>[ GestureDetector( onTap: () { print('OnTapped'); print(arrayDay[i].toString()); // get the text of TextWidget here },

我有一个ListView,它在文本小部件中显示日期。点击文本小部件,我希望文本为字符串。我怎么能得到这个

这是myCode

 children: <Widget>[
    GestureDetector(
      onTap: () {
         print('OnTapped');
         print(arrayDay[i].toString());
         // get the text of TextWidget here
      },
      child: new Text(
         arrayDay[i].toString(),
         style: new TextStyle(
         fontWeight: FontWeight.w400),
        ),
     ),

使用ListView.builder并在RowItem中传递数据

ListView.builder(
        itemBuilder: (context, index) => RowItem( list[index]),
        itemCount: list.length,
      ),
以及


尝试ListBuilder,在ListBuilder中传递列表,并在点击TextWidget时从当前索引获取数据

  child: ListView.builder(
          itemCount: _list.length,
          itemBuilder: (BuildContext context, int index) {
          return listTileCard(index);
          });

         listTileCard(index) {
         return GestureDetector(
            onTap: () {
              print('OnTapped');
              print(_list[index].toString());
              // get the text of TextWidget here
            },
            child: new Text(
              _list[index].toString(),
              style: new TextStyle(
                  fontWeight: FontWeight.w400),
            ),
          )

}

在点击方式中,您可以从列表中获取数据。所以我在这里发布了一些代码,以便了解更多信息

return ListView.builder(
            itemCount: count,
            itemBuilder: (BuildContext context, int position) {
              return Card(
                color: Colors.white,
                elevation: 2.0,
                child: ListTile(

                  title: Text(this.noteList[position].title,
                    style: titleStyle,
                  ),
                  subtitle: Text(this.noteList[position].date),

                  onTap: () {
                    debugPrint('Note Data '+ this.noteList[position].title);
                    debugPrint('Data '+ 'Here your Data Get'); // you can get data here
                  },
                ),
              ); // Card
            });
使用ListView.builder-它将为您提供一个可以在arrayDay[i].toString中使用的索引
return ListView.builder(
            itemCount: count,
            itemBuilder: (BuildContext context, int position) {
              return Card(
                color: Colors.white,
                elevation: 2.0,
                child: ListTile(

                  title: Text(this.noteList[position].title,
                    style: titleStyle,
                  ),
                  subtitle: Text(this.noteList[position].date),

                  onTap: () {
                    debugPrint('Note Data '+ this.noteList[position].title);
                    debugPrint('Data '+ 'Here your Data Get'); // you can get data here
                  },
                ),
              ); // Card
            });