首页 > 解决方案 > 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(),用单引号、双引号括起来。有什么建议么?

标签: flutterflutter-web

解决方案


尝试for(final product in productList){...}


推荐阅读