Don't prepend an empty font family when only fontFamilyFallback is set by arthvr9 · Pull Request #194941 · flutter/flutter · GitHub
Skip to content

Don't prepend an empty font family when only fontFamilyFallback is set - #194941

Open
arthvr9 wants to merge 1 commit into
flutter:masterfrom
arthvr9:fix-fontfamily-fallback-194543
Open

arthvr9 wants to merge 1 commit into
flutter:masterfrom
arthvr9:fix-fontfamily-fallback-194543

Conversation

@arthvr9

@arthvr9 arthvr9 commented Oct 21, 2026 •

Copy link
Copy Markdown

TextStyle stored a null fontFamily as '', and ParagraphBuilder.pushStyle always prepended it, so the engine received ['', ...fontFamilyFallback]. The platform default font (FlutterTest in flutter_tester) therefore took precedence over fontFamilyFallback[0], contrary to the TextStyle.fontFamily docs.

This keeps _fontFamily nullable and builds the list as [?fontFamily, ...?fontFamilyFallback], the same way StrutStyle already does.

Added a test in testing/dart/paragraph_test.dart: with only fontFamilyFallback: ['Ahem'], the alphabetic baseline should be 0.8em (Ahem), not 0.75em (FlutterTest). I confirmed it fails on current stable (Expected: <80.0> Actual: <75.0>).

Fixes #194543

Pre-launch Checklist

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems engine flutter/engine related. See also e: labels. labels Oct 21, 2026
@google-cla

google-cla Bot commented Oct 21, 2026

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates TextStyle to support a nullable _fontFamily and simplifies the list construction of font families in pushStyle. It also adds a test case to verify that the first fallback font is preferred when fontFamily is null. The review feedback correctly identifies that the prefix ? syntax used in the collection literal is invalid in Dart and suggests using a collection if statement instead.

Comment thread engine/src/flutter/lib/ui/text.dart
TextStyle stored a null fontFamily as '', and ParagraphBuilder.pushStyle
always prepended it, so the font families passed to the engine were
['', ...fontFamilyFallback]. This made the default font take precedence
over fontFamilyFallback[0], contrary to the TextStyle docs.

Fixes flutter#194543
@arthvr9
arthvr9 force-pushed the fix-fontfamily-fallback-194543 branch from 9354471 to 79916c2 Compare October 21, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextStyle.fontFamily sets the preferred font to "" if only fontFamilyFallback is specified

1 participant