Skip to content

[Material3] Update documentation of AlertDialog's default text styles when Material 3 is used #144489

@Nenuphar12

Description

@Nenuphar12

Steps to reproduce

  1. Create a Flutter app with Material 3 enabled (default).
  2. Add an AlertDialog to the app without specifying titleTextStyle and contentTextStyle.
  3. Observe the style applied to the title text and the content text.
    • The TextStyle applied to the title text is TextTheme.headlineSmall of ThemeData.textTheme
    • The TextStyle applied to the content text is TextTheme.bodyMedium of ThemeData.textTheme
Current Documentation

The current documentation for the properties AlertDialog.titelTextStyle and AlertDialog.contentTextStyle from alert_dialog.dart:

  /// Style for the text in the [title] of this [AlertDialog].
  ///
  /// If null, [DialogTheme.titleTextStyle] is used. If that's null, defaults to
  /// [TextTheme.titleLarge] of [ThemeData.textTheme].
  final TextStyle? titleTextStyle;

  /// Style for the text in the [content] of this [AlertDialog].
  ///
  /// If null, [DialogTheme.contentTextStyle] is used. If that's null, defaults
  /// to [TextTheme.titleMedium] of [ThemeData.textTheme].
  final TextStyle? contentTextStyle;

Expected results

  • The documentation of AlertDialog.titleTextStyle should clearly state that with Material 3 (useMaterial3: true), the default titleTextStyle of AlertDialog fall back to TextTheme.headlineSmall and not to TextTheme.titleLarge.
  • The documentation of AlertDialog.contentTextStyle should clearly state that with Material 3 (useMaterial3: true), the default contentTextStyle of AlertDialog fall back to TextTheme.bodyMedium and not to TextTheme.titleMedium.

Actual results

  • The current documentation incorrectly suggests that AlertDialog.titleTextStyle defaults to TextTheme.titleLarge, causing confusion when styling dialogs in Material 3 apps.
  • The current documentation incorrectly suggests that AlertDialog.contentTextStyle defaults to TextTheme.titleMedium, causing confusion when styling dialogs in Material 3 apps.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Documentation Issue Example',
      theme: ThemeData(
        textTheme: const TextTheme(
          // Text style used for the title of the [AlertDialog] according to
          // [AlertDialog.titleTextStyle] DOCUMENTATION.
          titleLarge: TextStyle(color: Colors.green),
          // Text style ACTUALLY USED for the title of the [AlertDialog] when
          // Material 3 is in use.
          headlineSmall: TextStyle(color: Colors.red),

          // Text style used for the content of the [AlertDialog] according to
          // [AlertDialog.contentTextStyle] DOCUMENTATION.
          titleMedium: TextStyle(color: Colors.green),
          // Text style ACTUALLY USED for the content of the [AlertDialog]
          // when Material 3 is in use.
          bodyMedium: TextStyle(color: Colors.red),
        ),
        useMaterial3: true,
      ),
      home: const AlertDialog(
        title: Text(
          'Title - should be green according to [AlertDialog.titleTextStyle] '
          'documentation',
        ),
        content: Text(
          'Content - should be green according to '
          '[AlertDialog.contentTextStyle] documentation.',
        ),
      ),
    );
  }
}

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.19.2, on Microsoft Windows [version 10.0.22631.3155], locale fr-FR)
    • Flutter version 3.19.2 on channel stable at C:\Users\nenup\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7482962148 (3 days ago), 2024-02-27 16:51:22 -0500
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\nenup\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.8.3)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    • Visual Studio Build Tools 2022 version 17.8.34330.188
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2023.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.87.0)
    • VS Code at C:\Users\nenup\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.82.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [version 10.0.22631.3155]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 122.0.6261.71
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 122.0.2365.52

[√] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions