Skip to content

Commit

Permalink
Added expandIconColor property on ExpansionPanelList Widget (flutter#…
Browse files Browse the repository at this point in the history
…115950)

* Create expanIconColor doc template

* Add expandIconColor property to ExpansionPanelList

* Added tests for expandIconColor on ExpansionPanelList & radio

* Removed trailing spaces
  • Loading branch information
M97Chahboun authored Jan 6, 2023
1 parent 57dc071 commit 5070620
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/material/expand_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ class ExpandIcon extends StatefulWidget {
/// This property must not be null. It defaults to 8.0 padding on all sides.
final EdgeInsetsGeometry padding;


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

/// The color of the icon when it is disabled,
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/lib/src/material/expansion_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ExpansionPanelList extends StatefulWidget {
this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding,
this.dividerColor,
this.elevation = 2,
this.expandIconColor,
}) : assert(children != null),
assert(animationDuration != null),
_allowOnlyOnePanelOpen = false,
Expand Down Expand Up @@ -195,6 +196,7 @@ class ExpansionPanelList extends StatefulWidget {
this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding,
this.dividerColor,
this.elevation = 2,
this.expandIconColor,
}) : assert(children != null),
assert(animationDuration != null),
_allowOnlyOnePanelOpen = true;
Expand Down Expand Up @@ -249,6 +251,9 @@ class ExpansionPanelList extends StatefulWidget {
/// By default, the value of elevation is 2.
final double elevation;

/// {@macro flutter.material.ExpandIcon.color}
final Color? expandIconColor;

@override
State<StatefulWidget> createState() => _ExpansionPanelListState();
}
Expand Down Expand Up @@ -356,6 +361,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
Widget expandIconContainer = Container(
margin: const EdgeInsetsDirectional.only(end: 8.0),
child: ExpandIcon(
color: widget.expandIconColor,
isExpanded: _isChildExpanded(index),
padding: const EdgeInsets.all(16.0),
onPressed: !child.canTapOnHeader
Expand Down
49 changes: 49 additions & 0 deletions packages/flutter/test/material/expansion_panel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,55 @@ void main() {
expect(boxDecoration.border!.top.color, dividerColor);
});

testWidgets('ExpansionPanelList respects expandIconColor', (WidgetTester tester) async {
const Color expandIconColor = Colors.blue;
await tester.pumpWidget(MaterialApp(
home: SingleChildScrollView(
child: ExpansionPanelList(
expandIconColor: expandIconColor,
children: <ExpansionPanel>[
ExpansionPanel(
canTapOnHeader: true,
body: const SizedBox.shrink(),
headerBuilder: (BuildContext context, bool isExpanded) {
return const SizedBox.shrink();
}
)
],
),
),
));

final ExpandIcon expandIcon = tester.widget(find.byType(ExpandIcon));

expect(expandIcon.color, expandIconColor);
});

testWidgets('ExpansionPanelList.radio respects expandIconColor', (WidgetTester tester) async {
const Color expandIconColor = Colors.blue;
await tester.pumpWidget(MaterialApp(
home: SingleChildScrollView(
child: ExpansionPanelList.radio(
expandIconColor: expandIconColor,
children: <ExpansionPanelRadio>[
ExpansionPanelRadio(
canTapOnHeader: true,
body: const SizedBox.shrink(),
headerBuilder: (BuildContext context, bool isExpanded) {
return const SizedBox.shrink();
},
value: true
)
],
),
),
));

final ExpandIcon expandIcon = tester.widget(find.byType(ExpandIcon));

expect(expandIcon.color, expandIconColor);
});

testWidgets('elevation is propagated properly to MergeableMaterial', (WidgetTester tester) async {
const double elevation = 8;

Expand Down

0 comments on commit 5070620

Please sign in to comment.