Skip to content

Commit e84f129

Browse files
Refactor to use Apple system fonts (#137275)
Addresses #63507, and is a follow up to the engine PR flutter/engine#46857 Changes the font family string when attempting to use Apple system fonts to the new proxies added by the engine. For the "Text" font this will be more secure in the future against possible changes to Apple's API. For the "Display" font, this will now work correctly when it didn't before. I checked the letter spacing values against a native app for all font sizes between 17-28. I made a few adjustments to better match native, but especially for the "Text" font we were either really close, or close enough to not make a large breaking change to default fonts worth it. | Before | After | | ------------- | ------------- | | <img width="466" alt="Screenshot 2023-11-02 at 11 45 12�AM" src="https://github.com/flutter/flutter/assets/58190796/627ed8ac-d848-4f71-aa62-a467b8aac62d"> | <img width="383" alt="Screenshot 2023-11-02 at 11 46 25�AM" src="https://github.com/flutter/flutter/assets/58190796/9a502021-7d2b-4e14-98f1-86971b3830a5"> | The smaller text in both the before and after should be the same. The large system font that Flutter used before was incorrect, which caused it to look more spread out. Now we use the correct font.
1 parent 4f8a991 commit e84f129

File tree

13 files changed

+99
-82
lines changed

13 files changed

+99
-82
lines changed

dev/integration_tests/flutter_gallery/lib/demo/cupertino/cupertino_text_field_demo.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class _CupertinoTextFieldDemoState extends State<CupertinoTextFieldDemo> {
153153
Widget build(BuildContext context) {
154154
return DefaultTextStyle(
155155
style: const TextStyle(
156-
fontFamily: '.SF UI Text',
156+
fontFamily: 'CupertinoSystemText',
157157
inherit: false,
158158
fontSize: 17.0,
159159
color: CupertinoColors.black,

packages/flutter/lib/src/cupertino/context_menu_action.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class _CupertinoContextMenuActionState extends State<CupertinoContextMenuAction>
5757
);
5858
static const double _kButtonHeight = 43;
5959
static const TextStyle _kActionSheetActionStyle = TextStyle(
60-
fontFamily: '.SF UI Text',
60+
fontFamily: 'CupertinoSystemText',
6161
inherit: false,
6262
fontSize: 16.0,
6363
fontWeight: FontWeight.w400,

packages/flutter/lib/src/cupertino/dialog.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import 'theme.dart';
2323
// Apple Design Resources(https://developer.apple.com/design/resources/).
2424
// However the values are not exactly the same as native, so eyeballing is needed.
2525
const TextStyle _kCupertinoDialogTitleStyle = TextStyle(
26-
fontFamily: '.SF UI Display',
26+
fontFamily: 'CupertinoSystemDisplay',
2727
inherit: false,
2828
fontSize: 17.0,
2929
fontWeight: FontWeight.w600,
@@ -33,7 +33,7 @@ const TextStyle _kCupertinoDialogTitleStyle = TextStyle(
3333
);
3434

3535
const TextStyle _kCupertinoDialogContentStyle = TextStyle(
36-
fontFamily: '.SF UI Text',
36+
fontFamily: 'CupertinoSystemText',
3737
inherit: false,
3838
fontSize: 13.0,
3939
fontWeight: FontWeight.w400,
@@ -43,7 +43,7 @@ const TextStyle _kCupertinoDialogContentStyle = TextStyle(
4343
);
4444

4545
const TextStyle _kCupertinoDialogActionStyle = TextStyle(
46-
fontFamily: '.SF UI Text',
46+
fontFamily: 'CupertinoSystemText',
4747
inherit: false,
4848
fontSize: 16.8,
4949
fontWeight: FontWeight.w400,
@@ -52,15 +52,15 @@ const TextStyle _kCupertinoDialogActionStyle = TextStyle(
5252

5353
// CupertinoActionSheet-specific text styles.
5454
const TextStyle _kActionSheetActionStyle = TextStyle(
55-
fontFamily: '.SF UI Text',
55+
fontFamily: 'CupertinoSystemText',
5656
inherit: false,
5757
fontSize: 20.0,
5858
fontWeight: FontWeight.w400,
5959
textBaseline: TextBaseline.alphabetic,
6060
);
6161

6262
const TextStyle _kActionSheetContentStyle = TextStyle(
63-
fontFamily: '.SF UI Text',
63+
fontFamily: 'CupertinoSystemText',
6464
inherit: false,
6565
fontSize: 13.0,
6666
fontWeight: FontWeight.w400,

packages/flutter/lib/src/cupertino/text_theme.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'colors.dart';
1414
// Values derived from https://developer.apple.com/design/resources/.
1515
const TextStyle _kDefaultTextStyle = TextStyle(
1616
inherit: false,
17-
fontFamily: '.SF Pro Text',
17+
fontFamily: 'CupertinoSystemText',
1818
fontSize: 17.0,
1919
letterSpacing: -0.41,
2020
color: CupertinoColors.label,
@@ -28,7 +28,7 @@ const TextStyle _kDefaultTextStyle = TextStyle(
2828
// Values derived from https://developer.apple.com/design/resources/.
2929
const TextStyle _kDefaultActionTextStyle = TextStyle(
3030
inherit: false,
31-
fontFamily: '.SF Pro Text',
31+
fontFamily: 'CupertinoSystemText',
3232
fontSize: 17.0,
3333
letterSpacing: -0.41,
3434
color: CupertinoColors.activeBlue,
@@ -42,7 +42,7 @@ const TextStyle _kDefaultActionTextStyle = TextStyle(
4242
// Values derived from https://developer.apple.com/design/resources/.
4343
const TextStyle _kDefaultTabLabelTextStyle = TextStyle(
4444
inherit: false,
45-
fontFamily: '.SF Pro Text',
45+
fontFamily: 'CupertinoSystemText',
4646
fontSize: 10.0,
4747
fontWeight: FontWeight.w500,
4848
letterSpacing: -0.24,
@@ -51,7 +51,7 @@ const TextStyle _kDefaultTabLabelTextStyle = TextStyle(
5151

5252
const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle(
5353
inherit: false,
54-
fontFamily: '.SF Pro Text',
54+
fontFamily: 'CupertinoSystemText',
5555
fontSize: 17.0,
5656
fontWeight: FontWeight.w600,
5757
letterSpacing: -0.41,
@@ -60,10 +60,10 @@ const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle(
6060

6161
const TextStyle _kDefaultLargeTitleTextStyle = TextStyle(
6262
inherit: false,
63-
fontFamily: '.SF Pro Display',
63+
fontFamily: 'CupertinoSystemDisplay',
6464
fontSize: 34.0,
6565
fontWeight: FontWeight.w700,
66-
letterSpacing: 0.41,
66+
letterSpacing: 0.38,
6767
color: CupertinoColors.label,
6868
);
6969

@@ -80,7 +80,7 @@ const TextStyle _kDefaultLargeTitleTextStyle = TextStyle(
8080
// * https://github.com/flutter/flutter/pull/65501#discussion_r486557093
8181
const TextStyle _kDefaultPickerTextStyle = TextStyle(
8282
inherit: false,
83-
fontFamily: '.SF Pro Display',
83+
fontFamily: 'CupertinoSystemDisplay',
8484
fontSize: 21.0,
8585
fontWeight: FontWeight.w400,
8686
letterSpacing: -0.6,
@@ -95,8 +95,9 @@ const TextStyle _kDefaultPickerTextStyle = TextStyle(
9595
// Value extracted from off-center labels. Centered labels have a font size of 25pt.
9696
const TextStyle _kDefaultDateTimePickerTextStyle = TextStyle(
9797
inherit: false,
98-
fontFamily: '.SF Pro Display',
98+
fontFamily: 'CupertinoSystemDisplay',
9999
fontSize: 21,
100+
letterSpacing: 0.4,
100101
fontWeight: FontWeight.normal,
101102
color: CupertinoColors.label,
102103
);

packages/flutter/lib/src/material/typography.dart

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -507,21 +507,21 @@ class Typography with Diagnosticable {
507507
///
508508
/// This theme uses the iOS version of the font names.
509509
static const TextTheme blackCupertino = TextTheme(
510-
displayLarge: TextStyle(debugLabel: 'blackCupertino displayLarge', fontFamily: '.SF UI Display', color: Colors.black54, decoration: TextDecoration.none),
511-
displayMedium: TextStyle(debugLabel: 'blackCupertino displayMedium', fontFamily: '.SF UI Display', color: Colors.black54, decoration: TextDecoration.none),
512-
displaySmall: TextStyle(debugLabel: 'blackCupertino displaySmall', fontFamily: '.SF UI Display', color: Colors.black54, decoration: TextDecoration.none),
513-
headlineLarge: TextStyle(debugLabel: 'blackCupertino headlineLarge', fontFamily: '.SF UI Display', color: Colors.black54, decoration: TextDecoration.none),
514-
headlineMedium: TextStyle(debugLabel: 'blackCupertino headlineMedium', fontFamily: '.SF UI Display', color: Colors.black54, decoration: TextDecoration.none),
515-
headlineSmall: TextStyle(debugLabel: 'blackCupertino headlineSmall', fontFamily: '.SF UI Display', color: Colors.black87, decoration: TextDecoration.none),
516-
titleLarge: TextStyle(debugLabel: 'blackCupertino titleLarge', fontFamily: '.SF UI Display', color: Colors.black87, decoration: TextDecoration.none),
517-
titleMedium: TextStyle(debugLabel: 'blackCupertino titleMedium', fontFamily: '.SF UI Text', color: Colors.black87, decoration: TextDecoration.none),
518-
titleSmall: TextStyle(debugLabel: 'blackCupertino titleSmall', fontFamily: '.SF UI Text', color: Colors.black, decoration: TextDecoration.none),
519-
bodyLarge: TextStyle(debugLabel: 'blackCupertino bodyLarge', fontFamily: '.SF UI Text', color: Colors.black87, decoration: TextDecoration.none),
520-
bodyMedium: TextStyle(debugLabel: 'blackCupertino bodyMedium', fontFamily: '.SF UI Text', color: Colors.black87, decoration: TextDecoration.none),
521-
bodySmall: TextStyle(debugLabel: 'blackCupertino bodySmall', fontFamily: '.SF UI Text', color: Colors.black54, decoration: TextDecoration.none),
522-
labelLarge: TextStyle(debugLabel: 'blackCupertino labelLarge', fontFamily: '.SF UI Text', color: Colors.black87, decoration: TextDecoration.none),
523-
labelMedium: TextStyle(debugLabel: 'blackCupertino labelMedium', fontFamily: '.SF UI Text', color: Colors.black, decoration: TextDecoration.none),
524-
labelSmall: TextStyle(debugLabel: 'blackCupertino labelSmall', fontFamily: '.SF UI Text', color: Colors.black, decoration: TextDecoration.none),
510+
displayLarge: TextStyle(debugLabel: 'blackCupertino displayLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none),
511+
displayMedium: TextStyle(debugLabel: 'blackCupertino displayMedium', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none),
512+
displaySmall: TextStyle(debugLabel: 'blackCupertino displaySmall', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none),
513+
headlineLarge: TextStyle(debugLabel: 'blackCupertino headlineLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none),
514+
headlineMedium: TextStyle(debugLabel: 'blackCupertino headlineMedium', fontFamily: 'CupertinoSystemDisplay', color: Colors.black54, decoration: TextDecoration.none),
515+
headlineSmall: TextStyle(debugLabel: 'blackCupertino headlineSmall', fontFamily: 'CupertinoSystemDisplay', color: Colors.black87, decoration: TextDecoration.none),
516+
titleLarge: TextStyle(debugLabel: 'blackCupertino titleLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.black87, decoration: TextDecoration.none),
517+
titleMedium: TextStyle(debugLabel: 'blackCupertino titleMedium', fontFamily: 'CupertinoSystemText', color: Colors.black87, decoration: TextDecoration.none),
518+
titleSmall: TextStyle(debugLabel: 'blackCupertino titleSmall', fontFamily: 'CupertinoSystemText', color: Colors.black, decoration: TextDecoration.none),
519+
bodyLarge: TextStyle(debugLabel: 'blackCupertino bodyLarge', fontFamily: 'CupertinoSystemText', color: Colors.black87, decoration: TextDecoration.none),
520+
bodyMedium: TextStyle(debugLabel: 'blackCupertino bodyMedium', fontFamily: 'CupertinoSystemText', color: Colors.black87, decoration: TextDecoration.none),
521+
bodySmall: TextStyle(debugLabel: 'blackCupertino bodySmall', fontFamily: 'CupertinoSystemText', color: Colors.black54, decoration: TextDecoration.none),
522+
labelLarge: TextStyle(debugLabel: 'blackCupertino labelLarge', fontFamily: 'CupertinoSystemText', color: Colors.black87, decoration: TextDecoration.none),
523+
labelMedium: TextStyle(debugLabel: 'blackCupertino labelMedium', fontFamily: 'CupertinoSystemText', color: Colors.black, decoration: TextDecoration.none),
524+
labelSmall: TextStyle(debugLabel: 'blackCupertino labelSmall', fontFamily: 'CupertinoSystemText', color: Colors.black, decoration: TextDecoration.none),
525525
);
526526

527527
/// A Material Design text theme with light glyphs based on San Francisco.
@@ -530,21 +530,21 @@ class Typography with Diagnosticable {
530530
///
531531
/// This theme uses the iOS version of the font names.
532532
static const TextTheme whiteCupertino = TextTheme(
533-
displayLarge: TextStyle(debugLabel: 'whiteCupertino displayLarge', fontFamily: '.SF UI Display', color: Colors.white70, decoration: TextDecoration.none),
534-
displayMedium: TextStyle(debugLabel: 'whiteCupertino displayMedium', fontFamily: '.SF UI Display', color: Colors.white70, decoration: TextDecoration.none),
535-
displaySmall: TextStyle(debugLabel: 'whiteCupertino displaySmall', fontFamily: '.SF UI Display', color: Colors.white70, decoration: TextDecoration.none),
536-
headlineLarge: TextStyle(debugLabel: 'whiteCupertino headlineLarge', fontFamily: '.SF UI Display', color: Colors.white70, decoration: TextDecoration.none),
537-
headlineMedium: TextStyle(debugLabel: 'whiteCupertino headlineMedium', fontFamily: '.SF UI Display', color: Colors.white70, decoration: TextDecoration.none),
538-
headlineSmall: TextStyle(debugLabel: 'whiteCupertino headlineSmall', fontFamily: '.SF UI Display', color: Colors.white, decoration: TextDecoration.none),
539-
titleLarge: TextStyle(debugLabel: 'whiteCupertino titleLarge', fontFamily: '.SF UI Display', color: Colors.white, decoration: TextDecoration.none),
540-
titleMedium: TextStyle(debugLabel: 'whiteCupertino titleMedium', fontFamily: '.SF UI Text', color: Colors.white, decoration: TextDecoration.none),
541-
titleSmall: TextStyle(debugLabel: 'whiteCupertino titleSmall', fontFamily: '.SF UI Text', color: Colors.white, decoration: TextDecoration.none),
542-
bodyLarge: TextStyle(debugLabel: 'whiteCupertino bodyLarge', fontFamily: '.SF UI Text', color: Colors.white, decoration: TextDecoration.none),
543-
bodyMedium: TextStyle(debugLabel: 'whiteCupertino bodyMedium', fontFamily: '.SF UI Text', color: Colors.white, decoration: TextDecoration.none),
544-
bodySmall: TextStyle(debugLabel: 'whiteCupertino bodySmall', fontFamily: '.SF UI Text', color: Colors.white70, decoration: TextDecoration.none),
545-
labelLarge: TextStyle(debugLabel: 'whiteCupertino labelLarge', fontFamily: '.SF UI Text', color: Colors.white, decoration: TextDecoration.none),
546-
labelMedium: TextStyle(debugLabel: 'whiteCupertino labelMedium', fontFamily: '.SF UI Text', color: Colors.white, decoration: TextDecoration.none),
547-
labelSmall: TextStyle(debugLabel: 'whiteCupertino labelSmall', fontFamily: '.SF UI Text', color: Colors.white, decoration: TextDecoration.none),
533+
displayLarge: TextStyle(debugLabel: 'whiteCupertino displayLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none),
534+
displayMedium: TextStyle(debugLabel: 'whiteCupertino displayMedium', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none),
535+
displaySmall: TextStyle(debugLabel: 'whiteCupertino displaySmall', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none),
536+
headlineLarge: TextStyle(debugLabel: 'whiteCupertino headlineLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none),
537+
headlineMedium: TextStyle(debugLabel: 'whiteCupertino headlineMedium', fontFamily: 'CupertinoSystemDisplay', color: Colors.white70, decoration: TextDecoration.none),
538+
headlineSmall: TextStyle(debugLabel: 'whiteCupertino headlineSmall', fontFamily: 'CupertinoSystemDisplay', color: Colors.white, decoration: TextDecoration.none),
539+
titleLarge: TextStyle(debugLabel: 'whiteCupertino titleLarge', fontFamily: 'CupertinoSystemDisplay', color: Colors.white, decoration: TextDecoration.none),
540+
titleMedium: TextStyle(debugLabel: 'whiteCupertino titleMedium', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none),
541+
titleSmall: TextStyle(debugLabel: 'whiteCupertino titleSmall', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none),
542+
bodyLarge: TextStyle(debugLabel: 'whiteCupertino bodyLarge', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none),
543+
bodyMedium: TextStyle(debugLabel: 'whiteCupertino bodyMedium', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none),
544+
bodySmall: TextStyle(debugLabel: 'whiteCupertino bodySmall', fontFamily: 'CupertinoSystemText', color: Colors.white70, decoration: TextDecoration.none),
545+
labelLarge: TextStyle(debugLabel: 'whiteCupertino labelLarge', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none),
546+
labelMedium: TextStyle(debugLabel: 'whiteCupertino labelMedium', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none),
547+
labelSmall: TextStyle(debugLabel: 'whiteCupertino labelSmall', fontFamily: 'CupertinoSystemText', color: Colors.white, decoration: TextDecoration.none),
548548
);
549549

550550
/// A Material Design text theme with dark glyphs based on San Francisco.

packages/flutter/lib/src/painting/text_style.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ const String _kColorBackgroundWarning = 'Cannot provide both a backgroundColor a
433433
/// By default, fonts differ depending on the platform.
434434
///
435435
/// * The default font-family for `Android`,`Fuchsia` and `Linux` is `Roboto`.
436-
/// * The default font-family for `iOS` is `.SF UI Display`/`.SF UI Text`.
436+
/// * The default font-family for `iOS` is `SF Pro Display`/`SF Pro Text`.
437437
/// * The default font-family for `MacOS` is `.AppleSystemUIFont`.
438438
/// * The default font-family for `Windows` is `Segoe UI`.
439439
//
@@ -470,6 +470,14 @@ class TextStyle with Diagnosticable {
470470
/// The `package` argument must be non-null if the font family is defined in a
471471
/// package. It is combined with the `fontFamily` argument to set the
472472
/// [fontFamily] property.
473+
///
474+
/// On Apple devices the strings 'CupertinoSystemText' and
475+
/// 'CupertinoSystemDisplay' are used in [fontFamily] as proxies for the
476+
/// Apple system fonts. They currently redirect to the equivilant of SF Pro
477+
/// Text and SF Pro Display respectively. 'CupertinoSystemText' is designed
478+
/// for fonts below 20 point size, and 'CupertinoSystemDisplay' is recommended
479+
/// for sizes 20 and above. When used on non-Apple platforms, these strings
480+
/// will return the regular fallback font family instead.
473481
const TextStyle({
474482
this.inherit = true,
475483
this.color,
@@ -561,6 +569,14 @@ class TextStyle with Diagnosticable {
561569
/// first value in [fontFamilyFallback] acts as the preferred/first font
562570
/// family. When neither is provided, then the default platform font will
563571
/// be used.
572+
///
573+
/// When running on Apple devices, the strings 'CupertinoSystemText' and
574+
/// 'CupertinoSystemDisplay' are used as proxies for the Apple system fonts.
575+
/// They currently redirect to the equivilant of SF Pro Text and SF Pro Display
576+
/// respectively. 'CupertinoSystemText' is designed for fonts below 20 point
577+
/// size, and 'CupertinoSystemDisplay' is recommended for sizes 20 and above.
578+
/// When used on non-Apple platforms, these strings will return the regular
579+
/// fallback font family instead.
564580
final String? fontFamily;
565581

566582
/// The ordered list of font families to fall back on when a glyph cannot be

packages/flutter/test/cupertino/date_picker_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void main() {
633633
// Distance between the first and the last column should be the same.
634634
expect(
635635
tester.getCenter(find.text('10')).dx - tester.getCenter(find.text('AM')).dx,
636-
distance,
636+
moreOrLessEquals(distance),
637637
);
638638
});
639639

packages/flutter/test/cupertino/nav_bar_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ class _ExpectStyles extends StatelessWidget {
15811581
Widget build(BuildContext context) {
15821582
final TextStyle style = DefaultTextStyle.of(context).style;
15831583
expect(style.color, isSameColorAs(color));
1584-
expect(style.fontFamily, '.SF Pro Text');
1584+
expect(style.fontFamily, 'CupertinoSystemText');
15851585
expect(style.fontSize, 17.0);
15861586
expect(style.letterSpacing, -0.41);
15871587
count += index;

0 commit comments

Comments
 (0)