我有动态数据,我正在使用 ListView.builder 向用户显示。我只是使用文本向用户显示数据。只有我添加了一个编辑图标,所以当用户单击该图标时,它使用户能够编辑特定文本。如何制作可编辑的 ListView 项目?
最佳答案
您应该将以下类调用到 itemBuilder 中: ListView.builder(...) 的字段
class ListItem extends StatefulWidget {
@override
_ListItemState createState() => _ListItemState();
}
class _ListItemState extends State<ListItem> {
bool _isEnabled = false;
@override
Widget build(BuildContext context) {
return ListTile(
title: TextField(
enabled: _isEnabled,
decoration: InputDecoration(
hintText: 'Enter a text',
),
),
// The icon button which will notify list item to change
trailing: GestureDetector(
child: new Icon(
Icons.edit,
color: Colors.black,
),
onTap: () {
setState((){
_isEnabled = !_isEnabled;
});
},
),
);
}
}
关于listview - 如何制作可编辑的 ListView 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53700347/