Skip to content

Commit d98a9e3

Browse files
chrisbobbegnprice
authored andcommitted
content [nfc]: Move errorStyle and errorCodeStyle to ContentTheme
1 parent fcc83da commit d98a9e3

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

lib/widgets/content.dart

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
4646
fontFamilyFallback: defaultFontFamilyFallback,
4747
)
4848
.merge(weightVariableTextStyle(context))
49-
.copyWith(debugLabel: 'ContentTheme.textStylePlainParagraph');
49+
.copyWith(debugLabel: 'ContentTheme.textStylePlainParagraph'),
50+
textStyleError = const TextStyle(
51+
fontSize: kBaseFontSize, fontWeight: FontWeight.bold, color: Colors.red),
52+
textStyleErrorCode = kMonospaceTextStyle
53+
.merge(const TextStyle(fontSize: kBaseFontSize, color: Colors.red));
5054

5155
ContentTheme._({
5256
required this.textStylePlainParagraph,
57+
required this.textStyleError,
58+
required this.textStyleErrorCode,
5359
});
5460

5561
/// The [ContentTheme] from the context's active theme.
@@ -70,12 +76,19 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
7076
/// should not need styles from other sources, such as Material defaults.
7177
final TextStyle textStylePlainParagraph;
7278

79+
final TextStyle textStyleError;
80+
final TextStyle textStyleErrorCode;
81+
7382
@override
7483
ContentTheme copyWith({
7584
TextStyle? textStylePlainParagraph,
85+
TextStyle? textStyleError,
86+
TextStyle? textStyleErrorCode,
7687
}) {
7788
return ContentTheme._(
7889
textStylePlainParagraph: textStylePlainParagraph ?? this.textStylePlainParagraph,
90+
textStyleError: textStyleError ?? this.textStyleError,
91+
textStyleErrorCode: textStyleErrorCode ?? this.textStyleErrorCode,
7992
);
8093
}
8194

@@ -86,6 +99,8 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
8699
}
87100
return ContentTheme._(
88101
textStylePlainParagraph: TextStyle.lerp(textStylePlainParagraph, other?.textStylePlainParagraph, t)!,
102+
textStyleError: TextStyle.lerp(textStyleError, other?.textStyleError, t)!,
103+
textStyleErrorCode: TextStyle.lerp(textStyleErrorCode, other?.textStyleErrorCode, t)!,
89104
);
90105
}
91106
}
@@ -175,7 +190,7 @@ class BlockContentList extends StatelessWidget {
175190
} else if (node is EmbedVideoNode) {
176191
return MessageEmbedVideo(node: node);
177192
} else if (node is UnimplementedBlockContentNode) {
178-
return Text.rich(_errorUnimplemented(node));
193+
return Text.rich(_errorUnimplemented(node, context: context));
179194
} else {
180195
// TODO(dart-3): Use a sealed class / pattern-matching to exclude this.
181196
throw Exception("impossible BlockContentNode: ${node.debugHtmlText}");
@@ -836,7 +851,7 @@ class _InlineContentBuilder {
836851
return WidgetSpan(alignment: PlaceholderAlignment.middle,
837852
child: GlobalTime(node: node, ambientTextStyle: widget.style));
838853
} else if (node is UnimplementedInlineContentNode) {
839-
return _errorUnimplemented(node);
854+
return _errorUnimplemented(node, context: _context!);
840855
} else {
841856
// TODO(dart-3): Use a sealed class / pattern matching to eliminate this case.
842857
throw Exception("impossible InlineContentNode: ${node.debugHtmlText}");
@@ -1326,33 +1341,30 @@ class AvatarShape extends StatelessWidget {
13261341
// Small helpers.
13271342
//
13281343

1329-
InlineSpan _errorUnimplemented(UnimplementedNode node) {
1344+
InlineSpan _errorUnimplemented(UnimplementedNode node, {required BuildContext context}) {
1345+
final contentTheme = ContentTheme.of(context);
1346+
final errorStyle = contentTheme.textStyleError;
1347+
final errorCodeStyle = contentTheme.textStyleErrorCode;
13301348
// For now this shows error-styled HTML code even in release mode,
13311349
// because release mode isn't yet about general users but developer demos,
13321350
// and we want to keep the demos honest.
13331351
// TODO(#194) think through UX for general release
13341352
final htmlNode = node.htmlNode;
13351353
if (htmlNode is dom.Element) {
13361354
return TextSpan(children: [
1337-
const TextSpan(text: "(unimplemented:", style: errorStyle),
1355+
TextSpan(text: "(unimplemented:", style: errorStyle),
13381356
TextSpan(text: htmlNode.outerHtml, style: errorCodeStyle),
1339-
const TextSpan(text: ")", style: errorStyle),
1357+
TextSpan(text: ")", style: errorStyle),
13401358
]);
13411359
} else if (htmlNode is dom.Text) {
13421360
return TextSpan(children: [
1343-
const TextSpan(text: "(unimplemented: text «", style: errorStyle),
1361+
TextSpan(text: "(unimplemented: text «", style: errorStyle),
13441362
TextSpan(text: htmlNode.text, style: errorCodeStyle),
1345-
const TextSpan(text: "»)", style: errorStyle),
1363+
TextSpan(text: "»)", style: errorStyle),
13461364
]);
13471365
} else {
13481366
return TextSpan(
13491367
text: "(unimplemented: DOM node type ${htmlNode.nodeType})",
13501368
style: errorStyle);
13511369
}
13521370
}
1353-
1354-
const errorStyle = TextStyle(
1355-
fontSize: kBaseFontSize, fontWeight: FontWeight.bold, color: Colors.red);
1356-
1357-
final errorCodeStyle = kMonospaceTextStyle
1358-
.merge(const TextStyle(fontSize: kBaseFontSize, color: Colors.red));

0 commit comments

Comments
 (0)