我试图在PaginatedDataTable中调用SetState()。显然,如果小部件未嵌套在BottomNavigationBar内,则此方法有效,但是当我将其放入BottomNavigationBar内时,SetState()中设置的值在切换选项卡之前不会刷新,是否有一种方法可以在不切换选项卡的情况下工作?
Widget paginatedDataTableWidget(ItemDataSource _itemDataSource) {
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
verticalDirection: VerticalDirection.down,
children: <Widget>[
PaginatedDataTable(
header: const Text('Item List'),
rowsPerPage: _rowsPerPage,
sortColumnIndex: _sortColumnIndex,
sortAscending: _sortAscending,
onSelectAll: _itemDataSource._selectAll,
columnSpacing: 8,
onRowsPerPageChanged: (int value) {
setState(() {
_rowsPerPage = value;
});
},
...
body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
selectedItemColor: Colors.teal,
items: [
BottomNavigationBarItem(
title: Text("Home"),
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
title: Text("Account"),
icon: Icon(Icons.account_circle),
),
],
onTap: _onItemTapped,
),
paginatedDataTable嵌套在以下小部件选项中:
_widgetOptions = <Widget>[showDataTable(), showAccountInfo()];
showDataTable()包含一个futureBuilder,当数据加载时,该FutureBuilder返回paginatedDataTableWidget()。
在调用onRowsPerPageChanged()时,它不会刷新页面,直到我切换到另一个选项卡并返回到主页选项卡,有没有一种方法可以将其从BottomNavigationBar中取出来?
非常感谢您的帮助