flutter - Flutter Web - 迭代对象列表时如何保留绝对值?
问题描述
我有一个字典列表,其中有一个 ID。我遍历列表并创建一个凸起的按钮。提升按钮“onPressed”旨在发送创建时“产品”中的“id”,但它始终发送列表中最后一个“产品”对象的“id”。它似乎保留了与产品对象的相对链接,而不是“id”的绝对值。(** 仅用于突出显示对象,不在代码中)。
if(productList!=null)
for(product in productList)
TableRow(
children: <Widget>[
Container(
decoration: new BoxDecoration(
color: Colors.white,
),
child: Center(
child: Row(
children: <Widget>[
SizedBox(
width: 50,
height: 20,
child:RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
),
onPressed: () => editProduct('**${product['id']}**'),
color: Colors.blue,
padding: EdgeInsets.fromLTRB(1, 1, 1, 1),
child: Text('Edit',
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
),
),
),
],
),
],
),
),
),
],
),
我已经尝试了所有我能想到的转换为字符串的组合。toString(),用单引号、双引号括起来。有什么建议么?
解决方案
尝试for(final product in productList){...}
推荐阅读
- python - 如何使用 Fernet 加密对字符串变量进行加密
- ios - 通过添加/减去本地偏移量来计算日期时间 [将任何日期时间转换为 UTC 时间格式]
- javascript - Google Charts - 更改可点击标签 ColumnChart 中列的颜色
- objective-c - UIViewController - iPad Pro 3rd 顶部和底部的神秘空白
- c# - glyphicon 不超过一页 asp.net webform
- javascript - 加载javascript时如何修复我的webview崩溃
- python - 求解不可行的不等式系统
- linux - Yocto - Linux 映像生成 - 删除 qemu 支持
- java - 如何使用 if 语句检查布尔值
- ruby-on-rails - 如何在haml中将三元运算符用于复选框?