Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 类型';列表<;动态>';不是类型为';列表<;MSEventH>';内铸_Flutter_Dart - Fatal编程技术网

Flutter 类型';列表<;动态>';不是类型为';列表<;MSEventH>';内铸

Flutter 类型';列表<;动态>';不是类型为';列表<;MSEventH>';内铸,flutter,dart,Flutter,Dart,所以我最近犯了这个错误。我总是指定类型,所以我不知道为什么会出现此错误。。 我使用的代码如下 谢谢你的帮助 List<MSEvent> fetchEvents(); Future<void> cacheEvents(List<MSEvent> events); } class MSEventLocalSourceImpl implements MSEventLocalSource { List<MSEventH> convertList

所以我最近犯了这个错误。我总是指定类型,所以我不知道为什么会出现此错误。。 我使用的代码如下 谢谢你的帮助

  List<MSEvent> fetchEvents();
  Future<void> cacheEvents(List<MSEvent> events);
}
class MSEventLocalSourceImpl implements MSEventLocalSource {
  List<MSEventH> convertList(List<MSEventH> hevents) {
    List<MSEventH> eventList = [];
    for (int i = 0; i < hevents.length; i++) {
      eventList.add(hevents[i]);
    }
    return eventList;
  }
  final localStorageService = locator<LocalStorageService>();
  @override
  List<MSEvent> fetchEvents() {
    List<MSEvent> eventList = [];
    Iterable<List<MSEventH>> heventLists = localStorageService.eventsBox.values;
    List<MSEventH> heventList = heventLists.first;
    if (localStorageService.eventsBox.isEmpty) {
      throw CacheException('No events found in cache');
    }
    try{
      heventList.forEach((eventh) => eventList.add(MSEvent.fromMSEventH(eventh)));
    } catch(e){
      print(e);
    }
    return eventList;
  }
  @override
  Future<void> cacheEvents(List<MSEvent> events) async {
    List<MSEventH> eventList = [];
    events.forEach((event) => eventList.add(MSEventH.fromMSEvent(event)));
    await localStorageService.eventsBox.add(eventList);
  }
}
List fetchEvents();
未来缓存事件(列出事件);
}
类MSEventLocalSourceImpl实现MSEventLocalSource{
列表转换器列表(列表事件){
列表事件列表=[];
for(int i=0;ieventList.add(MSEvent.fromMSEventH(eventh));
}捕获(e){
印刷品(e);
}
返回事件列表;
}
@凌驾
未来缓存事件(列表事件)异步{
列表事件列表=[];
events.forEach((event)=>eventList.add(MSEventH.fromsevent(event));
等待localStorageService.eventsBox.add(eventList);
}
}

听起来像是差异问题。如果
列出heventList=heventLists.first
抛出错误,请尝试使用
List.from(heventLists.first)
创建一个新列表。简而言之,您无法将列表转换为列表,因为Dart不知道动态项是否为MSEventH。你能分享LocalStorageService的代码吗?我认为问题在于localStorageService.eventsBox.values返回的列表没有指定类型,也许您应该在localStorageService上使用泛型。另外,您能告诉我们问题来自哪一行吗?这可能有助于我们识别任何特定问题,谢谢;这行正在抛出错误。localStorageService.eventsBox.values正在返回列表的iterable。这就是我为什么选择第一个。