Skip to content

Commit baea8c7

Browse files
author
CamronG
committed
add google font loader
1 parent f3e7910 commit baea8c7

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

Diff for: configurator/lib/src/models/processed_config.dart

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ProcessedConfig {
3636
Directive.import( 'package:configurator_flutter/configurator_flutter.dart' ),
3737
Directive.import( 'dart:ui' ),
3838
Directive.import( 'package:slang/builder/model/node.dart' ),
39+
Directive.import( 'package:google_fonts/google_fonts.dart' ),
3940
Directive.export( 'package:slang_flutter/slang_flutter.dart' ),
4041
]);
4142

Diff for: configurator/lib/src/writers/text_style_writer.dart

+16-7
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,24 @@ class TextStyleWriter extends Writer {
6969
return '''
7070
var ts = _config.textStyle( ${name}ConfigKeys.textStyles.${e.key} );
7171
var fontSize = ts["size"] ?? 12.0;
72+
var source = ts["typeface"]?["source"];
7273
var heightAbs = ts["height"] ?? 0.0;
7374
74-
return TextStyle(
75-
color: _ColorUtil.parseColorValue(ts["color"]),
76-
fontSize: fontSize,
77-
fontWeight: _FontUtil.parseFontWeight(ts["weight"] ?? 400),
78-
fontFamily: ts["typeface"]?["family"] ?? "Poppins",
79-
height: heightAbs == 0 ? null : (heightAbs / fontSize),
80-
);
75+
var style = TextStyle(
76+
color: _ColorUtil.parseColorValue(ts["color"]),
77+
fontSize: fontSize,
78+
fontWeight: _FontUtil.parseFontWeight(ts["weight"] ?? 400),
79+
fontFamily: ts["typeface"]?["family"] ?? "Poppins",
80+
height: heightAbs == 0 ? null : (heightAbs / fontSize),
81+
);
82+
83+
if (source == 'GoogleFont') {
84+
try {
85+
return GoogleFonts.getFont(source, textStyle: style);
86+
} catch (_) {}
87+
}
88+
89+
return style;
8190
''';
8291
}
8392

Diff for: configurator_builder/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ dependencies:
2525
configurator:
2626
git:
2727
url: [email protected]:camrongiuliani/configurator.git
28-
ref: 0.0.4
28+
ref: 0.0.5
2929
path: configurator
3030

3131
configurator_annotations:
3232
git:
3333
url: [email protected]:camrongiuliani/configurator.git
34-
ref: 0.0.4
34+
ref: 0.0.5
3535
path: configurator_annotations
3636

3737
meta: ^1.7.0

Diff for: configurator_flutter/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies:
2828
git:
2929
url: [email protected]:camrongiuliani/configurator.git
3030
path: configurator
31-
ref: 0.0.4
31+
ref: 0.0.5
3232

3333
dev_dependencies:
3434
flutter_test:

Diff for: example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ packages:
140140
path: "../configurator"
141141
relative: true
142142
source: path
143-
version: "0.0.1"
143+
version: "0.0.2"
144144
configurator_annotations:
145145
dependency: "direct main"
146146
description:

0 commit comments

Comments
 (0)