![](/img/trans.png)
[英]Flutter Isolate doesn't go do setState after navigate to a other page and back
[英]Flutter: PaginatedDataTable doesn't go back to the first page after the number of rows changed
我在我的 web 應用程序中使用 PaginatedDataTable,應用程序用戶可以通過提供關鍵字來搜索行。
問題是:在搜索和調用setstate后,在搜索PaginatedDataTable是否在第二、第三頁或其他頁面而不是第一頁之前,我必須go到第一頁查看output,非常不方便。
有什么辦法可以讓 PaginatedDataTable 到 go 成為行數改變后的第一頁?
通過將唯一的Key
傳遞給PaginatedDataTable
實例,我終於能夠解決這個問題。
class MyDataTable extends StatelessWidget {
const MyDataTable({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return InteractiveViewer(
child: PaginatedDataTable(
key: key,
columns: getColumnHeadersForOwners(),
source: getDataSource(),
header: Container(),
rowsPerPage: 4,
),
);
}
}
在您調用此 class 的根 Widget 中:
...
...
child: MyDataTable(key: UniqueKey())
...
我建議您查看Flutter 的簡短視頻,該視頻解釋了我們為什么使用Key
s,如果您不熟悉它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.