【问题标题】:A value of type 'Iterable<Transactions>' can't be returned from the function '_recentTransactions' because it has a return type of 'List<Transactions>无法从函数“_recentTransactions”返回类型为“Iterable<Transactions>”的值,因为它的返回类型为“List<Transactions>”
【发布时间】:2021-10-05 05:52:16
【问题描述】:

当我添加 where 函数时,我的 dart 代码出现问题,它给了我这个错误 函数“_recentTransactions”无法返回“Iterable”类型的值,因为它的返回类型为“List”

  final List<Transactions> _transactionsList = [

  ];
  List<Transactions> get _recentTransactions{
    return _transactionsList.where((element) => {

    };
  }

【问题讨论】:

    标签: android flutter dart flutter-layout flutter-animation


    【解决方案1】:

    只需调用 toList() 它在 Iterable 类中:

    List<Transactions> get recentTransactions {
      return _transactionsList.where((element) {
        return true // or whatever;
      }).toList();
    }
    

    【讨论】:

      【解决方案2】:

      尝试将您的返回值转换为List&lt;Transactions&gt;

      List<Transactions> get recentTransactions {
        return _transactionsList.where((element) {
          //...
        }) as List<Transactions>;
      }
      

      【讨论】:

      • 谢谢兄弟,它和我一起工作,非常感谢
      猜你喜欢
      • 2022-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 2021-01-25
      • 2021-10-02
      • 2022-07-13
      相关资源
      最近更新 更多