【发布时间】:2021-10-08 02:48:20
【问题描述】:
我正在从列表创建动态小部件,当我单击由列表创建的小部件时,我希望它更新其名称。我正在使用有状态小部件并且没有错误,当我单击小部件建议列表更新自身但它不影响文本小部件时。
这是我的清单
List suggestionList = [
{'name':'Tomato','imageurl':'https://ayb.akinoncdn.com/products/2021/06/18/7025/46ead09c-f4cb-
4b85-acd7-8ca1d8452864_size780x780_quality60_cropCenter.jpg'}];
这是我的 GridView
GridView.builder(
shrinkWrap: true,
itemCount: suggestionList.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemBuilder: (context,index){
Map data = suggestionList[index];
return GestureDetector(
onTap: (){
setState(() {
suggestionList.clear();
suggestionList =
[{'name':'Eggplant','imageurl':'https://ayb.akinoncdn.com/products/2021/06/18/7025/46ead09c-
f4cb-4b85-acd7-8ca1d8452864_size780x780_quality60_cropCenter.jpg'}];
print(suggestionList);
});
},
child:Container(
alignment: Alignment.topLeft,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 2.0, // soften the shadow
spreadRadius: 1.0, //extend the shadow
offset: Offset(
0, // Move to right 10 horizontally
1.0, // Move to bottom 5 Vertically
),
)
],
),
child: Column(
children: [
Expanded(
flex: 10,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
image: DecorationImage(image: NetworkImage(data['imageurl']),
fit: BoxFit.scaleDown)
),
),),
Expanded(flex:1,
child: Text(data['name'],style: TextStyle(
fontWeight: FontWeight.w600
),),),
],
),
));}
),
【问题讨论】:
标签: flutter gridview set state setstate