Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Conversation

shihaohong
Copy link

@shihaohong shihaohong commented Jan 6, 2021

Turns out state restoration has to be done on the user side of things. In PaginatedDataTables, DataRows are created by the DataTableSource class. This PR adds state restoration to the selection state of the PaginatedDataTable.

Closes flutter/flutter#70916

@@ -17,11 +17,39 @@ class DataTableDemo extends StatefulWidget {
_DataTableDemoState createState() => _DataTableDemoState();
}

class _RestorableSelectedDessertIndices extends RestorableValue<Set<int>> {
Copy link
Member

Choose a reason for hiding this comment

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

This design makes it tempting to just modify the values set directly, which doesn't work because those updates will not be restored.

Instead of exposing the value set directly, I would write a custom RestorableProperty, which does not expose the set and instead has an interface like this:

class Foo extends ... {
  setSelection(Set<int> selectedIndexes);
  isSelected(int index);
}

Copy link
Author

Choose a reason for hiding this comment

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

Done

@shihaohong
Copy link
Author

Ready for another round of review. I also fixed an issue where the selected count of the data table wasn't being restored correctly.

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

@shihaohong shihaohong merged commit cb26c5a into flutter:master Jan 7, 2021
@shihaohong shihaohong deleted the state-restorable-data-table branch January 7, 2021 23:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[State Restoration] DataTable selected index/counts
2 participants