Skip to content

Commit 5070620

Browse files
authored
Added expandIconColor property on ExpansionPanelList Widget (#115950)
* Create expanIconColor doc template * Add expandIconColor property to ExpansionPanelList * Added tests for expandIconColor on ExpansionPanelList & radio * Removed trailing spaces
1 parent 57dc071 commit 5070620

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ class ExpandIcon extends StatefulWidget {
6666
/// This property must not be null. It defaults to 8.0 padding on all sides.
6767
final EdgeInsetsGeometry padding;
6868

69-
69+
/// {@template flutter.material.ExpandIcon.color}
7070
/// The color of the icon.
7171
///
7272
/// Defaults to [Colors.black54] when the theme's
7373
/// [ThemeData.brightness] is [Brightness.light] and to
7474
/// [Colors.white60] when it is [Brightness.dark]. This adheres to the
7575
/// Material Design specifications for [icons](https://material.io/design/iconography/system-icons.html#color)
7676
/// and for [dark theme](https://material.io/design/color/dark-theme.html#ui-application)
77+
/// {@endtemplate}
7778
final Color? color;
7879

7980
/// The color of the icon when it is disabled,

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

+6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class ExpansionPanelList extends StatefulWidget {
168168
this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding,
169169
this.dividerColor,
170170
this.elevation = 2,
171+
this.expandIconColor,
171172
}) : assert(children != null),
172173
assert(animationDuration != null),
173174
_allowOnlyOnePanelOpen = false,
@@ -195,6 +196,7 @@ class ExpansionPanelList extends StatefulWidget {
195196
this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding,
196197
this.dividerColor,
197198
this.elevation = 2,
199+
this.expandIconColor,
198200
}) : assert(children != null),
199201
assert(animationDuration != null),
200202
_allowOnlyOnePanelOpen = true;
@@ -249,6 +251,9 @@ class ExpansionPanelList extends StatefulWidget {
249251
/// By default, the value of elevation is 2.
250252
final double elevation;
251253

254+
/// {@macro flutter.material.ExpandIcon.color}
255+
final Color? expandIconColor;
256+
252257
@override
253258
State<StatefulWidget> createState() => _ExpansionPanelListState();
254259
}
@@ -356,6 +361,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
356361
Widget expandIconContainer = Container(
357362
margin: const EdgeInsetsDirectional.only(end: 8.0),
358363
child: ExpandIcon(
364+
color: widget.expandIconColor,
359365
isExpanded: _isChildExpanded(index),
360366
padding: const EdgeInsets.all(16.0),
361367
onPressed: !child.canTapOnHeader

packages/flutter/test/material/expansion_panel_test.dart

+49
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,55 @@ void main() {
13901390
expect(boxDecoration.border!.top.color, dividerColor);
13911391
});
13921392

1393+
testWidgets('ExpansionPanelList respects expandIconColor', (WidgetTester tester) async {
1394+
const Color expandIconColor = Colors.blue;
1395+
await tester.pumpWidget(MaterialApp(
1396+
home: SingleChildScrollView(
1397+
child: ExpansionPanelList(
1398+
expandIconColor: expandIconColor,
1399+
children: <ExpansionPanel>[
1400+
ExpansionPanel(
1401+
canTapOnHeader: true,
1402+
body: const SizedBox.shrink(),
1403+
headerBuilder: (BuildContext context, bool isExpanded) {
1404+
return const SizedBox.shrink();
1405+
}
1406+
)
1407+
],
1408+
),
1409+
),
1410+
));
1411+
1412+
final ExpandIcon expandIcon = tester.widget(find.byType(ExpandIcon));
1413+
1414+
expect(expandIcon.color, expandIconColor);
1415+
});
1416+
1417+
testWidgets('ExpansionPanelList.radio respects expandIconColor', (WidgetTester tester) async {
1418+
const Color expandIconColor = Colors.blue;
1419+
await tester.pumpWidget(MaterialApp(
1420+
home: SingleChildScrollView(
1421+
child: ExpansionPanelList.radio(
1422+
expandIconColor: expandIconColor,
1423+
children: <ExpansionPanelRadio>[
1424+
ExpansionPanelRadio(
1425+
canTapOnHeader: true,
1426+
body: const SizedBox.shrink(),
1427+
headerBuilder: (BuildContext context, bool isExpanded) {
1428+
return const SizedBox.shrink();
1429+
},
1430+
value: true
1431+
)
1432+
],
1433+
),
1434+
),
1435+
));
1436+
1437+
final ExpandIcon expandIcon = tester.widget(find.byType(ExpandIcon));
1438+
1439+
expect(expandIcon.color, expandIconColor);
1440+
});
1441+
13931442
testWidgets('elevation is propagated properly to MergeableMaterial', (WidgetTester tester) async {
13941443
const double elevation = 8;
13951444

0 commit comments

Comments
 (0)