Normalize TabBarTheme (#155476)

This PR is to make preparations to make `TabBarTheme` conform to Flutter's conventions for component themes:

* Added a `TabBarThemeData` class which defines overrides for the defaults for `TabBar` properties.
* Added 2 `TabBarTheme` constructor parameters: `TabBarThemeData? data` and `Widget? child`. This is now the preferred way to configure a `TabBarTheme`:
```
TabBarTheme(
  data: TabBarThemeData(labelColor: xxx, indicatorColor: xxx, ...),
  child: TabBar(...)
)
```
  These two properties are made nullable to not break existing apps which has customized `ThemeData.tabBarTheme`.

* Changed the type of component theme defaults from `TabBarTheme` to `TabBarThemeData`.

TODO:

* Fix internal failures.
* Change the type of `ThemeData.tabBarTheme` from `TabBarTheme` to `TabBarThemeData`. 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-09-25 10:19:00 -07:00
committed by GitHub
parent 3d14246cee
commit f310625bc6
4 changed files with 489 additions and 99 deletions

View File

@@ -12,7 +12,7 @@ class TabsTemplate extends TokenTemplate {
@override
String generate() => '''
class _${blockName}PrimaryDefaultsM3 extends TabBarTheme {
class _${blockName}PrimaryDefaultsM3 extends TabBarThemeData {
_${blockName}PrimaryDefaultsM3(this.context, this.isScrollable)
: super(indicatorSize: TabBarIndicatorSize.label);
@@ -91,7 +91,7 @@ class _${blockName}PrimaryDefaultsM3 extends TabBarTheme {
static const EdgeInsetsGeometry iconMargin = EdgeInsets.only(bottom: 2);
}
class _${blockName}SecondaryDefaultsM3 extends TabBarTheme {
class _${blockName}SecondaryDefaultsM3 extends TabBarThemeData {
_${blockName}SecondaryDefaultsM3(this.context, this.isScrollable)
: super(indicatorSize: TabBarIndicatorSize.tab);