-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollControllerAbout.dart
More file actions
133 lines (130 loc) · 5.75 KB
/
ScrollControllerAbout.dart
File metadata and controls
133 lines (130 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import 'package:flutter/material.dart';
import 'package:flutter_starter_notes/component/CommonTitle.dart';
import 'package:flutter_starter_notes/ui/scrollcontroller/NotificationListener-demo.dart';
import 'package:flutter_starter_notes/ui/scrollcontroller/ScrollController-listener.dart';
class ScrollControllerAbout extends StatelessWidget {
ScrollControllerAbout({Key key, this.title});
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
CommonTitle('ScrollController 介绍'),
Container(
color: Colors.grey[300],
alignment: Alignment.centerLeft,
padding: EdgeInsets.fromLTRB(16, 16, 16, 0),
child: Text("""ScrollController({
double initialScrollOffset = 0.0, //初始滚动位置
this.keepScrollOffset = true,//是否保存滚动位置
...
})
"""),
),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16),
child: Text("""ScrollController常用的属性和方法:
1. offset:可滚动Widget当前滚动的位置。
2. jumpTo(double offset)、animateTo(double offset,...):这两个方法用于跳转到指定的位置,它们不同之处在于,后者在跳转时会执行一个动画,而前者不会。"""),
),
CommonTitle('ScrollController 设置监听'),
Container(
color: Colors.grey[300],
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16),
child: Text(
"""controller.addListener(()=>print(controller.offset))"""),
),
CommonTitle('滚动位置恢复'),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16),
child: Text(
"""PageStorage是一个用于保存页面(路由)相关数据的Widget,它并不会影响子树的UI外观,其实,PageStorage是一个功能型Widget,它拥有一个存储桶(bucket),子树中的Widget可以通过指定不同的PageStorageKey来存储各自的数据或状态"""),
),
CommonTitle('ScrollController 示例'),
InkWell(
onTap: () => {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => ScrollControllerListener(
title: "Listener 使用示例")))
},
child: Container(
height: 60,
padding: EdgeInsets.only(left: 10),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Expanded(
child: Text('Listener 使用示例'),
flex: 1,
),
new Icon(Icons.keyboard_arrow_right)
],
),
),
),
),
Divider(
height: 1,
),
CommonTitle('滚动监听 NotificationListener 介绍和示例'),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16),
child: Text(
"""NotificationListener 是一个 Widget,模板参数T是想监听的通知类型,如果省略,则所有类型通知都会被监听,如果指定特定类型,则只有该类型的通知会被监听。NotificationListener需要一个onNotification回调函数,用于实现监听处理逻辑,该回调可以返回一个布尔值,代表是否阻止该事件继续向上冒泡,如果为true时,则冒泡终止,事件停止向上传播,如果不返回或者返回值为false 时,则冒泡继续。"""),
),
CommonTitle('NotificationListener 与 ScrollController 比较'),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16),
child: Text(
"""1. 通过NotificationListener可以在从Scrollable Widget到Widget树根之间任意位置都能监听。而ScrollController只能和具体的Scrollable Widget关联后才可以。\n2. 收到滚动事件后获得的信息不同;NotificationListener在收到滚动事件时,通知中会携带当前滚动位置和ViewPort的一些信息,而ScrollController只能获取当前滚动位置。"""),
),
Divider(
height: 1,
),
InkWell(
onTap: () => {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => NotificationListenerDemo(
title: "NotificationListener 使用示例")))
},
child: Container(
height: 60,
padding: EdgeInsets.only(left: 10),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Expanded(
child: Text('NotificationListener 使用示例'),
flex: 1,
),
new Icon(Icons.keyboard_arrow_right)
],
),
),
),
),
Divider(
height: 1,
),
],
),
),
);
}
}