Skip to content

text: Convert the last uses of FontWeight.bold to weightVariableTextStyle #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'page.dart';
import 'recent_dm_conversations.dart';
import 'store.dart';
import 'subscription_list.dart';
import 'text.dart';
import 'theme.dart';

class ZulipApp extends StatefulWidget {
Expand Down Expand Up @@ -242,7 +243,8 @@ class HomePage extends StatelessWidget {
final zulipLocalizations = ZulipLocalizations.of(context);

InlineSpan bold(String text) => TextSpan(
text: text, style: const TextStyle(fontWeight: FontWeight.bold));
style: const TextStyle().merge(weightVariableTextStyle(context, wght: 700)),
text: text);

int? testStreamId;
if (store.connection.realmUrl.origin == 'https://chat.zulip.org') {
Expand Down
40 changes: 26 additions & 14 deletions lib/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
fontFamilyFallback: defaultFontFamilyFallback,
)
.merge(weightVariableTextStyle(context))
.copyWith(debugLabel: 'ContentTheme.textStylePlainParagraph');
.copyWith(debugLabel: 'ContentTheme.textStylePlainParagraph'),
textStyleError = const TextStyle(fontSize: kBaseFontSize, color: Colors.red)
.merge(weightVariableTextStyle(context, wght: 700)),
textStyleErrorCode = kMonospaceTextStyle
.merge(const TextStyle(fontSize: kBaseFontSize, color: Colors.red));

ContentTheme._({
required this.textStylePlainParagraph,
required this.textStyleError,
required this.textStyleErrorCode,
});

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

final TextStyle textStyleError;
final TextStyle textStyleErrorCode;

@override
ContentTheme copyWith({
TextStyle? textStylePlainParagraph,
TextStyle? textStyleError,
TextStyle? textStyleErrorCode,
}) {
return ContentTheme._(
textStylePlainParagraph: textStylePlainParagraph ?? this.textStylePlainParagraph,
textStyleError: textStyleError ?? this.textStyleError,
textStyleErrorCode: textStyleErrorCode ?? this.textStyleErrorCode,
);
}

Expand All @@ -86,6 +99,8 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
}
return ContentTheme._(
textStylePlainParagraph: TextStyle.lerp(textStylePlainParagraph, other?.textStylePlainParagraph, t)!,
textStyleError: TextStyle.lerp(textStyleError, other?.textStyleError, t)!,
textStyleErrorCode: TextStyle.lerp(textStyleErrorCode, other?.textStyleErrorCode, t)!,
);
}
}
Expand Down Expand Up @@ -175,7 +190,7 @@ class BlockContentList extends StatelessWidget {
} else if (node is EmbedVideoNode) {
return MessageEmbedVideo(node: node);
} else if (node is UnimplementedBlockContentNode) {
return Text.rich(_errorUnimplemented(node));
return Text.rich(_errorUnimplemented(node, context: context));
} else {
// TODO(dart-3): Use a sealed class / pattern-matching to exclude this.
throw Exception("impossible BlockContentNode: ${node.debugHtmlText}");
Expand Down Expand Up @@ -836,7 +851,7 @@ class _InlineContentBuilder {
return WidgetSpan(alignment: PlaceholderAlignment.middle,
child: GlobalTime(node: node, ambientTextStyle: widget.style));
} else if (node is UnimplementedInlineContentNode) {
return _errorUnimplemented(node);
return _errorUnimplemented(node, context: _context!);
} else {
// TODO(dart-3): Use a sealed class / pattern matching to eliminate this case.
throw Exception("impossible InlineContentNode: ${node.debugHtmlText}");
Expand Down Expand Up @@ -1326,33 +1341,30 @@ class AvatarShape extends StatelessWidget {
// Small helpers.
//

InlineSpan _errorUnimplemented(UnimplementedNode node) {
InlineSpan _errorUnimplemented(UnimplementedNode node, {required BuildContext context}) {
final contentTheme = ContentTheme.of(context);
final errorStyle = contentTheme.textStyleError;
final errorCodeStyle = contentTheme.textStyleErrorCode;
// For now this shows error-styled HTML code even in release mode,
// because release mode isn't yet about general users but developer demos,
// and we want to keep the demos honest.
// TODO(#194) think through UX for general release
final htmlNode = node.htmlNode;
if (htmlNode is dom.Element) {
return TextSpan(children: [
const TextSpan(text: "(unimplemented:", style: errorStyle),
TextSpan(text: "(unimplemented:", style: errorStyle),
TextSpan(text: htmlNode.outerHtml, style: errorCodeStyle),
const TextSpan(text: ")", style: errorStyle),
TextSpan(text: ")", style: errorStyle),
]);
} else if (htmlNode is dom.Text) {
return TextSpan(children: [
const TextSpan(text: "(unimplemented: text «", style: errorStyle),
TextSpan(text: "(unimplemented: text «", style: errorStyle),
TextSpan(text: htmlNode.text, style: errorCodeStyle),
const TextSpan(text: "»)", style: errorStyle),
TextSpan(text: "»)", style: errorStyle),
]);
} else {
return TextSpan(
text: "(unimplemented: DOM node type ${htmlNode.nodeType})",
style: errorStyle);
}
}

const errorStyle = TextStyle(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content [nfc]: Move codeStyle to ContentTheme

Do you mean s/codeStyle/errorStyle/?

fontSize: kBaseFontSize, fontWeight: FontWeight.bold, color: Colors.red);

final errorCodeStyle = kMonospaceTextStyle
.merge(const TextStyle(fontSize: kBaseFontSize, color: Colors.red));
15 changes: 11 additions & 4 deletions lib/widgets/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import 'content.dart';
import 'message_list.dart';
import 'page.dart';
import 'store.dart';
import 'text.dart';

class _TextStyles {
static const primaryFieldText = TextStyle(fontSize: 20);
static const customProfileFieldLabel = TextStyle(fontSize: 15, fontWeight: FontWeight.bold);

static TextStyle customProfileFieldLabel(BuildContext context) =>
const TextStyle(fontSize: 15)
.merge(weightVariableTextStyle(context, wght: 700));

static const customProfileFieldText = TextStyle(fontSize: 15);
}

Expand Down Expand Up @@ -43,7 +48,8 @@ class ProfilePage extends StatelessWidget {
const SizedBox(height: 16),
Text(user.fullName,
textAlign: TextAlign.center,
style: _TextStyles.primaryFieldText.merge(const TextStyle(fontWeight: FontWeight.bold))),
style: _TextStyles.primaryFieldText
.merge(weightVariableTextStyle(context, wght: 700))),
// TODO(#291) render email field
Text(roleToLabel(user.role, zulipLocalizations),
textAlign: TextAlign.center,
Expand Down Expand Up @@ -191,8 +197,9 @@ class _ProfileDataTable extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
SizedBox(width: 96,
child: Text(realmField.name, style: _TextStyles.customProfileFieldLabel)),
SizedBox(width: 100,
child: Text(style: _TextStyles.customProfileFieldLabel(context),
realmField.name)),
const SizedBox(width: 8),
Flexible(child: widget),
]));
Expand Down
Loading