Skip to content

Conversation

@Piinks
Copy link
Contributor

@Piinks Piinks commented Mar 27, 2024

Fixes flutter/flutter#131226

This adds support for infinite rows and columns in TableView.
When using a TableCellBuilderDelegate or the TableView.builder constructor, the row and column counts are no longer required. Omitting them will result in an infinite number or rows and/or columns.

When the row and column count are finite, the layout of the table is eagerly computed, while the children are actually laid out lazily. In the infinite TableView world, both the layout computation and the layout of children is lazy. The metrics for the table will only be computed for what is visible or in the cache extent, and will update the metrics as needed.

Similar to widgets like ListView, there is an option to null terminate the number of rows or columns in the table. The table's rows and/or columns will be infinite in number unless the rowBuilder or columnBuilder returns null, signifying the end. The ScrollPosition will reflect a maxScrollExtent of double.infinity unless the null terminating row or column has been reached, similar to other infinite-until-null-terminated widgets like ListView.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@Piinks Piinks added the p: two_dimensional_scrollables Issues pertaining to the two_dimensional_scrollables package label Mar 27, 2024
@Piinks Piinks requested a review from goderbauer March 27, 2024 18:11
Comment on lines 173 to 176
return switch (maxXIndex) {
null => maxXIndex,
_ => maxXIndex! + 1,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch statements are cool and all, but IMO this could be more clearly expressed as:

Suggested change
return switch (maxXIndex) {
null => maxXIndex,
_ => maxXIndex! + 1,
};
return maxXIndex == null ? null : maxXIndex! + 1;

(here and elsewhere where this pattern is used)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I may have gotten carried away here. 😜

),
);
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of test cases here, so maybe I missed it: Do you have a test case where it changes at what index columnBuilder/rowBuilder returns null? Let's say initially, columnBuilder/rowBuilder return null it index 10. Is it properly handled if later two rows are added and they now return null at index 12? Same if two rows are removed and they now return null at index 8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh excellent test cases!! I will add these. I suspect I do not handle this well currently... I'll check and see how ListView does this. I have an idea, but this problem is already solved there. 🙃

int? _lastNonPinnedRow;
int? _lastNonPinnedColumn;

int? _columnNullTerminated;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my own understanding (and maybe to clarify in the name): This is the index at which the columns are null terminated, right? The current name made it sound like this should be a boolean indicating whether the column builder has returned null yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct! I am changing the name to indicate this better. Funny you imagined a bool - at one point it was!

_lastNonPinnedColumn = null;
double startOfRegularColumn = 0;
double startOfPinnedColumn = 0;
// Updates the cached column metrics for the table.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help future readers: maybe document the meaning of the arguments to this method here since they are not immediately clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@Piinks
Copy link
Contributor Author

Piinks commented Mar 29, 2024

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// No columns laid out after column 5.
expect(find.text('R0:C5'), findsNothing);
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these additional test cases!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a great catch! Thank you!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 1, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: two_dimensional_scrollables Issues pertaining to the two_dimensional_scrollables package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TableView follow up: Infinite rows and columns

2 participants