toTypeList method

List? toTypeList(
  1. List? source, {
  2. required bool canNull,
})

内部定义的类型的T为VmVlue,如果使用T进行转换后,某些情况会报错 => type 'VmInstance' is not a subtype of type 'VmValue' of 'value' 如:

 var arr = <InnerClass>[];
 var val = InnerClass();
 arr.add(val); // throw => type 'VmInstance' is not a subtype of type 'VmValue' of 'value'

转换为精确的List

Implementation

///转换为精确的List<T>类型
List? toTypeList(List? source, {required bool canNull}) {
  if (source == null || !isExternal) return source;
  if (canNull) {
    return List<T?>.from(source);
  } else {
    return List<T>.from(source);
  }
}