Flutter系列博文链接 ↓:
工具安装:
Flutter基础篇:
Flutter进阶篇:
Dart语法系列博文链接 ↓:
Dart语法基础篇:
Dart语法进阶篇:
Flutter安装路径:E:/develop/flutter
。
本文所讲到的文件名称为:page_storage.dart
,源码存放在本地的路径为:Flutter安装路径/packages/flutter/lib/src/widgets/page_storage.dart
。
一、PageStorageKey:
PageStorageKey继承自ValueKey,其实就是一个Key,保存状态用的。
PageStorageKey:它是定义PageStorage
的value
将保存在何处的一个ValueKey
。
Scrollable
(实际上是ScrollPosition
)以及它的相关类使用PageStorage
保存滚动偏移量。每次滚动完成时,滚动条的页面存储都会更新。
源码:
class PageStorageKey<T> extends ValueKey<T> {
/// Creates a [ValueKey] that defines where [PageStorage] values will be saved.
const PageStorageKey(T value) : super(value);
}
例如,为了确保在重新创建TabbarView时恢复下面每个MyScrollableTabView中scrollable 的滚动偏移量(scroll offsets),我们指定了pageStorageKey,其值是Tabs的字符串标签。示例代码如下:
new TabBarView(
children: myTabs.map((Tab tab) {
new MyScrollableTabView(
key: new PageStorageKey<String>(tab.text), // like 'Tab 1'
tab: tab,
),
}),
)