List 类型';列表<;动态>';不是类型为';列表<;MyData>';,颤振
在flatter小部件中,我将List 类型';列表<;动态>';不是类型为';列表<;MyData>';,颤振,list,flutter,dynamic,casting,List,Flutter,Dynamic,Casting,在flatter小部件中,我将MyData类型的对象列表与Hive包一起存储在内存中 但是当Hive返回数据时,它会在列表中返回数据,我想将其转换为列表,但这样做会产生以下错误 E/flutter (22594): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<MyData>' E/
MyData
类型的对象列表与Hive包一起存储在内存中
但是当Hive返回数据时,它会在列表中返回数据,我想将其转换为列表,但这样做会产生以下错误
E/flutter (22594): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<MyData>'
E/flatter(22594):[错误:flatter/lib/ui/ui\u dart\u state.cc(157)]未处理的异常:类型“List”不是类型“List”的子类型
代码:
List data=(monthBox.get(DateTime.now().day).toList()作为列表);
我们可以将List
转换为List
而不进行迭代吗
List<MyData> data = (monthBox.get(DateTime.now().day).toList() as List<MyData>);