From 5a6978109df81b5e4fc8013a7fc1df3e1cb0d9a9 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Mon, 12 Apr 2021 18:05:03 +0000 Subject: [PATCH] Fix analysis errors in text.dart (flutter/engine#25526) --- engine/src/flutter/lib/ui/text.dart | 852 ++++++++++++++-------------- 1 file changed, 441 insertions(+), 411 deletions(-) diff --git a/engine/src/flutter/lib/ui/text.dart b/engine/src/flutter/lib/ui/text.dart index 9093df50bb..6d74a9c418 100644 --- a/engine/src/flutter/lib/ui/text.dart +++ b/engine/src/flutter/lib/ui/text.dart @@ -109,73 +109,75 @@ class FontWeight { /// such as to examine your fonts to /// determine what features are available. /// -/// {@tool sample --template=freeform} +/// {@tool sample --template=stateless_widget_material} /// /// This example shows usage of several OpenType font features, /// including Small Caps (selected manually using the "smcp" code), /// old-style figures, fractional ligatures, and stylistic sets. /// +/// ```dart dartImports +/// import 'dart:ui'; +/// ``` +/// +/// ```dart preamble +/// final TextStyle titleStyle = TextStyle( +/// fontSize: 18, +/// fontFeatures: const [FontFeature.enable('smcp')], +/// color: Colors.blueGrey[600], +/// ); +/// ``` +/// /// ```dart -/// class TypePage extends StatelessWidget { +/// Widget build(BuildContext context) { /// // The Cardo, Milonga and Raleway Dots fonts can be downloaded from /// // Google Fonts (https://www.google.com/fonts). -/// -/// final titleStyle = TextStyle( -/// fontSize: 18, -/// fontFeatures: [FontFeature.enable('smcp')], -/// color: Colors.blueGrey[600], -/// ); -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// Spacer(flex: 5), -/// Text('regular numbers have their place:', style: titleStyle), -/// Text('The 1972 cup final was a 1-1 draw.', -/// style: TextStyle( +/// return Scaffold( +/// body: Center( +/// child: Column( +/// mainAxisAlignment: MainAxisAlignment.center, +/// children: [ +/// const Spacer(flex: 5), +/// Text('regular numbers have their place:', style: titleStyle), +/// const Text('The 1972 cup final was a 1-1 draw.', +/// style: TextStyle( +/// fontFamily: 'Cardo', +/// fontSize: 24, +/// )), +/// const Spacer(), +/// Text('but old-style figures blend well with lower case:', +/// style: titleStyle), +/// const Text('The 1972 cup final was a 1-1 draw.', +/// style: TextStyle( /// fontFamily: 'Cardo', /// fontSize: 24, -/// )), -/// Spacer(), -/// Text('but old-style figures blend well with lower case:', -/// style: titleStyle), -/// Text('The 1972 cup final was a 1-1 draw.', -/// style: TextStyle( -/// fontFamily: 'Cardo', -/// fontSize: 24, -/// fontFeatures: [FontFeature.oldstyleFigures()])), -/// Spacer(), -/// Divider(), -/// Spacer(), -/// Text('fractions look better with a custom ligature:', -/// style: titleStyle), -/// Text('Add 1/2 tsp of flour and stir.', -/// style: TextStyle( -/// fontFamily: 'Milonga', -/// fontSize: 24, -/// fontFeatures: [FontFeature.alternativeFractions()])), -/// Spacer(), -/// Divider(), -/// Spacer(), -/// Text('multiple stylistic sets in one font:', style: titleStyle), -/// Text('Raleway Dots', -/// style: TextStyle(fontFamily: 'Raleway Dots', fontSize: 48)), -/// Text('Raleway Dots', -/// style: TextStyle( -/// fontFeatures: [FontFeature.stylisticSet(1)], -/// fontFamily: 'Raleway Dots', -/// fontSize: 48, -/// )), -/// Spacer(flex: 5), -/// ], -/// ), +/// fontFeatures: const [FontFeature.oldstyleFigures()])), +/// const Spacer(), +/// const Divider(), +/// const Spacer(), +/// Text('fractions look better with a custom ligature:', +/// style: titleStyle), +/// const Text('Add 1/2 tsp of flour and stir.', +/// style: TextStyle( +/// fontFamily: 'Milonga', +/// fontSize: 24, +/// fontFeatures: [FontFeature.alternativeFractions()])), +/// const Spacer(), +/// const Divider(), +/// const Spacer(), +/// Text('multiple stylistic sets in one font:', style: titleStyle), +/// const Text('Raleway Dots', +/// style: TextStyle(fontFamily: 'Raleway Dots', fontSize: 48)), +/// Text('Raleway Dots', +/// style: TextStyle( +/// fontFeatures: [FontFeature.stylisticSet(1)], +/// fontFamily: 'Raleway Dots', +/// fontSize: 48, +/// )), +/// const Spacer(flex: 5), +/// ], /// ), -/// ); -/// } +/// ), +/// ); /// } /// ``` /// {@end-tool} @@ -233,7 +235,7 @@ class FontFeature { /// /// This feature selects the given glyph variant for glyphs in the span. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Raleway font supports several alternate glyphs. The code /// below shows how specific glyphs can be selected. With `aalt` set @@ -245,21 +247,22 @@ class FontFeature { /// (using [Text.rich]), the desired rendering for each glyph can be /// achieved. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Raleway font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'The infamous Tuna Torture.', - /// style: TextStyle( - /// fontFamily: 'Raleway', - /// fontFeatures: [ - /// FontFeature.alternative(1), // or 2, or 3, or... - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'The infamous Tuna Torture.', + /// style: TextStyle( + /// fontFamily: 'Raleway', + /// fontFeatures: [ + /// FontFeature.alternative(1), // or 2, or 3, or... + /// ], + /// ), + /// ); /// } /// ``` /// @@ -282,27 +285,28 @@ class FontFeature { /// /// This feature overrides all other features. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Ubuntu Mono font supports the `afrc` feature. It causes digits /// before slashes to become superscripted and digits after slashes to become /// subscripted. This contrasts to the effect seen with [FontFeature.fractions]. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Ubuntu Mono font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Fractions: 1/2 2/3 3/4 4/5', - /// style: TextStyle( - /// fontFamily: 'Ubuntu Mono', - /// fontFeatures: [ - /// FontFeature.alternativeFractions(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Fractions: 1/2 2/3 3/4 4/5', + /// style: TextStyle( + /// fontFamily: 'Ubuntu Mono', + /// fontFeatures: [ + /// FontFeature.alternativeFractions(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -321,7 +325,7 @@ class FontFeature { /// With this feature enabled, specific glyphs may be replaced by /// alternatives based on nearby text. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Barriecito font supports the `calt` feature. It causes some /// letters in close proximity to other instances of themselves to @@ -329,20 +333,22 @@ class FontFeature { /// in the glyphs, rather than having each letter always use a /// particular glyph. /// - /// class Demo extends StatelessWidget { + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// + /// ```dart + /// Widget build(BuildContext context) { /// // The Barriecito font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Ooohh, we weren\'t going to tell him that.', - /// style: TextStyle( - /// fontFamily: 'Barriecito', - /// fontFeatures: [ - /// FontFeature.contextualAlternates(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Ooohh, we weren\'t going to tell him that.', + /// style: TextStyle( + /// fontFamily: 'Barriecito', + /// fontFeatures: [ + /// FontFeature.contextualAlternates(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -368,7 +374,7 @@ class FontFeature { /// be shifted slightly, or otherwise adjusted, so as to form a more /// aethestically pleasing combination with capital letters. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `case` feature. It causes /// parentheses, brackets, braces, guillemets, slashes, bullets, and @@ -381,21 +387,22 @@ class FontFeature { /// The difference is very subtle. It may be most obvious when /// examining the square brackets compared to the capital A. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// '(A) [A] {A} «A» A/B A•B', - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.caseSensitiveForms(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// '(A) [A] {A} «A» A/B A•B', + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.caseSensitiveForms(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -418,7 +425,7 @@ class FontFeature { /// sets, controlled by the [FontFeature.stylisticSet] feature /// (`ssXX`). /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Source Code Pro font supports the `cvXX` feature for several /// characters. In the example below, variants 1 (`cv01`), 2 @@ -434,23 +441,24 @@ class FontFeature { /// the set which affects the "g" character also affects theta and /// delta. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Source Code Pro font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'aáâ β gǵĝ θб Iiíî Ll', - /// style: TextStyle( - /// fontFamily: 'Source Code Pro', - /// fontFeatures: [ - /// FontFeature.characterVariant(1), - /// FontFeature.characterVariant(2), - /// FontFeature.characterVariant(4), - /// ], - /// ), - /// ); - /// } + /// return Text( + /// 'aáâ β gǵĝ θб Iiíî Ll', + /// style: TextStyle( + /// fontFamily: 'Source Code Pro', + /// fontFeatures: [ + /// FontFeature.characterVariant(1), + /// FontFeature.characterVariant(2), + /// FontFeature.characterVariant(4), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -475,26 +483,27 @@ class FontFeature { /// system as part of the implementation of `frac` for the denominator /// part of fractions (see [FontFeature.fractions]). /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `dnom` feature. It causes /// the digits to be rendered smaller and near the bottom of the EM box. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Fractions: 1/2 2/3 3/4 4/5', - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.denominator(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Fractions: 1/2 2/3 3/4 4/5', + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.denominator(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -517,28 +526,29 @@ class FontFeature { /// This feature may imply the [FontFeature.numerator] and /// [FontFeature.denominator] features. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Ubuntu Mono font supports the `frac` feature. It causes /// digits around slashes to be turned into dedicated fraction /// glpyhs. This contrasts to the effect seen with /// [FontFeature.alternativeFractions]. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Ubuntu Mono font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Fractions: 1/2 2/3 3/4 4/5', - /// style: TextStyle( - /// fontFamily: 'Ubuntu Mono', - /// fontFeatures: [ - /// FontFeature.fractions(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Fractions: 1/2 2/3 3/4 4/5', + /// style: TextStyle( + /// fontFamily: 'Ubuntu Mono', + /// fontFeatures: [ + /// FontFeature.fractions(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -564,28 +574,29 @@ class FontFeature { /// /// This feature may override other glyph-substitution features. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Cardo font supports the `hist` feature specifically for the /// letter "s": it changes occurrences of that letter for the glyph /// used by U+017F LATIN SMALL LETTER LONG S. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Cardo font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'VIBRANT fish assisted his business.', - /// style: TextStyle( - /// fontFamily: 'Sorts Mill Goudy', - /// fontFeatures: [ - /// FontFeature.historicalForms(), // Enables "hist". - /// // Use FontFeature.historicalLigatures() to enable "hlig" as well. - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'VIBRANT fish assisted his business.', + /// style: TextStyle( + /// fontFamily: 'Sorts Mill Goudy', + /// fontFeatures: [ + /// FontFeature.historicalForms(), // Enables "hist". + /// // Use FontFeature.historicalLigatures() to enable "hlig" as well. + /// ], + /// ), + /// ); /// } /// ``` /// @@ -621,7 +632,7 @@ class FontFeature { /// /// This feature may override other glyph-substitution features. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Cardo font supports the `hlig` feature. It has legacy /// ligatures for "VI" and "NT", and various ligatures involving the @@ -635,22 +646,23 @@ class FontFeature { /// Observe in particular the position of the dot of the "i" in /// "business" in the various combinations of these features. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Cardo font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'VIBRANT fish assisted his business.', - /// style: TextStyle( - /// fontFamily: 'Sorts Mill Goudy', - /// fontFeatures: [ - /// FontFeature.historicalForms(), // Enables "hist". - /// FontFeature.historicalLigatures() // Enables "hlig". - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'VIBRANT fish assisted his business.', + /// style: TextStyle( + /// fontFamily: 'Sorts Mill Goudy', + /// fontFeatures: [ + /// FontFeature.historicalForms(), // Enables "hist". + /// FontFeature.historicalLigatures() // Enables "hlig". + /// ], + /// ), + /// ); /// } /// ``` /// @@ -675,26 +687,27 @@ class FontFeature { /// /// This feature may conflict with [FontFeature.oldstyleFigures]. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Sorts Mill Goudy font supports the `lnum` feature. It causes /// digits to fit more seamlessly with capital letters. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Sorts Mill Goudy font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'CALL 311-555-2368 NOW!', - /// style: TextStyle( - /// fontFamily: 'Sorts Mill Goudy', - /// fontFeatures: [ - /// FontFeature.liningFigures(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'CALL 311-555-2368 NOW!', + /// style: TextStyle( + /// fontFamily: 'Sorts Mill Goudy', + /// fontFeatures: [ + /// FontFeature.liningFigures(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -732,26 +745,27 @@ class FontFeature { /// locale-awareness. (So does not specifying the locale in the /// first place, of course.) /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Noto Sans CJK font supports the `locl` feature for CJK characters. /// In this example, the `localeAware` feature is not explicitly used, as it is /// enabled by default. This example instead shows how to set the locale, /// thus demonstrating how Noto Sans adapts the glyph shapes to the locale. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Noto family of fonts can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// '次 化 刃 直 入 令', - /// locale: const Locale('zh', 'CN'), // or Locale('ja'), Locale('ko'), Locale('zh', 'TW'), etc - /// style: TextStyle( - /// fontFamily: 'Noto Sans', - /// ), - /// ); - /// } + /// return const Text( + /// '次 化 刃 直 入 令', + /// locale: const Locale('zh', 'CN'), // or Locale('ja'), Locale('ko'), Locale('zh', 'TW'), etc + /// style: TextStyle( + /// fontFamily: 'Noto Sans', + /// ), + /// ); /// } /// ``` /// @@ -775,7 +789,7 @@ class FontFeature { /// selects the set to use (a positive integer, or 0 to disable the /// feature). The default set if none is specified is 1. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Gothic A1 font supports several notational variant sets via /// the `nalt` feature. @@ -788,21 +802,22 @@ class FontFeature { /// /// The code below shows how to select set 3. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Gothic A1 font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'abc 123', - /// style: TextStyle( - /// fontFamily: 'Gothic A1', - /// fontFeatures: [ - /// FontFeature.notationalForms(3), // circled letters and digits - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'abc 123', + /// style: TextStyle( + /// fontFamily: 'Gothic A1', + /// fontFeatures: [ + /// FontFeature.notationalForms(3), // circled letters and digits + /// ], + /// ), + /// ); /// } /// ``` /// @@ -821,26 +836,27 @@ class FontFeature { /// system as part of the implementation of `frac` for the numerator /// part of fractions (see [FontFeature.fractions]). /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `numr` feature. It causes /// the digits to be rendered smaller and near the top of the EM box. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Fractions: 1/2 2/3 3/4 4/5', - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.numerators(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Fractions: 1/2 2/3 3/4 4/5', + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.numerators(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -865,26 +881,27 @@ class FontFeature { /// This overrides [FontFeature.slashedZero] and may conflict with /// [FontFeature.liningFigures]. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `onum` feature. It causes /// digits to extend below the baseline. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Call 311-555-2368 now!', - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.oldstyleFigures(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Call 311-555-2368 now!', + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.oldstyleFigures(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -906,26 +923,27 @@ class FontFeature { /// /// This may override other features that substitute glyphs. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `ordn` feature. It causes /// alphabetic glyphs to become smaller and superscripted. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// '1st, 2nd, 3rd, 4th...', - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.ordinalForms(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// '1st, 2nd, 3rd, 4th...', + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.ordinalForms(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -947,7 +965,7 @@ class FontFeature { /// /// The default behavior varies from font to font. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Kufam font supports the `pnum` feature. It causes the digits /// to become proportionally-sized, rather than all being the same @@ -956,21 +974,22 @@ class FontFeature { /// sans-serif font, but with the proportionally figures enabled, /// the digit becomes much narrower. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Kufam font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Call 311-555-2368 now!', - /// style: TextStyle( - /// fontFamily: 'Kufam', - /// fontFeatures: [ - /// FontFeature.proportionalFigures(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Call 311-555-2368 now!', + /// style: TextStyle( + /// fontFamily: 'Kufam', + /// fontFeatures: [ + /// FontFeature.proportionalFigures(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -1009,7 +1028,7 @@ class FontFeature { /// /// This may override other features that substitute glyphs. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Source Code Pro font supports the `salt` feature. It causes /// some glyphs to be rendered differently, for example the "a" and @@ -1019,20 +1038,22 @@ class FontFeature { /// angled), and the "0" rendering changes from a center dot to a /// slash. /// - /// class Demo extends StatelessWidget { + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// + /// ```dart + /// Widget build(BuildContext context) { /// // The Source Code Pro font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Agile Game - \$100 initial bet', - /// style: TextStyle( - /// fontFamily: 'Source Code Pro', - /// fontFeatures: [ - /// FontFeature.stylisticAlternates(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// r'Agile Game - $100 initial bet', + /// style: TextStyle( + /// fontFamily: 'Source Code Pro', + /// fontFeatures: [ + /// FontFeature.stylisticAlternates(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -1055,26 +1076,27 @@ class FontFeature { /// /// This may override other features that substitute glyphs. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `sinf` feature. It causes /// digits to be smaller and subscripted. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'C8H10N4O2', - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.scientificInferiors(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'C8H10N4O2', + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.scientificInferiors(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -1096,7 +1118,7 @@ class FontFeature { /// character variants can also be controlled by the /// [FontFeature.characterVariant] feature (`cvXX`). /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Source Code Pro font supports the `ssXX` feature for several /// sets. In the example below, stylistic sets 2 (`ss02`), 3 @@ -1109,30 +1131,31 @@ class FontFeature { /// This font also supports character variants (see /// [FontFeature.characterVariant]). /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Source Code Pro font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'aáâ β gǵĝ θб Iiíî Ll', - /// style: TextStyle( - /// fontFamily: 'Source Code Pro', - /// fontFeatures: [ - /// FontFeature.stylisticSet(2), - /// FontFeature.stylisticSet(3), - /// FontFeature.stylisticSet(4), - /// ], - /// ), - /// ); - /// } + /// return Text( + /// 'aáâ β gǵĝ θб Iiíî Ll', + /// style: TextStyle( + /// fontFamily: 'Source Code Pro', + /// fontFeatures: [ + /// FontFeature.stylisticSet(2), + /// FontFeature.stylisticSet(3), + /// FontFeature.stylisticSet(4), + /// ], + /// ), + /// ); /// } /// ``` /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/font_feature_ssXX_1.png) /// {@end-tool} /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `ssXX` feature for for more /// elaborate stylistic effects. Set 1 turns some Latin characters @@ -1141,22 +1164,23 @@ class FontFeature { /// /// _These_ stylistic sets do _not_ correspond to character variants. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// '-> MCMXCVII <-', // 1997 - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.stylisticSet(1), - /// FontFeature.stylisticSet(2), - /// ], - /// ), - /// ); - /// } + /// return Text( + /// '-> MCMXCVII <-', // 1997 + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.stylisticSet(1), + /// FontFeature.stylisticSet(2), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -1184,26 +1208,27 @@ class FontFeature { /// /// This may override other features that substitute glyphs. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `subs` feature. It causes /// digits to be smaller and subscripted. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Line from x1,y1 to x2,y2', - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.subscript(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Line from x1,y1 to x2,y2', + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.subscripts(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -1232,27 +1257,28 @@ class FontFeature { /// /// This may override other features that substitute glyphs. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Sorts Mill Goudy font supports the `sups` feature. It causes /// digits to be smaller, superscripted, and changes them to lining /// figures (so they are all the same height). /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Sorts Mill Goudy font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'The isotope 238U decays to 206Pb', - /// style: TextStyle( - /// fontFamily: 'Sorts Mill Goudy', - /// fontFeatures: [ - /// FontFeature.superscript(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'The isotope 238U decays to 206Pb', + /// style: TextStyle( + /// fontFamily: 'Sorts Mill Goudy', + /// fontFeatures: [ + /// FontFeature.superscripts(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -1282,25 +1308,27 @@ class FontFeature { /// example, Adobe's Poetica famously has 63 different ampersand /// forms available through this feature! /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The BioRhyme Expanded font supports the `swsh` feature specifically /// for the capital "Q" and "R" glyphs and the ampersand. /// - /// class Demo extends StatelessWidget { + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// + /// ```dart + /// Widget build(BuildContext context) { /// // The BioRhyme Expanded font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Queer & Romantic', - /// style: TextStyle( - /// fontFamily: 'BioRhyme Expanded', - /// fontFeatures: [ - /// FontFeature.swash(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Queer & Romantic', + /// style: TextStyle( + /// fontFamily: 'BioRhyme Expanded', + /// fontFeatures: [ + /// FontFeature.swash(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -1324,7 +1352,7 @@ class FontFeature { /// /// The default behavior varies from font to font. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Piazzolla font supports the `tnum` feature. It causes the /// digits to become uniformally-sized, rather than having variable @@ -1332,21 +1360,22 @@ class FontFeature { /// digit "1"; with tabular figures enabled, the "1" digit is more /// widely spaced. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Piazzolla font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'Call 311-555-2368 now!', - /// style: TextStyle( - /// fontFamily: 'Piazzolla', - /// fontFeatures: [ - /// FontFeature.tabularFigures(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'Call 311-555-2368 now!', + /// style: TextStyle( + /// fontFamily: 'Piazzolla', + /// fontFeatures: [ + /// FontFeature.tabularFigures(), + /// ], + /// ), + /// ); /// } /// ``` /// @@ -1366,27 +1395,28 @@ class FontFeature { /// /// This is overridden by [FontFeature.oldstyleFigures]. /// - /// {@tool sample --template=freeform} + /// {@tool sample --template=stateless_widget} /// /// The Source Code Pro font supports the `zero` feature. It causes the /// zero digit to be drawn with a slash rather than the default rendering, /// which in this case has a dot through the zero rather than a slash. /// + /// ```dart dartImports + /// import 'dart:ui'; + /// ``` + /// /// ```dart - /// class Demo extends StatelessWidget { + /// Widget build(BuildContext context) { /// // The Source Code Pro font can be downloaded from Google Fonts (https://www.google.com/fonts). - /// @override - /// Widget build(BuildContext context) { - /// return Text( - /// 'One million is: 1,000,000.00', - /// style: TextStyle( - /// fontFamily: 'Source Code Pro', - /// fontFeatures: [ - /// FontFeature.slashedZero(), - /// ], - /// ), - /// ); - /// } + /// return const Text( + /// 'One million is: 1,000,000.00', + /// style: TextStyle( + /// fontFamily: 'Source Code Pro', + /// fontFeatures: [ + /// FontFeature.slashedZero(), + /// ], + /// ), + /// ); /// } /// ``` ///