繁体   English   中英

Flutter:PaginatedDataTable 没有 go 在行数改变后回到第一页

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM