【问题标题】:Return list works with from only "Dart"返回列表仅适用于 \"Dart\"
【发布时间】:2022-11-01 19:01:20
【问题描述】:

我必须从 function() 获取列表 当我直接返回此列表时,出现错误 而当我先用 List.from 填充它时,它工作正常 这是一个例子

/// This Make an Error "IDE" don't print errors just stop compiling tree

  static List<Event> get eventList => cacheImpl.get('HiveBoxName');

/// This Working Fine

  static List<Event> get eventList2 => List.from(cacheImpl.get('HiveBoxName'));

那么为什么它只适用于 List from 呢?

【问题讨论】:

  • 请添加您从中创建 cacheImpl 实例的类的源代码。添加你得到的错误
  • 我已将示例编辑得更清楚
  • 但是您粘贴了与图像相同的代码
  • cachImp 仅调用获取本地数据的配置单元实现
  • cacheImpl.get('HiveBoxName') 返回什么类型的数据

标签: flutter dart


【解决方案1】:

尝试将其转换为列表

 static List<Event> get eventList => cacheImpl.get('HiveBoxName').toList();

【讨论】:

  • 是的,我做过也没有工作
  • 你能显示正在调用的函数代码吗?
猜你喜欢
  • 2021-12-30
  • 1970-01-01
  • 2021-06-13
  • 2014-02-07
  • 2020-03-21
  • 2014-09-07
  • 2016-01-23
  • 2015-12-31
  • 1970-01-01
相关资源
最近更新 更多