How to find TableRow in a flutter test

0 votes

I am having issues with finding table rows when testing using Flutter. It is able to find the table, and when printing the tableWidget, it does show that the table has contents, with the keys that I am searching for, thus I am confused as to why the tester is not able to find them.

await buildApp(tester);
await tester.pump(const Duration(seconds: 1));
var table = find.byKey(const Key('Tablebase'));
expect(table, findsOneWidget);

var tableWidget = table.evaluate().single.widget as Table;
print(tableWidget.children);

expect(find.byType(TableRow), findsOneWidget);
expect(find.byKey(const ValueKey('row-0')), findsOneWidget);

The print statement gives the following (trimmed down to remove containers):
[TableRow([<'row-0'>],

Apr 4, 2023 in Flutter by Ashwini
• 5,430 points
932 views

1 answer to this question.

0 votes

Based on the code you provided, it seems like you are correctly finding the table and its children using the find.byKey method and the Table widget. However, in your assertion, you are searching for a TableRow widget using find.byType(TableRow) and a ValueKey using find.byKey(const ValueKey('row-0')).

It's possible that the TableRow widgets are not directly children of the Table widget, but are instead nested inside other widgets such as Container, Expanded, or TableCell. In this case, you may need to modify your test code to search for these nested widgets to find the TableRow.

For example, you could try searching for Container widgets that contain the TableRow widgets, like this:

expect(find.byType(Container).evaluate().where((widget) {
  return widget.child is TableRow;
}), findsWidgets);

This code will find all Container widgets that contain a TableRow widget, which should include the TableRow widgets that you are looking for.

answered Apr 4, 2023 by pooja

Related Questions In Flutter

0 votes
1 answer

How to change Android minSdkVersion in Flutter Project?

Yes, you can change the minSdkVersion in ...READ MORE

answered Mar 21, 2023 in Flutter by Tej
11,085 views
0 votes
1 answer

How to implement drop down list in flutter?

You're close! The error you're getting is ...READ MORE

answered Mar 26, 2023 in Flutter by vishalini
4,085 views
0 votes
1 answer

How to dynamically resize text in Flutter?

You can use the FittedBox widget to ...READ MORE

answered Mar 27, 2023 in Flutter by Tej
8,927 views
0 votes
1 answer

What is the future of flutter?

Hi@MD, Flutter is a rather new cross-platform framework ...READ MORE

answered Jul 17, 2020 in Others by akhtar
• 38,260 points
1,147 views
0 votes
1 answer

What is Flutter?

Hi@akhtar, Flutter is an app SDK for building ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
1,450 views
0 votes
1 answer

How to install Flutter in Windows system?

Hi@akhtar, You can follow the below-given steps to ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
1,781 views
0 votes
2 answers

How to create a circle icon button in Flutter?

To create something similar to a FloatingActionButton, ...READ MORE

answered Aug 23, 2023 in Flutter by anonymous
• 140 points
14,354 views
0 votes
1 answer

How to Deserialize a list of objects from json in flutter Ask Question?

To deserialize a list of objects from ...READ MORE

answered Mar 28, 2023 in Flutter by vishalini
2,281 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP