Unverified Commit 72aafe86 authored by Mateus Felipe C. C. Pinto's avatar Mateus Felipe C. C. Pinto Committed by GitHub

Add `enabled` property to `ExpansionTile` (#139519)

Adds an `enabled` property to `ExpansionTile` that allows the user to disable the internal `ListTile`, so that we can prevent user interaction.

Fixes #135770.
parent 935d12cc
...@@ -252,6 +252,7 @@ class ExpansionTile extends StatefulWidget { ...@@ -252,6 +252,7 @@ class ExpansionTile extends StatefulWidget {
this.dense, this.dense,
this.visualDensity, this.visualDensity,
this.enableFeedback = true, this.enableFeedback = true,
this.enabled = true,
this.expansionAnimationStyle, this.expansionAnimationStyle,
}) : assert( }) : assert(
expandedCrossAxisAlignment != CrossAxisAlignment.baseline, expandedCrossAxisAlignment != CrossAxisAlignment.baseline,
...@@ -507,6 +508,15 @@ class ExpansionTile extends StatefulWidget { ...@@ -507,6 +508,15 @@ class ExpansionTile extends StatefulWidget {
/// {@macro flutter.material.ListTile.enableFeedback} /// {@macro flutter.material.ListTile.enableFeedback}
final bool? enableFeedback; final bool? enableFeedback;
/// Whether this expansion tile is interactive.
///
/// If false, the internal [ListTile] will be disabled, changing its
/// appearance according to the theme and disabling user interaction.
///
/// Even if disabled, the expansion can still be toggled programmatically
/// through an [ExpansionTileController].
final bool enabled;
/// Used to override the expansion animation curve and duration. /// Used to override the expansion animation curve and duration.
/// ///
/// If [AnimationStyle.duration] is provided, it will be used to override /// If [AnimationStyle.duration] is provided, it will be used to override
...@@ -685,6 +695,7 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider ...@@ -685,6 +695,7 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
iconColor: _iconColor.value ?? expansionTileTheme.iconColor, iconColor: _iconColor.value ?? expansionTileTheme.iconColor,
textColor: _headerColor.value, textColor: _headerColor.value,
child: ListTile( child: ListTile(
enabled: widget.enabled,
onTap: _handleTap, onTap: _handleTap,
dense: widget.dense, dense: widget.dense,
visualDensity: widget.visualDensity, visualDensity: widget.visualDensity,
......
...@@ -1333,4 +1333,36 @@ void main() { ...@@ -1333,4 +1333,36 @@ void main() {
expect(tileWidget.enableFeedback, enableFeedback); expect(tileWidget.enableFeedback, enableFeedback);
expect(tileWidget.visualDensity, visualDensity); expect(tileWidget.visualDensity, visualDensity);
}); });
testWidgetsWithLeakTracking('ExpansionTileController should not toggle if disabled', (WidgetTester tester) async {
final ExpansionTileController controller = ExpansionTileController();
await tester.pumpWidget(MaterialApp(
home: Material(
child: ExpansionTile(
enabled: false,
controller: controller,
title: const Text('Title'),
children: const <Widget>[
Text('Child 0'),
],
),
),
));
expect(find.text('Child 0'), findsNothing);
expect(controller.isExpanded, isFalse);
await tester.tap(find.widgetWithText(ExpansionTile, 'Title'));
await tester.pumpAndSettle();
expect(find.text('Child 0'), findsNothing);
expect(controller.isExpanded, isFalse);
controller.expand();
await tester.pumpAndSettle();
expect(find.text('Child 0'), findsOneWidget);
expect(controller.isExpanded, isTrue);
await tester.tap(find.widgetWithText(ExpansionTile, 'Title'));
await tester.pumpAndSettle();
expect(find.text('Child 0'), findsOneWidget);
expect(controller.isExpanded, isTrue);
});
} }
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