forked from FlutterGen/flutter_gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfonts_generator.dart
32 lines (27 loc) · 899 Bytes
/
fonts_generator.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import 'package:dart_style/dart_style.dart';
import 'package:dartx/dartx.dart';
import 'package:yaml/yaml.dart';
import '../settings/flutter.dart';
import '../utils/cast.dart';
import '../utils/string.dart';
import 'generator_helper.dart';
String generateFonts(DartFormatter formatter, FlutterFonts fonts) {
assert(fonts != null && fonts.hasFonts,
throw 'The value of "flutter/fonts:" is incorrect.');
final buffer = StringBuffer();
buffer.writeln(header);
buffer.writeln('class FontFamily {');
buffer.writeln(' FontFamily._();');
buffer.writeln();
fonts.fonts
.cast<YamlMap>()
.map((element) => safeCast<String>(element['family']))
.distinct()
.sorted()
.forEach((family) {
buffer
.writeln(" static const String ${family.camelCase()} = \'$family\';");
});
buffer.writeln('}');
return formatter.format(buffer.toString());
}