Skip to content

Commit

Permalink
text [nfc]: Make weightVariableTextStyle's context param required
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbobbe committed May 20, 2024
1 parent c4c5e7e commit c39874d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ class _InlineContentBuilder {
}

InlineSpan _buildStrong(StrongNode node) => _buildNodes(node.nodes,
style: weightVariableTextStyle(_context, wght: 600, wghtIfPlatformRequestsBold: 900));
style: weightVariableTextStyle(_context!, wght: 600, wghtIfPlatformRequestsBold: 900));

InlineSpan _buildDeleted(DeletedNode node) => _buildNodes(node.nodes,
style: const TextStyle(decoration: TextDecoration.lineThrough));
Expand Down
5 changes: 2 additions & 3 deletions lib/widgets/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,12 @@ const kButtonTextLetterSpacingProportion = 0.01;
/// ```
///
/// See also [FontVariation] for more background on variable fonts.
// TODO(a11y) make `context` required when callers can adapt?
TextStyle weightVariableTextStyle(BuildContext? context, {
TextStyle weightVariableTextStyle(BuildContext context, {
double? wght,
double? wghtIfPlatformRequestsBold,
}) {
double value = wght ?? FontWeight.normal.value.toDouble();
if (context != null && MediaQuery.boldTextOf(context)) {
if (MediaQuery.boldTextOf(context)) {
// The framework has a condition on [MediaQueryData.boldText]
// in the [Text] widget, but that only affects `fontWeight`.
// [Text] doesn't know where to land on the chosen font's "wght" axis if any,
Expand Down
9 changes: 0 additions & 9 deletions test/widgets/text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ void main() {
});
}

testWeights('no context passed; default wght values',
styleBuilder: (context) => weightVariableTextStyle(null),
expectedFontVariations: const [FontVariation('wght', 400)],
expectedFontWeight: FontWeight.normal);
testWeights('no context passed; specific wght',
styleBuilder: (context) => weightVariableTextStyle(null, wght: 225, wghtIfPlatformRequestsBold: 425),
expectedFontVariations: const [FontVariation('wght', 225)],
expectedFontWeight: FontWeight.w200);

testWeights('default values; platform does not request bold',
styleBuilder: (context) => weightVariableTextStyle(context),
platformRequestsBold: false,
Expand Down

0 comments on commit c39874d

Please sign in to comment.