diff --git a/packages/flutter/lib/src/material/expansion_tile.dart b/packages/flutter/lib/src/material/expansion_tile.dart index 0c736c6639..fab75cba94 100644 --- a/packages/flutter/lib/src/material/expansion_tile.dart +++ b/packages/flutter/lib/src/material/expansion_tile.dart @@ -235,6 +235,7 @@ class ExpansionTile extends StatefulWidget { this.onExpansionChanged, this.children = const [], this.trailing, + this.showTrailingIcon = true, this.initiallyExpanded = false, this.maintainState = false, this.tilePadding, @@ -322,6 +323,9 @@ class ExpansionTile extends StatefulWidget { /// may replace the rotating expansion arrow icon. final Widget? trailing; + /// Specifies if the [ExpansionTile] should build a default trailing icon if [trailing] is null. + final bool showTrailingIcon; + /// Specifies if the list tile is initially expanded (true) or collapsed (false, the default). final bool initiallyExpanded; @@ -731,7 +735,7 @@ class _ExpansionTileState extends State with SingleTickerProvider leading: widget.leading ?? _buildLeadingIcon(context), title: widget.title, subtitle: widget.subtitle, - trailing: widget.trailing ?? _buildTrailingIcon(context), + trailing: widget.showTrailingIcon ? widget.trailing ?? _buildTrailingIcon(context) : null, minTileHeight: widget.minTileHeight, ), ), diff --git a/packages/flutter/test/material/expansion_tile_test.dart b/packages/flutter/test/material/expansion_tile_test.dart index 0eb18a98ad..536e4fd36a 100644 --- a/packages/flutter/test/material/expansion_tile_test.dart +++ b/packages/flutter/test/material/expansion_tile_test.dart @@ -1532,4 +1532,40 @@ void main() { expect(find.text('Child 0'), findsOneWidget); expect(controller.isExpanded, isTrue); }); + + testWidgets('ExpansionTile does not include the default trailing icon when showTrailingIcon: false (#145268)', (WidgetTester tester) async { + await tester.pumpWidget(const MaterialApp( + home: Material( + child: ExpansionTile( + enabled: false, + tilePadding: EdgeInsets.zero, + title: ColoredBox(color: Colors.red, child: Text('Title')), + showTrailingIcon: false, + ), + ), + )); + + final Size materialAppSize = tester.getSize(find.byType(MaterialApp)); + final Size titleSize = tester.getSize(find.byType(ColoredBox)); + + expect(titleSize.width, materialAppSize.width); + }); + + testWidgets('ExpansionTile with smaller trailing widget allocates at least 32.0 units of space (preserves original behavior) (#145268)', (WidgetTester tester) async { + await tester.pumpWidget(const MaterialApp( + home: Material( + child: ExpansionTile( + enabled: false, + tilePadding: EdgeInsets.zero, + title: ColoredBox(color: Colors.red, child: Text('Title')), + trailing: SizedBox.shrink(), + ), + ), + )); + + final Size materialAppSize = tester.getSize(find.byType(MaterialApp)); + final Size titleSize = tester.getSize(find.byType(ColoredBox)); + + expect(titleSize.width, materialAppSize.width - 32.0); + }); }