forked from xuelongqy/flutter_easy_refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial_footer.dart
146 lines (134 loc) · 4.25 KB
/
material_footer.dart
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
134
135
136
137
138
139
140
141
142
143
144
145
146
import 'package:flutter/material.dart';
import 'src/footer/load_indicator.dart';
import 'src/footer/footer.dart';
/// 质感设计Footer
class MaterialFooter extends Footer {
final Key key;
final double displacement;
/// 颜色
final Animation<Color> valueColor;
/// 背景颜色
final Color backgroundColor;
final LinkFooterNotifier linkNotifier = LinkFooterNotifier();
MaterialFooter({
this.key,
this.displacement = 40.0,
this.valueColor,
this.backgroundColor,
completeDuration = const Duration(seconds: 1),
bool enableHapticFeedback = false,
bool enableInfiniteLoad = true,
}) : super(
float: true,
extent: 52.0,
triggerDistance: 52.0,
completeDuration: completeDuration == null
? Duration(
milliseconds: 300,
)
: completeDuration +
Duration(
milliseconds: 300,
),
enableHapticFeedback: enableHapticFeedback,
enableInfiniteLoad: enableInfiniteLoad,
);
@override
Widget contentBuilder(
BuildContext context,
LoadMode loadState,
double pulledExtent,
double loadTriggerPullDistance,
double loadIndicatorExtent,
AxisDirection axisDirection,
bool float,
Duration completeDuration,
bool enableInfiniteLoad,
bool success,
bool noMore) {
linkNotifier.contentBuilder(
context,
loadState,
pulledExtent,
loadTriggerPullDistance,
loadIndicatorExtent,
axisDirection,
float,
completeDuration,
enableInfiniteLoad,
success,
noMore);
return MaterialFooterWidget(
key: key,
displacement: displacement,
valueColor: valueColor,
backgroundColor: backgroundColor,
linkNotifier: linkNotifier,
);
}
}
/// 质感设计Footer组件
class MaterialFooterWidget extends StatefulWidget {
final double displacement;
// 颜色
final Animation<Color> valueColor;
// 背景颜色
final Color backgroundColor;
final LinkFooterNotifier linkNotifier;
const MaterialFooterWidget({
Key key,
this.displacement,
this.valueColor,
this.backgroundColor,
this.linkNotifier,
}) : super(key: key);
@override
MaterialFooterWidgetState createState() {
return MaterialFooterWidgetState();
}
}
class MaterialFooterWidgetState extends State<MaterialFooterWidget> {
LoadMode get _refreshState => widget.linkNotifier.loadState;
double get _pulledExtent => widget.linkNotifier.pulledExtent;
double get _riggerPullDistance => widget.linkNotifier.loadTriggerPullDistance;
AxisDirection get _axisDirection => widget.linkNotifier.axisDirection;
bool get _noMore => widget.linkNotifier.noMore;
@override
Widget build(BuildContext context) {
if (_noMore) return Container();
// 是否为垂直方向
bool isVertical = _axisDirection == AxisDirection.down ||
_axisDirection == AxisDirection.up;
// 是否反向
bool isReverse = _axisDirection == AxisDirection.up ||
_axisDirection == AxisDirection.left;
// 计算进度值
double indicatorValue = _pulledExtent / _riggerPullDistance;
indicatorValue = indicatorValue < 1.0 ? indicatorValue : 1.0;
return Stack(
children: <Widget>[
Positioned(
top: isVertical ? !isReverse ? 0.0 : null : 0.0,
bottom: isVertical ? isReverse ? 0.0 : null : 0.0,
left: !isVertical ? !isReverse ? 0.0 : null : 0.0,
right: !isVertical ? isReverse ? 0.0 : null : 0.0,
child: Container(
alignment: isVertical
? !isReverse ? Alignment.topCenter : Alignment.bottomCenter
: !isReverse ? Alignment.centerLeft : Alignment.centerRight,
child: RefreshProgressIndicator(
value: _refreshState == LoadMode.armed ||
_refreshState == LoadMode.load ||
_refreshState == LoadMode.loaded ||
_refreshState == LoadMode.done
? null
: indicatorValue,
valueColor: widget.valueColor,
backgroundColor: widget.backgroundColor,
),
),
),
],
);
}
}