buildClass method Null safety

Class buildClass(
  1. String name
)

Implementation

Class buildClass(String name) {
  final className = name.pascalCase;
  return Class(
    (b) => b
      ..annotations.add(
        const Reference(
          'freezed',
          'package:freezed_annotation/freezed_annotation.dart',
        ),
      )
      ..name = className
      ..mixins.add(Reference('_\$$className'))
      ..constructors.add(
        Constructor(
          (b) => b
            ..constant = true
            ..factory = true
            ..redirect = Reference('_$className')
            ..optionalParameters.addAll(
              fieldValueTypes.entries
                  .map((entry) => entry.value.buildParameter(entry.key)),
            ),
        ),
      )
      ..constructors.add(
        Constructor(
          (b) => b
            ..factory = true
            ..name = 'fromJson'
            ..requiredParameters.add(
              Parameter(
                (b) => b
                  ..name = 'json'
                  ..type = TypeReference(
                    (b) => b
                      ..symbol = 'Map'
                      ..url = 'dart:core'
                      ..types.add(const Reference('String', 'dart:core'))
                      ..types.add(const Reference('dynamic')),
                  ),
              ),
            )
            ..lambda = true
            ..body = InvokeExpression.newOf(
              Reference('_\$${className}FromJson'),
              [const Reference('json')],
            ).code,
        ),
      ),
  );
}