@@ -72,6 +72,28 @@ abstract class AssetPickerViewerBuilderDelegate<Asset, Path> {
72
72
/// 用于动画的 [TickerProvider]
73
73
late final TickerProvider vsync;
74
74
75
+ /// [AnimationController] for double tap animation.
76
+ /// 双击缩放的动画控制器
77
+ late final AnimationController doubleTapAnimationController;
78
+
79
+ /// [CurvedAnimation] for double tap.
80
+ /// 双击缩放的动画曲线
81
+ late final Animation <double > doubleTapCurveAnimation;
82
+
83
+ /// [Animation] for double tap.
84
+ /// 双击缩放的动画
85
+ Animation <double >? doubleTapAnimation;
86
+
87
+ /// Callback for double tap.
88
+ /// 双击缩放的回调
89
+ late VoidCallback doubleTapListener;
90
+
91
+ /// [PageController] for assets preview [PageView] .
92
+ /// 查看图片资源的页面控制器
93
+ late final PageController pageController = PageController (
94
+ initialPage: currentIndex,
95
+ );
96
+
75
97
/// Current previewing index in assets.
76
98
/// 当前查看的索引
77
99
int currentIndex;
@@ -110,21 +132,55 @@ abstract class AssetPickerViewerBuilderDelegate<Asset, Path> {
110
132
) {
111
133
viewerState = s;
112
134
vsync = v;
135
+ doubleTapAnimationController = AnimationController (
136
+ duration: const Duration (milliseconds: 200 ),
137
+ vsync: v,
138
+ );
139
+ doubleTapCurveAnimation = CurvedAnimation (
140
+ parent: doubleTapAnimationController,
141
+ curve: Curves .easeInOut,
142
+ );
113
143
}
114
144
115
145
/// Keep a dispose method to sync with [State] .
116
146
/// 保留一个 dispose 方法与 [State] 同步。
117
147
void dispose () {
118
148
provider? .dispose ();
149
+ pageController.dispose ();
119
150
pageStreamController.close ();
120
151
previewingListController.dispose ();
121
152
selectedNotifier.dispose ();
122
153
isDisplayingDetail.dispose ();
154
+ doubleTapAnimationController
155
+ ..stop ()
156
+ ..reset ()
157
+ ..dispose ();
123
158
}
124
159
125
160
/// Execute scale animation when double tap.
126
161
/// 双击时执行缩放动画
127
- void updateAnimation (ExtendedImageGestureState state);
162
+ void updateAnimation (ExtendedImageGestureState state) {
163
+ final double begin = state.gestureDetails! .totalScale! ;
164
+ final double end = state.gestureDetails! .totalScale! == 1.0 ? 3.0 : 1.0 ;
165
+ final Offset pointerDownPosition = state.pointerDownPosition! ;
166
+
167
+ doubleTapAnimation? .removeListener (doubleTapListener);
168
+ doubleTapAnimationController
169
+ ..stop ()
170
+ ..reset ();
171
+ doubleTapListener = () {
172
+ state.handleDoubleTap (
173
+ scale: doubleTapAnimation! .value,
174
+ doubleTapPosition: pointerDownPosition,
175
+ );
176
+ };
177
+ doubleTapAnimation = Tween <double >(
178
+ begin: begin,
179
+ end: end,
180
+ ).animate (doubleTapCurveAnimation)
181
+ ..addListener (doubleTapListener);
182
+ doubleTapAnimationController.forward ();
183
+ }
128
184
129
185
/// The length getter for selected assets currently.
130
186
/// 当前选中的资源的长度获取
@@ -273,27 +329,6 @@ class DefaultAssetPickerViewerBuilderDelegate
273
329
/// 如果类型不为空,则标题将不会显示。
274
330
final SpecialPickerType ? specialPickerType;
275
331
276
- /// [AnimationController] for double tap animation.
277
- /// 双击缩放的动画控制器
278
- late final AnimationController _doubleTapAnimationController;
279
-
280
- /// [CurvedAnimation] for double tap.
281
- /// 双击缩放的动画曲线
282
- late final Animation <double > _doubleTapCurveAnimation;
283
-
284
- /// [Animation] for double tap.
285
- /// 双击缩放的动画
286
- Animation <double >? _doubleTapAnimation;
287
-
288
- /// Callback for double tap.
289
- /// 双击缩放的回调
290
- late VoidCallback _doubleTapListener;
291
-
292
- /// [PageController] for assets preview [PageView] .
293
- /// 查看图片资源的页面控制器
294
- late final PageController pageController =
295
- PageController (initialPage: currentIndex);
296
-
297
332
/// Whether the [SpecialPickerType.wechatMoment] is enabled.
298
333
/// 当前是否为微信朋友圈选择模式
299
334
bool get isWeChatMoment =>
@@ -306,53 +341,6 @@ class DefaultAssetPickerViewerBuilderDelegate
306
341
(selectedAssets? .any ((AssetEntity e) => e.type == AssetType .video) ??
307
342
false );
308
343
309
- @override
310
- void initStateAndTicker (
311
- AssetPickerViewerState <AssetEntity , AssetPathEntity > s,
312
- TickerProvider v,
313
- ) {
314
- super .initStateAndTicker (s, v);
315
- _doubleTapAnimationController = AnimationController (
316
- duration: const Duration (milliseconds: 200 ),
317
- vsync: v,
318
- );
319
- _doubleTapCurveAnimation = CurvedAnimation (
320
- parent: _doubleTapAnimationController,
321
- curve: Curves .easeInOut,
322
- );
323
- }
324
-
325
- @override
326
- void dispose () {
327
- _doubleTapAnimationController.dispose ();
328
- pageController.dispose ();
329
- super .dispose ();
330
- }
331
-
332
- @override
333
- void updateAnimation (ExtendedImageGestureState state) {
334
- final double begin = state.gestureDetails! .totalScale! ;
335
- final double end = state.gestureDetails! .totalScale! == 1.0 ? 3.0 : 1.0 ;
336
- final Offset pointerDownPosition = state.pointerDownPosition! ;
337
-
338
- _doubleTapAnimation? .removeListener (_doubleTapListener);
339
- _doubleTapAnimationController
340
- ..stop ()
341
- ..reset ();
342
- _doubleTapListener = () {
343
- state.handleDoubleTap (
344
- scale: _doubleTapAnimation! .value,
345
- doubleTapPosition: pointerDownPosition,
346
- );
347
- };
348
- _doubleTapAnimation = Tween <double >(
349
- begin: begin,
350
- end: end,
351
- ).animate (_doubleTapCurveAnimation)
352
- ..addListener (_doubleTapListener);
353
- _doubleTapAnimationController.forward ();
354
- }
355
-
356
344
@override
357
345
Widget assetPageBuilder (BuildContext context, int index) {
358
346
final AssetEntity asset = previewAssets.elementAt (index);
0 commit comments