mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix ExpansionTile shows children background when expanded (#107834)
This commit is contained in:
parent
2b1288eeed
commit
e368e5862e
@ -10,6 +10,7 @@ import 'expansion_tile_theme.dart';
|
||||
import 'icons.dart';
|
||||
import 'list_tile.dart';
|
||||
import 'list_tile_theme.dart';
|
||||
import 'material.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
const Duration _kExpand = Duration(milliseconds: 200);
|
||||
@ -432,11 +433,13 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
|
||||
offstage: closed,
|
||||
child: TickerMode(
|
||||
enabled: !closed,
|
||||
child: Padding(
|
||||
padding: widget.childrenPadding ?? expansionTileTheme.childrenPadding ?? EdgeInsets.zero,
|
||||
child: Column(
|
||||
crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center,
|
||||
children: widget.children,
|
||||
child: Material(
|
||||
child: Padding(
|
||||
padding: widget.childrenPadding ?? expansionTileTheme.childrenPadding ?? EdgeInsets.zero,
|
||||
child: Column(
|
||||
crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center,
|
||||
children: widget.children,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../rendering/mock_canvas.dart';
|
||||
|
||||
class TestIcon extends StatefulWidget {
|
||||
const TestIcon({super.key});
|
||||
|
||||
@ -481,6 +483,51 @@ void main() {
|
||||
expect(columnRect.bottom, paddingRect.bottom - 4);
|
||||
});
|
||||
|
||||
testWidgets('ExpansionTile adds a Material widget above its children when expanded', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/107030
|
||||
const Color childColor = Color(0xff4caf50);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: ExpansionTile(
|
||||
title: Text('title'),
|
||||
childrenPadding: EdgeInsets.fromLTRB(10, 8, 12, 4),
|
||||
children: <Widget>[
|
||||
ListTile(tileColor: childColor),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder rootMaterialFinder = find.ancestor(
|
||||
of: find.byType(ExpansionTile),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
|
||||
final Finder expansionTileMaterialFinder = find.descendant(
|
||||
of: find.byType(ExpansionTile),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
|
||||
// ExpansionTile should not add a Material widget when it is not expanded
|
||||
expect(expansionTileMaterialFinder, findsNothing);
|
||||
|
||||
// Expand
|
||||
await tester.tap(find.text('title'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// ExpansionTile adds a Material widget when it is expanded
|
||||
expect(expansionTileMaterialFinder, findsOneWidget);
|
||||
|
||||
// Child color is painted on the inner Material widget
|
||||
expect(rootMaterialFinder, isNot(paints..path()..path(color: childColor)));
|
||||
expect(expansionTileMaterialFinder, paints..path(color: childColor));
|
||||
});
|
||||
|
||||
testWidgets('ExpansionTile.collapsedBackgroundColor', (WidgetTester tester) async {
|
||||
const Key expansionTileKey = Key('expansionTileKey');
|
||||
const Color backgroundColor = Colors.red;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user