From 9b17b79e7602c75b05133d7b2e3d40c808ff6e8a Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Fri, 21 Jan 2022 22:49:01 +0200 Subject: [PATCH] Explain how MaterialApp renders text style in absence of Material Widget (#96530) --- packages/flutter/lib/src/material/app.dart | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart index acc572928c..91f819d132 100644 --- a/packages/flutter/lib/src/material/app.dart +++ b/packages/flutter/lib/src/material/app.dart @@ -57,6 +57,11 @@ enum ThemeMode { /// adding material-design specific functionality, such as [AnimatedTheme] and /// [GridPaper]. /// +/// [MaterialApp] configures its [WidgetsApp.textStyle] with an ugly red/yellow +/// text style that's intended to warn the developer that their app hasn't defined +/// a default text style. Typically the app's [Scaffold] builds a [Material] widget +/// whose default [Material.textStyle] defines the text style for the entire scaffold. +/// /// The [MaterialApp] configures the top-level [Navigator] to search for routes /// in the following order: /// @@ -145,6 +150,28 @@ enum ThemeMode { /// ``` /// {@end-tool} /// +/// ## Troubleshooting +/// +/// ### Why is my app's text red with yellow underlines? +/// +/// [Text] widgets that lack a [Material] ancestor will be rendered with an ugly +/// red/yellow text style. +/// +/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/material_app_unspecified_textstyle.png) +/// +/// The typical fix is to give the widget a [Scaffold] ancestor. The [Scaffold] creates +/// a [Material] widget that defines its default text style. +/// +/// ```dart +/// MaterialApp( +/// title: 'Material App', +/// home: Scaffold( +/// body: Center( +/// child: Text('Hello World'), +/// ), +/// ), +/// ) +/// ``` /// See also: /// /// * [Scaffold], which provides standard app elements like an [AppBar] and a [Drawer].