Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Inside Flutter Text

Inside Flutter Text

In app development using Flutter, Text is heavily used in every app, but the behavior is slightly different between iOS and Android, and it doesn't look exactly the same on both platforms as is. Android tends to take up more widget height than iOS, among other differences. While using the same font on iOS and Android can eliminate design differences when placing Text across platforms, it's not user-friendly if the system font chosen by the OS the user usually sees is different. In this session, we will introduce the components of Text, make the audience aware that the execution results of Text are slightly different for each platform, and aim to be able to create Text that looks the same on iOS and Android.

Kakeru Nakabachi

June 13, 2024
Tweet

More Decks by Kakeru Nakabachi

Other Decks in Programming

Transcript

  1. 3

  2. Agenda 1. Introduction 2. Text and RichText 3. TextStyle and

    StrutStyle 4. Text Typography 5. Issues with Japanese display of Text 6. Conclusion 5
  3. Introduction Understanding Text and using it correctly could have a

    big impact on the apps they are developing. 9
  4. Text Simply set a string in the Text Widget to

    draw text on the screen. 11 https://youtu.be/1z6YP7YmvwA?si=kWbA1nRRXaJVqvto
  5. RichText Use when you want to combine multiple TextStyles. 14

    https://youtu.be/rykDVh-QFfw?si=nlhlDXFlUzsVMx4S
  6. RichText Some Text can be tappable like a link. 15

    https://youtu.be/rykDVh-QFfw?si=nlhlDXFlUzsVMx4S
  7. Text and RichText Text also has a Text.rich constructor. >

    Creates a text widget with a InlineSpan. 17 https://api.flutter.dev/flutter/widgets/Text/Text.rich.html
  8. If TextStyle is nested, the closest TextStyle is used. This

    is because the closest TextStyle to the context given to DefaultTextStyle.of(context) is taken and used in the text widget. TextStyle 23 DefaultTextStyle .of(context) DefaultTextStyle (InheritedWidget) dependOnInheritedWidgetOfExactType
  9. TextStyle Yellow Underline Text A TextStyle called _errorTextStyle is defined

    and is actually displayed. 26 https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/app.dart#L33-L42
  10. TextStyle Yellow Underline Text A TextStyle called _errorTextStyle is defined

    and is actually displayed. 👇Result of debugPrinting DefaultTextStyle.of(context).style 27
  11. TextStyle Yellow Underline Text • Scaffold ◦ Material ▪ TextStyle

    28 https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/material.dart#455
  12. TextStyle TextStyle has an important property called height in addition

    to text decoration. It is used to change the height of lines, which by default are laid out at the height defined by the font. 30 https://api.flutter.dev/flutter/painting/TextStyle-class.html
  13. StrutStyle Set minimum line height. No lines may be shorter

    than the strut. Strut is defined independently from any text content or TextStyles. 32
  14. Text Typography The Typography of Material Design is summarized in

    the following pages. 36 https://m3.material.io/styles/typography/type-scale-tokens
  15. Text Typography 38 Typography.material2014(Material 2) • black • white •

    englishLike • dense • tall TextTheme Typography.material2021(Material 3) • black • white • englishLike • dense • tall useMaterial3(default: true)
  16. Text Typography 39 Material Design Typography and Flutter's Typography implementation

    are linked. https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/typography.dart#L749-L76 5
  17. Issues with Japanese display of Text 1. Japanese height differs

    between iOS and Android. 2. Japanese characters looks closer to the bottom on Android. 41
  18. 1. Japanese height differs between iOS and Android. Issues with

    Japanese display of Text 43 Android iOS English 38.0 px 38.0 px Japanese 46.0 px 48.0 px
  19. Issues with Japanese display of Text 2. Japanese characters looks

    closer to the bottom on Android. Issue in Flutter 44 https://github.com/flutter/flutter/issues/79931
  20. Issues with Japanese display of Text 2. Japanese characters looks

    closer to the bottom on Android. 46 Android iOS
  21. Issues with Japanese display of Text 2. Japanese characters looks

    closer to the bottom on Android. 47 Android iOS
  22. Conclusion Text is RichText. Understanding TextStyle and StrutStyle allows for

    flexible Text display. Yellow Underline Text displayed when TextStyle is not set. Flutter's Japanese support has a few issues. 49
  23. Reference • https://qiita.com/b4tchkn/items/282f5bf759f168c3f4ce • https://speakerdeck.com/b4tchkn/understanding-the-structure-of-text • https://stackoverflow.com/questions/56799068/what-is-the-strutstyle-in-the-flutter-text -widget • https://zenn.dev/tsuruo/articles/576a98ec2f016b#texttheme-1

    • https://zenn.dev/shima999ba/articles/a1241cc8a06930 • https://developer.apple.com/design/human-interface-guidelines/typography • https://m3.material.io/styles/typography/type-scale-token • https://api.flutter.dev/flutter/painting/painting-library.htm • https://youtu.be/DUX1uVCewvk?si=PC2ctCgkZiMm2naV 51