generateLibrary function Null safety

Library generateLibrary(
  1. List<Spec> body,
  2. List<Element> classesToGenerate
)

Implementation

Library generateLibrary(List<Spec> body, List<Element> classesToGenerate) {
  final imports = classesToGenerate
      .map((clazz) => clazz.library!.identifier)
      .toSet()
      .map((e) => Directive.import(e));

  final lib = Library(
    (b) => b
      ..body.addAll(body)
      ..directives.addAll(
          [Directive.import('package:smartdata/smartdata.dart'), ...imports]),
  );
  return lib;
}