From 7bfcb2f66f47e0b3206f86ffd236253d50c3f795 Mon Sep 17 00:00:00 2001 From: Huy Date: Thu, 22 May 2025 05:14:16 +0700 Subject: [PATCH] Normalize BottomAppBarTheme (continue) (#168966) This is following https://github.com/flutter/flutter/pull/168586: See https://github.com/flutter/flutter/pull/168586#discussion_r2082606584 for the context of this. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md Signed-off-by: huycozy --- .../flutter/lib/src/material/theme_data.dart | 35 +++---------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index d42d6989c50..bfba0d2200c 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -320,8 +320,7 @@ class ThemeData with Diagnosticable { AppBarTheme? appBarTheme, BadgeThemeData? badgeTheme, MaterialBannerThemeData? bannerTheme, - // TODO(huycozy): Change the parameter type to BottomAppBarThemeData - Object? bottomAppBarTheme, + BottomAppBarThemeData? bottomAppBarTheme, BottomNavigationBarThemeData? bottomNavigationBarTheme, BottomSheetThemeData? bottomSheetTheme, ButtonThemeData? buttonTheme, @@ -527,16 +526,7 @@ class ThemeData with Diagnosticable { appBarTheme ??= const AppBarTheme(); badgeTheme ??= const BadgeThemeData(); bannerTheme ??= const MaterialBannerThemeData(); - // TODO(huycozy): Clean this up once the type of `bottomAppBarTheme` is changed to `BottomAppBarThemeData` - if (bottomAppBarTheme != null) { - if (bottomAppBarTheme is BottomAppBarTheme) { - bottomAppBarTheme = bottomAppBarTheme.data; - } else if (bottomAppBarTheme is! BottomAppBarThemeData) { - throw ArgumentError( - 'bottomAppBarTheme must be either a BottomAppBarThemeData or a BottomAppBarTheme', - ); - } - } + bottomAppBarTheme ??= const BottomAppBarThemeData(); bottomNavigationBarTheme ??= const BottomNavigationBarThemeData(); bottomSheetTheme ??= const BottomSheetThemeData(); cardTheme ??= const CardThemeData(); @@ -630,9 +620,7 @@ class ThemeData with Diagnosticable { appBarTheme: appBarTheme, badgeTheme: badgeTheme, bannerTheme: bannerTheme, - // TODO(huycozy): Remove this type cast when bottomAppBarTheme is explicitly set to BottomAppBarThemeData - bottomAppBarTheme: - (bottomAppBarTheme as BottomAppBarThemeData?) ?? const BottomAppBarThemeData(), + bottomAppBarTheme: bottomAppBarTheme, bottomNavigationBarTheme: bottomNavigationBarTheme, bottomSheetTheme: bottomSheetTheme, buttonTheme: buttonTheme, @@ -1531,8 +1519,7 @@ class ThemeData with Diagnosticable { AppBarTheme? appBarTheme, BadgeThemeData? badgeTheme, MaterialBannerThemeData? bannerTheme, - // TODO(huycozy): Change the parameter type to BottomAppBarThemeData - Object? bottomAppBarTheme, + BottomAppBarThemeData? bottomAppBarTheme, BottomNavigationBarThemeData? bottomNavigationBarTheme, BottomSheetThemeData? bottomSheetTheme, ButtonThemeData? buttonTheme, @@ -1651,19 +1638,7 @@ class ThemeData with Diagnosticable { appBarTheme: appBarTheme ?? this.appBarTheme, badgeTheme: badgeTheme ?? this.badgeTheme, bannerTheme: bannerTheme ?? this.bannerTheme, - // TODO(huycozy): Remove these checks when bottomAppBarTheme is a BottomAppBarThemeData - bottomAppBarTheme: () { - if (bottomAppBarTheme != null) { - if (bottomAppBarTheme is BottomAppBarTheme) { - return bottomAppBarTheme.data; - } else if (bottomAppBarTheme is! BottomAppBarThemeData) { - throw ArgumentError( - 'bottomAppBarTheme must be either a BottomAppBarThemeData or a BottomAppBarTheme', - ); - } - } - return bottomAppBarTheme as BottomAppBarThemeData? ?? this.bottomAppBarTheme; - }(), + bottomAppBarTheme: bottomAppBarTheme ?? this.bottomAppBarTheme, bottomNavigationBarTheme: bottomNavigationBarTheme ?? this.bottomNavigationBarTheme, bottomSheetTheme: bottomSheetTheme ?? this.bottomSheetTheme, buttonTheme: buttonTheme ?? this.buttonTheme,