factoryMethod method

String factoryMethod(
  1. String resultType,
  2. String tyArgs,
  3. String constructor
)

Implementation

String factoryMethod(String resultType, String tyArgs, String constructor) {
  String mkFun(String arg, String result) {
    return '''static $resultType $name$tyArgs($arg) =>
        $constructor($name: $result);''';
  }

  if (this.type.isUnit) {
    return mkFun('', 'const ${type.typeRepr}()');
  } else {
    const x = r'__x$';
    return mkFun('${type.typeRepr} $x', x);
  }
}