createInstanceByType static method

dynamic createInstanceByType(
  1. Type? type,
  2. List? args
)

Creates an instance of an object type.

  • type an object type (factory function) to create.
  • args arguments for the object constructor. Returns the created object instance.

Implementation

static dynamic createInstanceByType(Type? type, List? args) {
  if (type == null) throw Exception('Type constructor cannot be null');

  var cm = reflectClass(type);
  var im = cm.newInstance(Symbol(''), args ?? []);
  return im.reflectee;
}