我有一个存储在列表中的项目列表,我通过listview.builder
显示它,现在我需要允许用户编辑该文本,我该如何做呢?我尝试使用TextField,它会更改文本,但我还需要更新列表中的文本。
List shoppingList = [];
ListView.builder(
shrinkWrap: true,
itemCount: shoppingList.length,
itemBuilder: (context, index) {
return ShoppingListItemTile(
addText: () {
shoppingList[index] = '';
},
text: shoppingList[index],
removeList: () {
shoppingList.removeAt(index);
setState(() {});
});
},
)
class ShoppingListItemTile extends StatelessWidget {
final String text;
final VoidCallback removeList;
final VoidCallback addText;
const ShoppingListItemTile(
{Key? key,
required this.text,
required this.removeList,
required this.addText})
: super(key: key);
@override
Widget build(BuildContext context) {
bool isEditable = false;
return Padding(
padding: const EdgeInsets.only(left: 24.0, right: 24, top: 16),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(text,
style: AppTextStyle.latoMedium(
fontWeight: FontWeight.w400,
fontSize: 17,
color: AppColorPallet.zop_location_text)),
InkWell(
onTap: () {
removeList();
},
child: SvgPicture.asset(AppIcons.close))
],
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Divider(),
)
],
),
);
}
}
1条答案
按热度按时间im9ewurl1#
尝试以下代码