dart - 我正在使用 BottomNavigationBar 导航到 diff SliverList。我观察到它不会保留到我滚动的最后一行。我怎样才能解决这个问题?
问题描述
class _HomeState extends State<Home> {
int _currentIndex = 0;
final List<Widget> _children = [Profile(), ServiceRequestList()];
void _onTap(int index) {
setState(() {
_currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
onTap: _onTap,
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
title: Text('Profile'),
),
BottomNavigationBarItem(
icon: Icon(Icons.assignment),
title: Text('Service'),
),
],
));
}
}
我正在使用 BottomNavigationBar 导航到 diff SliverList。我观察到它不会保留到我滚动的最后一行。如何解决这个问题?
解决方案
PageStorageKey 就是您要找的东西!
在 Profile 页面和 ServiceRequestList 页面的 SliverList 小部件中,设置一个唯一的页面存储键,如下所示:
SliverList(
key: PageStorageKey("somethingUnique"),
)
PageStorageKey 适用于任何具有滚动区域的小部件。
推荐阅读
- r - 在 R 中创建一个函数以返回一个向量
- python-3.x - 使用 memoization 实现嵌套回溯功能 - Python3
- python - 无法对 GetKeys 进行心理测试
- python - 使用pandas,如何批量计算csv数据的平均值?
- google-apps-script - 如何在回答上一个问题谷歌脚本时弹出一个问题
- python - 我如何使用 for 循环来使这更简单?
- python - 是否可以在特定区域的屏幕上定位?
- java - javaws 堆空间错误 (OutOfMemoryError)
- wso2 - 服务商列表看不到
- types - 是否有一种类型定义语言旨在翻译语言之间的类型?