From 97426566104215127a44666fe2b75c18208d1701 Mon Sep 17 00:00:00 2001 From: Mohammed CHAHBOUN <69054810+M97Chahboun@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:52:19 +0100 Subject: [PATCH] Adds splashBorderRadius property to TabBarTheme (#160046) Adds splashBorderRadius property to TabBarTheme Fix #159845 ## 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]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com> --- .../lib/src/material/tab_bar_theme.dart | 12 ++++- packages/flutter/lib/src/material/tabs.dart | 2 +- .../test/material/tab_bar_theme_test.dart | 54 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/tab_bar_theme.dart b/packages/flutter/lib/src/material/tab_bar_theme.dart index 16c93c0275..a38c6ffcaa 100644 --- a/packages/flutter/lib/src/material/tab_bar_theme.dart +++ b/packages/flutter/lib/src/material/tab_bar_theme.dart @@ -327,6 +327,7 @@ class TabBarThemeData with Diagnosticable { this.tabAlignment, this.textScaler, this.indicatorAnimation, + this.splashBorderRadius }); /// Overrides the default value for [TabBar.indicator]. @@ -389,6 +390,9 @@ class TabBarThemeData with Diagnosticable { /// Overrides the default value for [TabBar.indicatorAnimation]. final TabIndicatorAnimation? indicatorAnimation; + /// Defines the clipping radius of splashes that extend outside the bounds of the tab. + final BorderRadius? splashBorderRadius; + /// Creates a copy of this object but with the given fields replaced with the /// new values. TabBarThemeData copyWith({ @@ -408,6 +412,7 @@ class TabBarThemeData with Diagnosticable { TabAlignment? tabAlignment, TextScaler? textScaler, TabIndicatorAnimation? indicatorAnimation, + BorderRadius? splashBorderRadius, }) { return TabBarThemeData( indicator: indicator ?? this.indicator, @@ -426,6 +431,7 @@ class TabBarThemeData with Diagnosticable { tabAlignment: tabAlignment ?? this.tabAlignment, textScaler: textScaler ?? this.textScaler, indicatorAnimation: indicatorAnimation ?? this.indicatorAnimation, + splashBorderRadius: splashBorderRadius ?? this.splashBorderRadius, ); } @@ -453,6 +459,7 @@ class TabBarThemeData with Diagnosticable { tabAlignment: t < 0.5 ? a.tabAlignment : b.tabAlignment, textScaler: t < 0.5 ? a.textScaler : b.textScaler, indicatorAnimation: t < 0.5 ? a.indicatorAnimation : b.indicatorAnimation, + splashBorderRadius: BorderRadius.lerp(a.splashBorderRadius, a.splashBorderRadius, t) ); } @@ -474,6 +481,7 @@ class TabBarThemeData with Diagnosticable { tabAlignment, textScaler, indicatorAnimation, + splashBorderRadius, ); @override @@ -500,7 +508,8 @@ class TabBarThemeData with Diagnosticable { && other.mouseCursor == mouseCursor && other.tabAlignment == tabAlignment && other.textScaler == textScaler - && other.indicatorAnimation == indicatorAnimation; + && other.indicatorAnimation == indicatorAnimation + && other.splashBorderRadius == splashBorderRadius; } @override @@ -522,5 +531,6 @@ class TabBarThemeData with Diagnosticable { properties.add(DiagnosticsProperty('tabAlignment', tabAlignment, defaultValue: null)); properties.add(DiagnosticsProperty('textScaler', textScaler, defaultValue: null)); properties.add(DiagnosticsProperty('indicatorAnimation', indicatorAnimation, defaultValue: null)); + properties.add(DiagnosticsProperty('splashBorderRadius', splashBorderRadius, defaultValue: null)); } } diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index f3bff2e378..defc21b174 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -1813,7 +1813,7 @@ class _TabBarState extends State { enableFeedback: widget.enableFeedback ?? true, overlayColor: widget.overlayColor ?? tabBarTheme.overlayColor ?? defaultOverlay, splashFactory: widget.splashFactory ?? tabBarTheme.splashFactory ?? _defaults.splashFactory, - borderRadius: widget.splashBorderRadius, + borderRadius: widget.splashBorderRadius ?? tabBarTheme.splashBorderRadius ?? _defaults.splashBorderRadius, child: Padding( padding: EdgeInsets.only(bottom: widget.indicatorWeight), child: Stack( diff --git a/packages/flutter/test/material/tab_bar_theme_test.dart b/packages/flutter/test/material/tab_bar_theme_test.dart index 5fa8cde6e8..74bb121859 100644 --- a/packages/flutter/test/material/tab_bar_theme_test.dart +++ b/packages/flutter/test/material/tab_bar_theme_test.dart @@ -1791,4 +1791,58 @@ void main() { targetRect = const Rect.fromLTRB(275.0, 0.0, 325.0, 48.0); expectIndicatorAttrs(tabBarBox, rect: rect, targetRect: targetRect); }); + + testWidgets('TabBar inherits splashBorderRadius from theme', (WidgetTester tester) async { + const Color hoverColor = Color(0xfff44336); + const double radius = 20; + await tester.pumpWidget( + Material( + child: Localizations( + locale: const Locale('en', 'US'), + delegates: const >[ + DefaultMaterialLocalizations.delegate, + DefaultWidgetsLocalizations.delegate, + ], + child: DefaultTabController( + length: 1, + child: TabBarTheme( + data: TabBarThemeData( + splashBorderRadius: BorderRadius.circular(radius), + ), + child: const TabBar( + overlayColor: WidgetStateMapper( + { + WidgetState.hovered: hoverColor, + WidgetState.any: Colors.black54, + }, + ), + tabs: [ + Tab( + child: Text(''), + ), + ], + ), + ), + ), + ), + ), + ); + final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1); + await gesture.moveTo(tester.getCenter(find.byType(Tab))); + await tester.pumpAndSettle(); + final Finder findInkWell = find.byType(InkWell); + + final BuildContext context = tester.element(findInkWell); + expect( + Material.of(context), + paints..rrect( + color: hoverColor, + rrect: RRect.fromRectAndRadius( + tester.getRect(findInkWell), + const Radius.circular(radius), + ), + ), + ); + gesture.removePointer(); + }); }