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>
This commit is contained in:
committed by
GitHub
parent
5cd440f6ec
commit
9742656610
@@ -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', 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user