Unverified Commit 8f57f87a authored by Pierre-Louis's avatar Pierre-Louis Committed by GitHub

Improve `useMaterial3` documentation (#104815)

* Improve `useMaterial3` documentation

* reverse styles and components

* tweak language around support

* Update theme_data.dart

* remove trailing space

* Update packages/flutter/lib/src/material/theme_data.dart
Co-authored-by: 's avatarDarren Austin <darren@darrenaustin.org>

* add missing spec links

* remove spec links from useMaterial3

* move defaults section up, rejig things

* spaces no longer trailing

* spaces no longer trailing (2)
Co-authored-by: 's avatarDarren Austin <darren@darrenaustin.org>
parent 1e53ad4e
...@@ -152,6 +152,7 @@ class _PreferredAppBarSize extends Size { ...@@ -152,6 +152,7 @@ class _PreferredAppBarSize extends Size {
/// * [FlexibleSpaceBar], which is used with [flexibleSpace] when the app bar /// * [FlexibleSpaceBar], which is used with [flexibleSpace] when the app bar
/// can expand and collapse. /// can expand and collapse.
/// * <https://material.io/design/components/app-bars-top.html> /// * <https://material.io/design/components/app-bars-top.html>
/// * <https://m3.material.io/components/top-app-bar>
/// * Cookbook: [Place a floating app bar above a list](https://flutter.dev/docs/cookbook/lists/floating-app-bar) /// * Cookbook: [Place a floating app bar above a list](https://flutter.dev/docs/cookbook/lists/floating-app-bar)
class AppBar extends StatefulWidget implements PreferredSizeWidget { class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// Creates a Material Design app bar. /// Creates a Material Design app bar.
......
...@@ -123,6 +123,7 @@ enum BottomNavigationBarLandscapeLayout { ...@@ -123,6 +123,7 @@ enum BottomNavigationBarLandscapeLayout {
/// * [BottomNavigationBarItem] /// * [BottomNavigationBarItem]
/// * [Scaffold] /// * [Scaffold]
/// * <https://material.io/design/components/bottom-navigation.html> /// * <https://material.io/design/components/bottom-navigation.html>
/// * [NavigationBar], this widget's replacement in Material Design 3.
class BottomNavigationBar extends StatefulWidget { class BottomNavigationBar extends StatefulWidget {
/// Creates a bottom navigation bar which is typically used as a /// Creates a bottom navigation bar which is typically used as a
/// [Scaffold]'s [Scaffold.bottomNavigationBar] argument. /// [Scaffold]'s [Scaffold.bottomNavigationBar] argument.
......
...@@ -53,6 +53,7 @@ import 'theme.dart'; ...@@ -53,6 +53,7 @@ import 'theme.dart';
/// * [ListTile], to display icons and text in a card. /// * [ListTile], to display icons and text in a card.
/// * [showDialog], to display a modal card. /// * [showDialog], to display a modal card.
/// * <https://material.io/design/components/cards.html> /// * <https://material.io/design/components/cards.html>
/// * <https://m3.material.io/components/cards>
class Card extends StatelessWidget { class Card extends StatelessWidget {
/// Creates a Material Design card. /// Creates a Material Design card.
/// ///
......
...@@ -169,10 +169,10 @@ class Dialog extends StatelessWidget { ...@@ -169,10 +169,10 @@ class Dialog extends StatelessWidget {
/// A Material Design alert dialog. /// A Material Design alert dialog.
/// ///
/// An alert dialog informs the user about situations that require /// An alert dialog (also known as a basic dialog) informs the user about
/// acknowledgement. An alert dialog has an optional title and an optional list /// situations that require acknowledgement. An alert dialog has an optional
/// of actions. The title is displayed above the content and the actions are /// title and an optional list of actions. The title is displayed above the
/// displayed below the content. /// content and the actions are displayed below the content.
/// ///
/// {@youtube 560 315 https://www.youtube.com/watch?v=75CsnyRXf5I} /// {@youtube 560 315 https://www.youtube.com/watch?v=75CsnyRXf5I}
/// ///
...@@ -251,6 +251,7 @@ class Dialog extends StatelessWidget { ...@@ -251,6 +251,7 @@ class Dialog extends StatelessWidget {
/// * [CupertinoAlertDialog], an iOS-styled alert dialog. /// * [CupertinoAlertDialog], an iOS-styled alert dialog.
/// * [showDialog], which actually displays the dialog and returns its result. /// * [showDialog], which actually displays the dialog and returns its result.
/// * <https://material.io/design/components/dialogs.html#alert-dialog> /// * <https://material.io/design/components/dialogs.html#alert-dialog>
/// * <https://m3.material.io/components/dialogs>
class AlertDialog extends StatelessWidget { class AlertDialog extends StatelessWidget {
/// Creates an alert dialog. /// Creates an alert dialog.
/// ///
...@@ -1060,6 +1061,7 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> a ...@@ -1060,6 +1061,7 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> a
/// * [DisplayFeatureSubScreen], which documents the specifics of how /// * [DisplayFeatureSubScreen], which documents the specifics of how
/// [DisplayFeature]s can split the screen into sub-screens. /// [DisplayFeature]s can split the screen into sub-screens.
/// * <https://material.io/design/components/dialogs.html> /// * <https://material.io/design/components/dialogs.html>
/// * <https://m3.material.io/components/dialogs>
Future<T?> showDialog<T>({ Future<T?> showDialog<T>({
required BuildContext context, required BuildContext context,
required WidgetBuilder builder, required WidgetBuilder builder,
......
...@@ -57,6 +57,7 @@ import 'theme_data.dart'; ...@@ -57,6 +57,7 @@ import 'theme_data.dart';
/// * [TextButton], a simple flat button without a shadow. /// * [TextButton], a simple flat button without a shadow.
/// * [OutlinedButton], a [TextButton] with a border outline. /// * [OutlinedButton], a [TextButton] with a border outline.
/// * <https://material.io/design/components/buttons.html> /// * <https://material.io/design/components/buttons.html>
/// * <https://m3.material.io/components/buttons>
class ElevatedButton extends ButtonStyleButton { class ElevatedButton extends ButtonStyleButton {
/// Create an ElevatedButton. /// Create an ElevatedButton.
/// ///
......
...@@ -89,6 +89,7 @@ enum _FloatingActionButtonType { ...@@ -89,6 +89,7 @@ enum _FloatingActionButtonType {
/// * [Scaffold], in which floating action buttons typically live. /// * [Scaffold], in which floating action buttons typically live.
/// * [ElevatedButton], a filled button whose material elevates when pressed. /// * [ElevatedButton], a filled button whose material elevates when pressed.
/// * <https://material.io/design/components/buttons-floating-action-button.html> /// * <https://material.io/design/components/buttons-floating-action-button.html>
/// * <https://m3.material.io/components/floating-action-button>
class FloatingActionButton extends StatelessWidget { class FloatingActionButton extends StatelessWidget {
/// Creates a circular floating action button. /// Creates a circular floating action button.
/// ///
...@@ -235,6 +236,9 @@ class FloatingActionButton extends StatelessWidget { ...@@ -235,6 +236,9 @@ class FloatingActionButton extends StatelessWidget {
/// The [label], [autofocus], and [clipBehavior] arguments must not be null. /// The [label], [autofocus], and [clipBehavior] arguments must not be null.
/// Additionally, [elevation], [highlightElevation], and [disabledElevation] /// Additionally, [elevation], [highlightElevation], and [disabledElevation]
/// (if specified) must be non-negative. /// (if specified) must be non-negative.
///
/// See also:
/// * <https://m3.material.io/components/extended-fab>
const FloatingActionButton.extended({ const FloatingActionButton.extended({
super.key, super.key,
this.tooltip, this.tooltip,
......
...@@ -291,6 +291,7 @@ enum ListTileControlAffinity { ...@@ -291,6 +291,7 @@ enum ListTileControlAffinity {
/// * <https://material.io/design/components/lists.html> /// * <https://material.io/design/components/lists.html>
/// * Cookbook: [Use lists](https://flutter.dev/docs/cookbook/lists/basic-list) /// * Cookbook: [Use lists](https://flutter.dev/docs/cookbook/lists/basic-list)
/// * Cookbook: [Implement swipe to dismiss](https://flutter.dev/docs/cookbook/gestures/dismissible) /// * Cookbook: [Implement swipe to dismiss](https://flutter.dev/docs/cookbook/gestures/dismissible)
// TODO(plg): Add link to m3 spec below m2 spec link when available
class ListTile extends StatelessWidget { class ListTile extends StatelessWidget {
/// Creates a list tile. /// Creates a list tile.
/// ///
......
...@@ -164,6 +164,7 @@ abstract class MaterialInkController { ...@@ -164,6 +164,7 @@ abstract class MaterialInkController {
/// * [MergeableMaterial], a piece of material that can split and re-merge. /// * [MergeableMaterial], a piece of material that can split and re-merge.
/// * [Card], a wrapper for a [Material] of [type] [MaterialType.card]. /// * [Card], a wrapper for a [Material] of [type] [MaterialType.card].
/// * <https://material.io/design/> /// * <https://material.io/design/>
/// * <https://m3.material.io/styles/color/the-color-system/color-roles>
class Material extends StatefulWidget { class Material extends StatefulWidget {
/// Creates a piece of material. /// Creates a piece of material.
/// ///
......
...@@ -48,6 +48,7 @@ import 'tooltip.dart'; ...@@ -48,6 +48,7 @@ import 'tooltip.dart';
/// * [NavigationDestination] /// * [NavigationDestination]
/// * [BottomNavigationBar] /// * [BottomNavigationBar]
/// * <https://api.flutter.dev/flutter/material/NavigationDestination-class.html> /// * <https://api.flutter.dev/flutter/material/NavigationDestination-class.html>
/// * <https://m3.material.io/components/navigation-bar>
class NavigationBar extends StatelessWidget { class NavigationBar extends StatelessWidget {
/// Creates a Material 3 Navigation Bar component. /// Creates a Material 3 Navigation Bar component.
/// ///
......
...@@ -61,7 +61,8 @@ import 'theme.dart'; ...@@ -61,7 +61,8 @@ import 'theme.dart';
/// destinations in the navigation rail. /// destinations in the navigation rail.
/// * [BottomNavigationBar], which is a similar navigation widget that's laid /// * [BottomNavigationBar], which is a similar navigation widget that's laid
/// out horizontally. /// out horizontally.
/// * https://material.io/components/navigation-rail/ /// * <https://material.io/components/navigation-rail/>
/// * <https://m3.material.io/components/navigation-rail>
class NavigationRail extends StatefulWidget { class NavigationRail extends StatefulWidget {
/// Creates a Material Design navigation rail. /// Creates a Material Design navigation rail.
/// ///
......
...@@ -62,6 +62,7 @@ import 'theme_data.dart'; ...@@ -62,6 +62,7 @@ import 'theme_data.dart';
/// * [ElevatedButton], a filled Material Design button with a shadow. /// * [ElevatedButton], a filled Material Design button with a shadow.
/// * [TextButton], a Material Design button without a shadow. /// * [TextButton], a Material Design button without a shadow.
/// * <https://material.io/design/components/buttons.html> /// * <https://material.io/design/components/buttons.html>
/// * <https://m3.material.io/components/buttons>
class OutlinedButton extends ButtonStyleButton { class OutlinedButton extends ButtonStyleButton {
/// Create an OutlinedButton. /// Create an OutlinedButton.
/// ///
......
...@@ -62,6 +62,7 @@ import 'theme_data.dart'; ...@@ -62,6 +62,7 @@ import 'theme_data.dart';
/// * [OutlinedButton], a [TextButton] with a border outline. /// * [OutlinedButton], a [TextButton] with a border outline.
/// * [ElevatedButton], a filled button whose material elevates when pressed. /// * [ElevatedButton], a filled button whose material elevates when pressed.
/// * <https://material.io/design/components/buttons.html> /// * <https://material.io/design/components/buttons.html>
/// * <https://m3.material.io/components/buttons>
class TextButton extends ButtonStyleButton { class TextButton extends ButtonStyleButton {
/// Create a TextButton. /// Create a TextButton.
/// ///
......
...@@ -1133,53 +1133,63 @@ class ThemeData with Diagnosticable { ...@@ -1133,53 +1133,63 @@ class ThemeData with Diagnosticable {
/// A temporary flag used to opt-in to Material 3 features. /// A temporary flag used to opt-in to Material 3 features.
/// ///
/// If true, then components that have been migrated to Material 3 will /// If true, then widgets that have been migrated to Material 3 will
/// use new colors, typography and other features of Material 3. /// use new colors, typography and other features of Material 3.
/// If false, they will use the Material 2 look and feel. /// If false, they will use the Material 2 look and feel.
/// ///
/// During the migration to Material 3, turning this on may yield
/// inconsistent look and feel in your app as some widgets are migrated
/// while others have yet to be.
///
/// Defaults to false. When the Material 3 specification is complete
/// and all widgets are migrated on stable, we will change this flag to be
/// true by default. After that change has landed on stable, we will deprecate
/// this flag and remove all uses of it. At that point, the `material` library
/// will aim to only support Material 3.
///
/// ## Defaults
/// If a [ThemeData] is constructed with [useMaterial3] set to true, then /// If a [ThemeData] is constructed with [useMaterial3] set to true, then
/// some properties will get special defaults. However, just copying a [ThemeData] /// some properties will get updated defaults. Please note that
/// with [useMaterial3] set to true will not change any of these properties in the /// [ThemeData.copyWith] with [useMaterial3] set to true will
/// resulting [ThemeData]. These properties are: /// not change any of these properties in the resulting [ThemeData].
///
/// <style>table,td,th { border-collapse: collapse; padding: 0.45em; } td { border: 1px solid }</style> /// <style>table,td,th { border-collapse: collapse; padding: 0.45em; } td { border: 1px solid }</style>
/// ///
/// | Property | Material 3 default | Fallback default | /// | Property | Material 3 default | Material 2 default |
/// | :-------------- | :--------------------------- | :------------------------ | /// | :-------------- | :--------------------------- | :------------------------ |
/// | [typography] | [Typography.material2021] | [Typography.material2014] | /// | [typography] | [Typography.material2021] | [Typography.material2014] |
/// | [splashFactory] | [InkSparkle]* or [InkRipple] | [InkSplash] | /// | [splashFactory] | [InkSparkle]* or [InkRipple] | [InkSplash] |
/// ///
/// \* if and only if the target platform is Android and the app is not /// \* if the target platform is Android and the app is not
/// running on the web, otherwise it will fallback to [InkRipple]. /// running on the web, otherwise it will fallback to [InkRipple].
/// ///
/// During the migration to Material 3, turning this on may yield /// ## Affected widgets
/// inconsistent look and feel in your app. Some components will be migrated ///
/// before others and typography changes will be coming in stages. /// This flag affects styles and components.
/// ///
/// [useMaterial3] defaults to false. After all the migrated components /// ### Styles
/// have landed on stable, we will change this to be true by default. After /// * Color: [ColorScheme], [Material]
/// that change has landed on stable, we will deprecate this flag and remove /// * Shape: (see components below)
/// all uses of it. Everything will use the Material 3 look and feel at /// * Typography: `typography` (see table above)
/// that point. ///
/// /// ### Components
/// Components that have been migrated to Material 3 are: /// * Common buttons: [TextButton], [OutlinedButton], [ElevatedButton]
/// /// * FAB: [FloatingActionButton]
/// * [AlertDialog] /// * Extended FAB: [FloatingActionButton.extended]
/// * [AppBar] /// * Cards: [Card]
/// * [Card] /// * Dialogs: [Dialog], [AlertDialog]
/// * [Dialog] /// * Lists: [ListTile]
/// * [ElevatedButton] /// * Navigation bar: [NavigationBar] (new, replacing [BottomNavigationBar])
/// * [FloatingActionButton] /// * [Navigation rail](https://m3.material.io/components/navigation-rail): [NavigationRail]
/// * [Material] /// * Top app bar: [AppBar]
/// * [NavigationBar] (new, replacing [BottomNavigationBar]) ///
/// * [NavigationRail] /// In addition, this flag enables features introduced in Android 12.
/// * [OutlinedButton] /// * Stretch overscroll: [MaterialScrollBehavior]
/// * [StretchingOverscrollIndicator], replacing the /// * Ripple: `splashFactory` (see table above)
/// [GlowingOverscrollIndicator]
/// * [TextButton]
/// ///
/// See also: /// See also:
/// ///
/// * [Material Design 3](https://m3.material.io/). /// * [Material 3 specification](https://m3.material.io/).
final bool useMaterial3; final bool useMaterial3;
/// The density value for specifying the compactness of various UI components. /// The density value for specifying the compactness of various UI components.
......
...@@ -77,6 +77,7 @@ enum ScriptCategory { ...@@ -77,6 +77,7 @@ enum ScriptCategory {
/// See also: /// See also:
/// ///
/// * <https://material.io/design/typography/> /// * <https://material.io/design/typography/>
/// * <https://m3.material.io/styles/typography>
@immutable @immutable
class Typography with Diagnosticable { class Typography with Diagnosticable {
/// Creates a typography instance. /// Creates a typography instance.
...@@ -157,6 +158,9 @@ class Typography with Diagnosticable { ...@@ -157,6 +158,9 @@ class Typography with Diagnosticable {
/// ///
/// The default values for [englishLike], [dense], and [tall] are /// The default values for [englishLike], [dense], and [tall] are
/// [englishLike2021], [dense2021], and [tall2021]. /// [englishLike2021], [dense2021], and [tall2021].
///
/// See also:
/// * <https://m3.material.io/styles/typography>
factory Typography.material2021({ factory Typography.material2021({
TargetPlatform? platform = TargetPlatform.android, TargetPlatform? platform = TargetPlatform.android,
TextTheme? black, TextTheme? black,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment