我有一个在文本小部件中显示日期的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),
),
),
发布于 2019-12-30 18:17:17
在on tap方法中,您可以从列表中获取数据。因此,我在这里发布了一些代码,以便获得更多想法
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
});
发布于 2019-12-30 17:28:38
使用ListView.builder并在RowItem中传递数据。
ListView.builder(
itemBuilder: (context, index) => RowItem( list[index]),
itemCount: list.length,
),
和,
class RowItem extends StatelessWidget {
final String data;
RowItem(this.data);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: (){
print(data);
},
child: Text(data),
);
}
}
发布于 2019-12-30 17:34:56
尝试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),
),
)
}
https://stackoverflow.com/questions/59528035
复制相似问题