Reputation: 550
I am new to testing widgets in flutter and I have no clue why it doesn't work. My expansionTile:
ExpansionTile(
title: Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: Table(
columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(1),
1: FlexColumnWidth(2.5),
2: FlexColumnWidth(1),
},
children: [
TableRow(children: [
Container(),
Container(TextButton(child: Text('Some title'))),
Container(),
])
],
)),
children: [
Table(
columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(1),
1: FlexColumnWidth(3),
2: FlexColumnWidth(0.5),
},
children: <TableRow>[
TableRow(children: [
Container(),
Container(
child: Row(
children: [
Text('Find me'),
]),
),
Align(),
]),
],
),
],
),
And this is the test I have now:
testWidgets('Get opties text', (WidgetTester tester) async {
await _createWidget(tester);
await tester.pump();
await tester.ensureVisible(find.byType(ExpansionTile));
await tester.tap(find.byType(ExpansionTile));
await tester.pump(Duration(seconds: 15));
await tester.ensureVisible(find.text('Find me')); //This gives me an error
});
Error: The following StateError was thrown running a test: Bad state: No element
Upvotes: 3
Views: 1011
Reputation: 11
What worked for me was simply to add a delay after the tap like in the above link tests https://github.com/flutter/flutter/blob/96f977f4df77f9f8069faa09062f58ba5836a9b5/packages/flutter/test/material/expansion_tile_test.dart#L123
await tester.pump(const Duration(seconds: 1));
Upvotes: 0
Reputation: 39
also try this It's work for me
final icon = find.byIcon(Icons.expand_more).first;
// if you have more then one ExpandablePanel then use .first.
expect(icon, findsOneWidget);
await tester.tap(icon);
Upvotes: 0
Reputation: 19
Hopefully you've already resolved this issue, but if not try tapping on the ExpansionTile's title widget rather than the ExpansionTile itself. You can find by text or by key (if you add a key to the title).
Taken from how the Flutter team test ExpansionTiles:
Upvotes: 1