From 507062032fa44678100c46250712f6b9dc07ba4b Mon Sep 17 00:00:00 2001 From: Mohammed CHAHBOUN <69054810+M97Chahboun@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:13:18 +0100 Subject: [PATCH] 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 --- .../flutter/lib/src/material/expand_icon.dart | 3 +- .../lib/src/material/expansion_panel.dart | 6 +++ .../test/material/expansion_panel_test.dart | 49 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/expand_icon.dart b/packages/flutter/lib/src/material/expand_icon.dart index ba20dcc5df26..fcf1f8799042 100644 --- a/packages/flutter/lib/src/material/expand_icon.dart +++ b/packages/flutter/lib/src/material/expand_icon.dart @@ -66,7 +66,7 @@ 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 @@ -74,6 +74,7 @@ class ExpandIcon extends StatefulWidget { /// [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, diff --git a/packages/flutter/lib/src/material/expansion_panel.dart b/packages/flutter/lib/src/material/expansion_panel.dart index 8195653e8c28..6e64eeb73358 100644 --- a/packages/flutter/lib/src/material/expansion_panel.dart +++ b/packages/flutter/lib/src/material/expansion_panel.dart @@ -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, @@ -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; @@ -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 createState() => _ExpansionPanelListState(); } @@ -356,6 +361,7 @@ class _ExpansionPanelListState extends State { 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 diff --git a/packages/flutter/test/material/expansion_panel_test.dart b/packages/flutter/test/material/expansion_panel_test.dart index cea8f6a88c5a..d6cdc27a4639 100644 --- a/packages/flutter/test/material/expansion_panel_test.dart +++ b/packages/flutter/test/material/expansion_panel_test.dart @@ -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( + 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( + 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;