Skip to content

Commit

Permalink
Adds splashBorderRadius property to TabBarTheme (flutter#160046)
Browse files Browse the repository at this point in the history
Adds splashBorderRadius property to TabBarTheme

Fix flutter#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 <[email protected]>
  • Loading branch information
M97Chahboun and QuncCccccc authored Dec 12, 2024
1 parent 5cd440f commit 9742656
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/flutter/lib/src/material/tab_bar_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ class TabBarThemeData with Diagnosticable {
this.tabAlignment,
this.textScaler,
this.indicatorAnimation,
this.splashBorderRadius
});

/// Overrides the default value for [TabBar.indicator].
Expand Down Expand Up @@ -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({
Expand All @@ -408,6 +412,7 @@ class TabBarThemeData with Diagnosticable {
TabAlignment? tabAlignment,
TextScaler? textScaler,
TabIndicatorAnimation? indicatorAnimation,
BorderRadius? splashBorderRadius,
}) {
return TabBarThemeData(
indicator: indicator ?? this.indicator,
Expand All @@ -426,6 +431,7 @@ class TabBarThemeData with Diagnosticable {
tabAlignment: tabAlignment ?? this.tabAlignment,
textScaler: textScaler ?? this.textScaler,
indicatorAnimation: indicatorAnimation ?? this.indicatorAnimation,
splashBorderRadius: splashBorderRadius ?? this.splashBorderRadius,
);
}

Expand Down Expand Up @@ -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)
);
}

Expand All @@ -474,6 +481,7 @@ class TabBarThemeData with Diagnosticable {
tabAlignment,
textScaler,
indicatorAnimation,
splashBorderRadius,
);

@override
Expand All @@ -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
Expand All @@ -522,5 +531,6 @@ class TabBarThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<TabAlignment?>('tabAlignment', tabAlignment, defaultValue: null));
properties.add(DiagnosticsProperty<TextScaler?>('textScaler', textScaler, defaultValue: null));
properties.add(DiagnosticsProperty<TabIndicatorAnimation?>('indicatorAnimation', indicatorAnimation, defaultValue: null));
properties.add(DiagnosticsProperty<BorderRadius?>('splashBorderRadius', splashBorderRadius, defaultValue: null));
}
}
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ class _TabBarState extends State<TabBar> {
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(
Expand Down
54 changes: 54 additions & 0 deletions packages/flutter/test/material/tab_bar_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
child: DefaultTabController(
length: 1,
child: TabBarTheme(
data: TabBarThemeData(
splashBorderRadius: BorderRadius.circular(radius),
),
child: const TabBar(
overlayColor: WidgetStateMapper<Color>(
<WidgetStatesConstraint, Color>{
WidgetState.hovered: hoverColor,
WidgetState.any: Colors.black54,
},
),
tabs: <Widget>[
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();
});
}

0 comments on commit 9742656

Please sign in to comment.