Skip to content

Commit 212bac8

Browse files
authored
Revert "Update ExpansionTile to support Material 3 & add an example (#119712)" (#120300)
This reverts commit e8eac0d.
1 parent 51227a9 commit 212bac8

File tree

6 files changed

+23
-228
lines changed

6 files changed

+23
-228
lines changed

dev/tools/gen_defaults/bin/gen_defaults.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import 'package:gen_defaults/date_picker_template.dart';
3131
import 'package:gen_defaults/dialog_template.dart';
3232
import 'package:gen_defaults/divider_template.dart';
3333
import 'package:gen_defaults/drawer_template.dart';
34-
import 'package:gen_defaults/expansion_tile_template.dart';
3534
import 'package:gen_defaults/fab_template.dart';
3635
import 'package:gen_defaults/filter_chip_template.dart';
3736
import 'package:gen_defaults/icon_button_template.dart';
@@ -154,7 +153,6 @@ Future<void> main(List<String> args) async {
154153
DialogTemplate('Dialog', '$materialLib/dialog.dart', tokens).updateFile();
155154
DividerTemplate('Divider', '$materialLib/divider.dart', tokens).updateFile();
156155
DrawerTemplate('Drawer', '$materialLib/drawer.dart', tokens).updateFile();
157-
ExpansionTileTemplate('ExpansionTile', '$materialLib/expansion_tile.dart', tokens).updateFile();
158156
FABTemplate('FAB', '$materialLib/floating_action_button.dart', tokens).updateFile();
159157
FilterChipTemplate('ChoiceChip', '$materialLib/choice_chip.dart', tokens).updateFile();
160158
FilterChipTemplate('FilterChip', '$materialLib/filter_chip.dart', tokens).updateFile();

dev/tools/gen_defaults/lib/expansion_tile_template.dart

Lines changed: 0 additions & 34 deletions
This file was deleted.

examples/api/lib/material/expansion_tile/expansion_tile.0.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,33 @@
66

77
import 'package:flutter/material.dart';
88

9-
void main() => runApp(const ExpansionTileApp());
9+
void main() => runApp(const MyApp());
1010

11-
class ExpansionTileApp extends StatelessWidget {
12-
const ExpansionTileApp({super.key});
11+
class MyApp extends StatelessWidget {
12+
const MyApp({super.key});
13+
14+
static const String _title = 'Flutter Code Sample';
1315

1416
@override
1517
Widget build(BuildContext context) {
1618
return MaterialApp(
17-
theme: ThemeData(useMaterial3: true),
19+
title: _title,
1820
home: Scaffold(
19-
appBar: AppBar(title: const Text('ExpansionTile Sample')),
20-
body: const ExpansionTileExample(),
21+
appBar: AppBar(title: const Text(_title)),
22+
body: const MyStatefulWidget(),
2123
),
2224
);
2325
}
2426
}
2527

26-
class ExpansionTileExample extends StatefulWidget {
27-
const ExpansionTileExample({super.key});
28+
class MyStatefulWidget extends StatefulWidget {
29+
const MyStatefulWidget({super.key});
2830

2931
@override
30-
State<ExpansionTileExample> createState() => _ExpansionTileExampleState();
32+
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
3133
}
3234

33-
class _ExpansionTileExampleState extends State<ExpansionTileExample> {
35+
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
3436
bool _customTileExpanded = false;
3537

3638
@override
@@ -56,9 +58,7 @@ class _ExpansionTileExampleState extends State<ExpansionTileExample> {
5658
ListTile(title: Text('This is tile number 2')),
5759
],
5860
onExpansionChanged: (bool expanded) {
59-
setState(() {
60-
_customTileExpanded = expanded;
61-
});
61+
setState(() => _customTileExpanded = expanded);
6262
},
6363
),
6464
const ExpansionTile(

examples/api/test/material/expansion_tile/expansion_tile.0_test.dart

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/flutter/lib/src/material/expansion_tile.dart

Lines changed: 10 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ const Duration _kExpand = Duration(milliseconds: 200);
3434
/// to the [leading] and [trailing] properties of [ExpansionTile].
3535
///
3636
/// {@tool dartpad}
37-
/// This example demonstrates how the [ExpansionTile] icon's location and appearance
38-
/// can be customized.
37+
/// This example demonstrates different configurations of ExpansionTile.
3938
///
4039
/// ** See code in examples/api/lib/material/expansion_tile/expansion_tile.0.dart **
4140
/// {@end-tool}
@@ -217,7 +216,7 @@ class ExpansionTile extends StatefulWidget {
217216
/// Used to override to the [ListTileThemeData.iconColor].
218217
///
219218
/// If this property is null then [ExpansionTileThemeData.iconColor] is used. If that
220-
/// is also null then the value of [ColorScheme.primary] is used.
219+
/// is also null then the value of [ListTileThemeData.iconColor] is used.
221220
///
222221
/// See also:
223222
///
@@ -228,15 +227,6 @@ class ExpansionTile extends StatefulWidget {
228227
/// The icon color of tile's expansion arrow icon when the sublist is collapsed.
229228
///
230229
/// Used to override to the [ListTileThemeData.iconColor].
231-
///
232-
/// If this property is null then [ExpansionTileThemeData.collapsedIconColor] is used. If that
233-
/// is also null and [ThemeData.useMaterial3] is true, [ColorScheme.onSurface] is used. Otherwise,
234-
/// defaults to [ThemeData.unselectedWidgetColor] color.
235-
///
236-
/// See also:
237-
///
238-
/// * [ExpansionTileTheme.of], which returns the nearest [ExpansionTileTheme]'s
239-
/// [ExpansionTileThemeData].
240230
final Color? collapsedIconColor;
241231

242232

@@ -245,8 +235,7 @@ class ExpansionTile extends StatefulWidget {
245235
/// Used to override to the [ListTileThemeData.textColor].
246236
///
247237
/// If this property is null then [ExpansionTileThemeData.textColor] is used. If that
248-
/// is also null then and [ThemeData.useMaterial3] is true, color of the [TextTheme.bodyLarge]
249-
/// will be used for the [title] and [subtitle]. Otherwise, defaults to [ColorScheme.primary] color.
238+
/// is also null then the value of [ListTileThemeData.textColor] is used.
250239
///
251240
/// See also:
252241
///
@@ -258,10 +247,8 @@ class ExpansionTile extends StatefulWidget {
258247
///
259248
/// Used to override to the [ListTileThemeData.textColor].
260249
///
261-
/// If this property is null then [ExpansionTileThemeData.collapsedTextColor] is used.
262-
/// If that is also null and [ThemeData.useMaterial3] is true, color of the
263-
/// [TextTheme.bodyLarge] will be used for the [title] and [subtitle]. Otherwise,
264-
/// defaults to color of the [TextTheme.titleMedium].
250+
/// If this property is null then [ExpansionTileThemeData.collapsedTextColor] is used. If that
251+
/// is also null then the value of [ListTileThemeData.textColor] is used.
265252
///
266253
/// See also:
267254
///
@@ -454,9 +441,7 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
454441
void didChangeDependencies() {
455442
final ThemeData theme = Theme.of(context);
456443
final ExpansionTileThemeData expansionTileTheme = ExpansionTileTheme.of(context);
457-
final ExpansionTileThemeData defaults = theme.useMaterial3
458-
? _ExpansionTileDefaultsM3(context)
459-
: _ExpansionTileDefaultsM2(context);
444+
final ColorScheme colorScheme = theme.colorScheme;
460445
_borderTween
461446
..begin = widget.collapsedShape
462447
?? expansionTileTheme.collapsedShape
@@ -473,13 +458,13 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
473458
_headerColorTween
474459
..begin = widget.collapsedTextColor
475460
?? expansionTileTheme.collapsedTextColor
476-
?? defaults.collapsedTextColor
477-
..end = widget.textColor ?? expansionTileTheme.textColor ?? defaults.textColor;
461+
?? theme.textTheme.titleMedium!.color
462+
..end = widget.textColor ?? expansionTileTheme.textColor ?? colorScheme.primary;
478463
_iconColorTween
479464
..begin = widget.collapsedIconColor
480465
?? expansionTileTheme.collapsedIconColor
481-
?? defaults.collapsedIconColor
482-
..end = widget.iconColor ?? expansionTileTheme.iconColor ?? defaults.iconColor;
466+
?? theme.unselectedWidgetColor
467+
..end = widget.iconColor ?? expansionTileTheme.iconColor ?? colorScheme.primary;
483468
_backgroundColorTween
484469
..begin = widget.collapsedBackgroundColor ?? expansionTileTheme.collapsedBackgroundColor
485470
..end = widget.backgroundColor ?? expansionTileTheme.backgroundColor;
@@ -513,54 +498,3 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
513498
);
514499
}
515500
}
516-
517-
class _ExpansionTileDefaultsM2 extends ExpansionTileThemeData {
518-
_ExpansionTileDefaultsM2(this.context);
519-
520-
final BuildContext context;
521-
late final ThemeData _theme = Theme.of(context);
522-
late final ColorScheme _colorScheme = _theme.colorScheme;
523-
524-
@override
525-
Color? get textColor => _colorScheme.primary;
526-
527-
@override
528-
Color? get iconColor => _colorScheme.primary;
529-
530-
@override
531-
Color? get collapsedTextColor => _theme.textTheme.titleMedium!.color;
532-
533-
@override
534-
Color? get collapsedIconColor => _theme.unselectedWidgetColor;
535-
}
536-
537-
// BEGIN GENERATED TOKEN PROPERTIES - ExpansionTile
538-
539-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
540-
// "END GENERATED" comments are generated from data in the Material
541-
// Design token database by the script:
542-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
543-
544-
// Token database version: v0_152
545-
546-
class _ExpansionTileDefaultsM3 extends ExpansionTileThemeData {
547-
_ExpansionTileDefaultsM3(this.context);
548-
549-
final BuildContext context;
550-
late final ThemeData _theme = Theme.of(context);
551-
late final ColorScheme _colors = _theme.colorScheme;
552-
553-
@override
554-
Color? get textColor => Theme.of(context).textTheme.bodyLarge!.color;
555-
556-
@override
557-
Color? get iconColor => _colors.primary;
558-
559-
@override
560-
Color? get collapsedTextColor => Theme.of(context).textTheme.bodyLarge!.color;
561-
562-
@override
563-
Color? get collapsedIconColor => _colors.onSurface;
564-
}
565-
566-
// END GENERATED TOKEN PROPERTIES - ExpansionTile

packages/flutter/test/material/expansion_tile_test.dart

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -522,35 +522,6 @@ void main() {
522522
expect(shapeDecoration.color, backgroundColor);
523523
});
524524

525-
testWidgets('ExpansionTile default iconColor, textColor', (WidgetTester tester) async {
526-
final ThemeData theme = ThemeData(useMaterial3: true);
527-
528-
await tester.pumpWidget(MaterialApp(
529-
theme: theme,
530-
home: const Material(
531-
child: ExpansionTile(
532-
title: TestText('title'),
533-
trailing: TestIcon(),
534-
children: <Widget>[
535-
SizedBox(height: 100, width: 100),
536-
],
537-
),
538-
),
539-
));
540-
541-
Color getIconColor() => tester.state<TestIconState>(find.byType(TestIcon)).iconTheme.color!;
542-
Color getTextColor() => tester.state<TestTextState>(find.byType(TestText)).textStyle.color!;
543-
544-
expect(getIconColor(), theme.colorScheme.onSurface);
545-
expect(getTextColor(), theme.textTheme.bodyLarge!.color);
546-
547-
await tester.tap(find.text('title'));
548-
await tester.pumpAndSettle();
549-
550-
expect(getIconColor(), theme.colorScheme.primary);
551-
expect(getTextColor(), theme.textTheme.bodyLarge!.color);
552-
});
553-
554525
testWidgets('ExpansionTile iconColor, textColor', (WidgetTester tester) async {
555526
// Regression test for https://github.com/flutter/flutter/pull/78281
556527

@@ -695,38 +666,4 @@ void main() {
695666
expect(listTile.leading.runtimeType, Icon);
696667
expect(listTile.trailing, isNull);
697668
});
698-
699-
group('Material 2', () {
700-
// Tests that are only relevant for Material 2. Once ThemeData.useMaterial3
701-
// is turned on by default, these tests can be removed.
702-
703-
testWidgets('ExpansionTile default iconColor, textColor', (WidgetTester tester) async {
704-
final ThemeData theme = ThemeData(useMaterial3: false);
705-
706-
await tester.pumpWidget(MaterialApp(
707-
theme: theme,
708-
home: const Material(
709-
child: ExpansionTile(
710-
title: TestText('title'),
711-
trailing: TestIcon(),
712-
children: <Widget>[
713-
SizedBox(height: 100, width: 100),
714-
],
715-
),
716-
),
717-
));
718-
719-
Color getIconColor() => tester.state<TestIconState>(find.byType(TestIcon)).iconTheme.color!;
720-
Color getTextColor() => tester.state<TestTextState>(find.byType(TestText)).textStyle.color!;
721-
722-
expect(getIconColor(), theme.unselectedWidgetColor);
723-
expect(getTextColor(), theme.textTheme.titleMedium!.color);
724-
725-
await tester.tap(find.text('title'));
726-
await tester.pumpAndSettle();
727-
728-
expect(getIconColor(), theme.colorScheme.primary);
729-
expect(getTextColor(), theme.colorScheme.primary);
730-
});
731-
});
732669
}

0 commit comments

Comments
 (0)