Update ExpansionPanel
example for the updated expansionCallback
callback (#132837)
fixes [ExpansionPanelList can't expand/collapse on the latest stable/master ](https://github.com/flutter/flutter/issues/132759) https://github.com/flutter/flutter/pull/128082 updated the `expansionCallback` and also the `ExpansionPanel` sample in the Flutter gallery but not the API example. This PR fixes the API example and adds tests.
This commit is contained in:
parent
505f9d8954
commit
af79b4c7a3
@ -306,7 +306,6 @@ final Set<String> _knownMissingTests = <String>{
|
||||
'examples/api/test/material/icon_button/icon_button.3_test.dart',
|
||||
'examples/api/test/material/icon_button/icon_button.0_test.dart',
|
||||
'examples/api/test/material/icon_button/icon_button.1_test.dart',
|
||||
'examples/api/test/material/expansion_panel/expansion_panel_list.0_test.dart',
|
||||
'examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart',
|
||||
'examples/api/test/material/input_decorator/input_decoration.1_test.dart',
|
||||
'examples/api/test/material/input_decorator/input_decoration.prefix_icon_constraints.0_test.dart',
|
||||
|
@ -67,7 +67,7 @@ class _ExpansionPanelListExampleState extends State<ExpansionPanelListExample> {
|
||||
return ExpansionPanelList(
|
||||
expansionCallback: (int index, bool isExpanded) {
|
||||
setState(() {
|
||||
_data[index].isExpanded = !isExpanded;
|
||||
_data[index].isExpanded = isExpanded;
|
||||
});
|
||||
},
|
||||
children: _data.map<ExpansionPanel>((Item item) {
|
||||
|
@ -0,0 +1,75 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/expansion_panel/expansion_panel_list.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('ExpansionPanel can be expanded', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.ExpansionPanelListExampleApp(),
|
||||
);
|
||||
|
||||
// Verify the first tile is collapsed.
|
||||
expect(tester.widget<ExpandIcon>(find.byType(ExpandIcon).first).isExpanded, false);
|
||||
|
||||
// Tap to expand the first tile.
|
||||
await tester.tap(find.byType(ExpandIcon).first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify that the first tile is expanded.
|
||||
expect(tester.widget<ExpandIcon>(find.byType(ExpandIcon).first).isExpanded, true);
|
||||
});
|
||||
|
||||
testWidgets('Tap to delete a ExpansionPanel', (WidgetTester tester) async {
|
||||
const int index = 3;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.ExpansionPanelListExampleApp(),
|
||||
);
|
||||
|
||||
expect(find.widgetWithText(ListTile, 'Panel $index'), findsOneWidget);
|
||||
expect(tester.widget<ExpandIcon>(find.byType(ExpandIcon).at(index)).isExpanded, false);
|
||||
|
||||
// Tap to expand the tile at index 3.
|
||||
await tester.tap(find.byType(ExpandIcon).at(index));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.widget<ExpandIcon>(find.byType(ExpandIcon).at(index)).isExpanded, true);
|
||||
|
||||
// Tap to delete the tile at index 3.
|
||||
await tester.tap(find.byIcon(Icons.delete).at(index));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify that the tile at index 3 is deleted.
|
||||
expect(find.widgetWithText(ListTile, 'Panel $index'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('ExpansionPanelList is scrollable', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.ExpansionPanelListExampleApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(SingleChildScrollView), findsOneWidget);
|
||||
|
||||
// Expand all the tiles.
|
||||
for (int i = 0; i < 8; i++) {
|
||||
await tester.tap(find.byType(ExpandIcon).at(i));
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Check panel 3 tile position.
|
||||
Offset tilePosition = tester.getBottomLeft(find.widgetWithText(ListTile, 'Panel 3'));
|
||||
expect(tilePosition.dy, 656.0);
|
||||
|
||||
// Scroll up.
|
||||
await tester.drag(find.byType(SingleChildScrollView), const Offset(0, -300));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify panel 3 tile position is updated after scrolling.
|
||||
tilePosition = tester.getBottomLeft(find.widgetWithText(ListTile, 'Panel 3'));
|
||||
expect(tilePosition.dy, 376.0);
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user