Unverified Commit 1dafa400 authored by Mahdi Bagheri's avatar Mahdi Bagheri Committed by GitHub

Added Features requested in #137530 (#137532)

This PR will add new parameters to `ExpansionTile` widget to manage `dense`, `visualDensity` and `enableFeedback` of the main ListTile.

Solves #137530 

It is not a breaking change.
parent 5350da67
......@@ -14,6 +14,7 @@ import 'list_tile_theme.dart';
import 'material.dart';
import 'material_localizations.dart';
import 'theme.dart';
import 'theme_data.dart';
const Duration _kExpand = Duration(milliseconds: 200);
......@@ -248,6 +249,9 @@ class ExpansionTile extends StatefulWidget {
this.clipBehavior,
this.controlAffinity,
this.controller,
this.dense,
this.visualDensity,
this.enableFeedback = true,
}) : assert(
expandedCrossAxisAlignment != CrossAxisAlignment.baseline,
'CrossAxisAlignment.baseline is not supported since the expanded children '
......@@ -491,6 +495,17 @@ class ExpansionTile extends StatefulWidget {
/// than supplying a controller.
final ExpansionTileController? controller;
/// {@macro flutter.material.ListTile.dense}
final bool? dense;
/// Defines how compact the expansion tile's layout will be.
///
/// {@macro flutter.material.themedata.visualDensity}
final VisualDensity? visualDensity;
/// {@macro flutter.material.ListTile.enableFeedback}
final bool? enableFeedback;
@override
State<ExpansionTile> createState() => _ExpansionTileState();
}
......@@ -629,6 +644,7 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
case TargetPlatform.windows:
break;
}
return Container(
clipBehavior: clipBehavior,
decoration: ShapeDecoration(
......@@ -646,6 +662,9 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
textColor: _headerColor.value,
child: ListTile(
onTap: _handleTap,
dense: widget.dense,
visualDensity: widget.visualDensity,
enableFeedback: widget.enableFeedback,
contentPadding: widget.tilePadding ?? expansionTileTheme.tilePadding,
leading: widget.leading ?? _buildLeadingIcon(context),
title: widget.title,
......
......@@ -424,6 +424,7 @@ class ListTile extends StatelessWidget {
/// line limits using [Text.maxLines].
final bool isThreeLine;
/// {@template flutter.material.ListTile.dense}
/// Whether this list tile is part of a vertically dense list.
///
/// If this property is null then its value is based on [ListTileTheme.dense].
......@@ -431,6 +432,7 @@ class ListTile extends StatelessWidget {
/// Dense list tiles default to a smaller height.
///
/// It is not recommended to set [dense] to true when [ThemeData.useMaterial3] is true.
/// {@endtemplate}
final bool? dense;
/// Defines how compact the list tile's layout will be.
......
......@@ -1198,4 +1198,38 @@ void main() {
final ExpansionTileController? controller2 = ExpansionTileController.maybeOf(nonDescendantKey.currentContext!);
expect(controller2, isNull);
});
testWidgetsWithLeakTracking('Check if dense, enableFeedback, visualDensity parameter is working', (WidgetTester tester) async {
final GlobalKey titleKey = GlobalKey();
final GlobalKey nonDescendantKey = GlobalKey();
const bool dense = true;
const bool enableFeedback = false;
const VisualDensity visualDensity = VisualDensity.compact;
await tester.pumpWidget(MaterialApp(
home: Material(
child: Column(
children: <Widget>[
ExpansionTile(
dense: dense,
enableFeedback: enableFeedback,
visualDensity: visualDensity,
title: Text('Title', key: titleKey),
children: const <Widget>[
Text('Child 0'),
],
),
Text('Non descendant', key: nonDescendantKey),
],
),
),
));
final Finder tileFinder = find.byType(ListTile);
final ListTile tileWidget = tester.widget<ListTile>(tileFinder);
expect(tileWidget.dense, dense);
expect(tileWidget.enableFeedback, enableFeedback);
expect(tileWidget.visualDensity, visualDensity);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment