Normalize Card theme (#151914)

This PR is to make preparations to make `CardTheme` conform to Flutter's conventions for component themes:
* Added a `CardThemeData` class which defines overrides for the defaults for `Card` properties.
* Added 2 `CardTheme` constructor parameters: `CardThemeData? data` and `Widget? child`. This is now the preferred way to configure a `CardTheme`:
```dart
CardTheme(
  data: CardThemeData(color: xxx, elevation: xxx, ...),
  child: Card(...)
)
```

These two properties are made nullable to not break existing apps which has customized `ThemeData.cardTheme`.
* Changed the type of theme defaults from `CardTheme` to `CardThemeData`.

TODO: 
* Fix internal failures that may have breakages.
* Change the type of `ThemeData.cardTheme` from `CardTheme` to `CardThemeData`. This may cause breaking changes, a migration guide will be created.

Addresses the "theme normalization" sub project within https://github.com/flutter/flutter/issues/91772
This commit is contained in:
Qun Cheng
2024-07-29 09:48:06 -07:00
committed by GitHub
parent 804cca62de
commit 2e7fa83f67
4 changed files with 273 additions and 53 deletions

View File

@@ -26,7 +26,7 @@ class CardTemplate extends TokenTemplate {
@override
String generate() => '''
class _${blockName}DefaultsM3 extends CardTheme {
class _${blockName}DefaultsM3 extends CardThemeData {
_${blockName}DefaultsM3(this.context)
: super(
clipBehavior: Clip.none,