Skip to content

Commit 70a3c3c

Browse files
Add optional splashColor property to ExpansionTile (flutter#172224)
This PR adds support for customizing the `splashColor` in the `ExpansionTile` widget. Currently, ExpansionTile uses the theme’s default splash color without allowing overrides. This change introduces a new optional splashColor parameter so developers can better control the ripple effect color when the tile is tapped. ## 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. <!-- Links --> [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 --------- Co-authored-by: Victor Sanni <[email protected]>
1 parent fa5d6aa commit 70a3c3c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/flutter/lib/src/material/expansion_tile.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class ExpansionTile extends StatefulWidget {
137137
this.controlAffinity,
138138
this.controller,
139139
this.dense,
140+
this.splashColor,
140141
this.visualDensity,
141142
this.minTileHeight,
142143
this.enableFeedback = true,
@@ -402,6 +403,25 @@ class ExpansionTile extends StatefulWidget {
402403
/// {@macro flutter.material.ListTile.dense}
403404
final bool? dense;
404405

406+
/// The splash color of the ink response when the tile is tapped.
407+
///
408+
/// This color is passed directly to the underlying [ListTile]'s
409+
/// `splashColor` property, which controls the ink ripple (splash)
410+
/// animation when the tile is tapped. Internally, [ListTile] uses
411+
/// an [InkWell] (which handles the actual splash effect), and so the
412+
/// provided color will apply to that ripple.
413+
///
414+
/// If null, the splash color will default to the current theme’s
415+
/// `ThemeData.splashColor`.
416+
///
417+
/// See also:
418+
///
419+
/// * [ListTile.splashColor], which sets the ink splash for the tile.
420+
/// * [InkWell.splashColor], which determines the color of the ripple
421+
/// effect in Material widgets.
422+
/// * [ThemeData.splashColor], which provides a fallback color.
423+
final Color? splashColor;
424+
405425
/// Defines how compact the expansion tile's layout will be.
406426
///
407427
/// {@macro flutter.material.themedata.visualDensity}
@@ -593,6 +613,7 @@ class _ExpansionTileState extends State<ExpansionTile> {
593613
enabled: widget.enabled,
594614
onTap: _tileController.isExpanded ? _tileController.collapse : _tileController.expand,
595615
dense: widget.dense,
616+
splashColor: widget.splashColor,
596617
visualDensity: widget.visualDensity,
597618
enableFeedback: widget.enableFeedback,
598619
contentPadding: widget.tilePadding ?? _expansionTileTheme.tilePadding,

packages/flutter/test/material/expansion_tile_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,13 +1600,14 @@ void main() {
16001600
expect(controller2, isNull);
16011601
});
16021602

1603-
testWidgets('Check if dense, enableFeedback, visualDensity parameter is working', (
1603+
testWidgets('Check if dense, splashColor, enableFeedback, visualDensity parameter is working', (
16041604
WidgetTester tester,
16051605
) async {
16061606
final GlobalKey titleKey = GlobalKey();
16071607
final GlobalKey nonDescendantKey = GlobalKey();
16081608

16091609
const bool dense = true;
1610+
const Color splashColor = Colors.blue;
16101611
const bool enableFeedback = false;
16111612
const VisualDensity visualDensity = VisualDensity.compact;
16121613

@@ -1617,6 +1618,7 @@ void main() {
16171618
children: <Widget>[
16181619
ExpansionTile(
16191620
dense: dense,
1621+
splashColor: splashColor,
16201622
enableFeedback: enableFeedback,
16211623
visualDensity: visualDensity,
16221624
title: Text('Title', key: titleKey),
@@ -1632,6 +1634,7 @@ void main() {
16321634
final Finder tileFinder = find.byType(ListTile);
16331635
final ListTile tileWidget = tester.widget<ListTile>(tileFinder);
16341636
expect(tileWidget.dense, dense);
1637+
expect(tileWidget.splashColor, splashColor);
16351638
expect(tileWidget.enableFeedback, enableFeedback);
16361639
expect(tileWidget.visualDensity, visualDensity);
16371640
});

0 commit comments

Comments
 (0)