createInstance static method

dynamic createInstance(
  1. Type? type, [
  2. Symbol? constructor,
  3. List? arguments,
  4. Map<Symbol, dynamic>? namedArguments,
])

Implementation

static dynamic createInstance(Type? type,
    [Symbol? constructor,
    List? arguments,
    Map<Symbol, dynamic>? namedArguments]) {
  if (type == null) {
    throw ArgumentError("type: $type");
  }

  final typeMirror = reflectType(type);
  if (typeMirror is ClassMirror) {
    return typeMirror
        .newInstance(constructor ?? const Symbol(""), arguments ?? const [],
            namedArguments ?? {})
        .reflectee;
  } else {
    throw ArgumentError("Cannot create the instance of the type '$type'.");
  }
}