【问题标题】:How to select an item from a List in flutter如何在颤动中从列表中选择一个项目
【发布时间】:2018-07-20 04:47:46
【问题描述】:

我有这样一个模型的列表

amount:"12000"
dateTime:"19/07/2018"
detail:"Soto"
hashCode:853818549
id:1
name:"Theodorus"

我只想选择数量并将其添加到另一个字符串列表中,但我总是收到此错误A value of type 'String' can't be assigned to a variable of type 'List<String>'.,我认为这是因为我做得不对,下面是我的代码

void setupList() async {
    DebtDatabase db = DebtDatabase();
    listCache = await db.getMyDebt();
    setState(() {
      filtered = listCache;
    });
     List<String> amount = new List<String>();
    listCache.map((value)  {
      amount = value.amount;   } );
    //print(amount);
  } 

任何人都可以帮助我,所以我可以从这个模型列表中获取数量列表,然后将所有数量相加吗?

【问题讨论】:

    标签: dart material-design flutter


    【解决方案1】:

    map 函数返回一个可迭代对象,然后您可以将其转换为列表。 你应该尝试这样的事情:

    void setupList() async {
      DebtDatabase db = DebtDatabase();
      listCache = await db.getMyDebt();
      setState(() {
        filtered = listCache;
      });
      List<String> amount = listCache.map((value) => value.amount).toList();
      //print(amount);
    }
    

    【讨论】:

    • 嗨,总和列表怎么样,你也能回答这个问题吗?或者我应该做一个新的回答,谢谢你的回答,我会把它标记为一个回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 2010-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多