generateFonts function

String generateFonts(
  1. DartFormatter formatter,
  2. List<FlutterFonts> fonts,
  3. FlutterGenFonts fontsConfig
)

Implementation

String generateFonts(
  DartFormatter formatter,
  List<FlutterFonts> fonts,
  FlutterGenFonts fontsConfig,
) {
  if (fonts.isEmpty) {
    throw InvalidSettingsException(
        'The value of "flutter/fonts:" is incorrect.');
  }

  final buffer = StringBuffer();
  final className = fontsConfig.outputs.className;
  buffer.writeln(header);
  buffer.writeln(ignore);
  buffer.writeln('class $className {');
  buffer.writeln('$className._();');
  buffer.writeln();

  fonts.map((element) => element.family).distinct().sorted().forEach((family) {
    buffer.writeln("""/// Font family: $family
    static const String ${family.camelCase()} = '$family';""");
  });

  buffer.writeln('}');
  return formatter.format(buffer.toString());
}