【问题标题】:Flutter How to convert List <string>to List<custom type>? Event typeFlutter 如何将 List <string> 转换为 List<custom type>?事件类型
【发布时间】:2022-06-27 17:53:13
【问题描述】:

我尝试在我的项目中保留 Event 数据类型

loadEventList() async {
  await _init();
  final _ev = _prefs.getStringList('eventList');
  List<Event> listToEvent = _ev as List<Event>;
  return _events = listToEvent;
}

我遇到了这个错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'List<String>' is not a subtype of type 'List<Event>' in type cast

有人可以帮我找到将我的列表转换为事件列表的方法吗?

【问题讨论】:

    标签: android flutter events calendar


    【解决方案1】:

    我认为使用地图功能会有所帮助

    _events = _ev.map((String element){return  Event(param);});
    

    【讨论】:

      猜你喜欢
      • 2019-02-16
      • 2017-03-11
      • 1970-01-01
      • 2020-01-11
      • 2013-08-26
      • 1970-01-01
      • 2020-11-27
      • 2018-10-06
      • 2021-08-29
      相关资源
      最近更新 更多