Skip to content

Commit 2ac2e30

Browse files
authored
fix: Manually dispose memory leak objects (#709)
1 parent d7bbe03 commit 2ac2e30

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,9 @@ class DefaultAssetPickerBuilderDelegate
937937
/// Whether the bottom actions bar should display.
938938
bool get hasBottomActions => isPreviewEnabled || !isSingleAssetMode;
939939

940+
/// The tap gesture recognizer for present limited assets.
941+
TapGestureRecognizer? presentLimitedTapGestureRecognizer;
942+
940943
/// The listener to track the scroll position of the [gridScrollController]
941944
/// if [keepScrollOffset] is true.
942945
/// 当 [keepScrollOffset] 为 true 时,跟踪 [gridScrollController] 位置的监听。
@@ -946,6 +949,13 @@ class DefaultAssetPickerBuilderDelegate
946949
}
947950
}
948951

952+
@override
953+
void initState(AssetPickerState<AssetEntity, AssetPathEntity> state) {
954+
super.initState(state);
955+
presentLimitedTapGestureRecognizer = TapGestureRecognizer()
956+
..onTap = PhotoManager.presentLimited;
957+
}
958+
949959
/// Be aware that the method will do nothing when [keepScrollOffset] is true.
950960
/// 注意当 [keepScrollOffset] 为 true 时方法不会进行释放。
951961
@override
@@ -955,6 +965,7 @@ class DefaultAssetPickerBuilderDelegate
955965
return;
956966
}
957967
provider.dispose();
968+
presentLimitedTapGestureRecognizer?.dispose();
958969
super.dispose();
959970
}
960971

@@ -2032,8 +2043,7 @@ class DefaultAssetPickerBuilderDelegate
20322043
text: ' '
20332044
'${textDelegate.changeAccessibleLimitedAssets}',
20342045
style: TextStyle(color: interactiveTextColor(context)),
2035-
recognizer: TapGestureRecognizer()
2036-
..onTap = PhotoManager.presentLimited,
2046+
recognizer: presentLimitedTapGestureRecognizer,
20372047
),
20382048
],
20392049
),

lib/src/widget/asset_picker_page_route.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ class AssetPickerPageRoute<T> extends PageRoute<T> {
4545

4646
final bool Function(TransitionRoute<dynamic>)? canTransitionFromPredicate;
4747

48+
/// The curved animation.
49+
CurvedAnimation? _curvedAnimation;
50+
51+
@override
52+
void dispose() {
53+
_curvedAnimation?.dispose();
54+
super.dispose();
55+
}
56+
4857
@override
4958
bool canTransitionFrom(TransitionRoute<dynamic> previousRoute) =>
5059
canTransitionFromPredicate?.call(previousRoute) ?? false;
@@ -65,12 +74,14 @@ class AssetPickerPageRoute<T> extends PageRoute<T> {
6574
Animation<double> secondaryAnimation,
6675
Widget child,
6776
) {
77+
_curvedAnimation ??=
78+
CurvedAnimation(curve: transitionCurve, parent: animation);
6879
return SlideTransition(
6980
position: Tween<Offset>(
7081
begin: const Offset(0, 1),
7182
end: Offset.zero,
7283
).animate(
73-
CurvedAnimation(curve: transitionCurve, parent: animation),
84+
_curvedAnimation!,
7485
),
7586
child: ClipRect(child: child), // Clip the overflowed part.
7687
);

lib/src/widget/builder/image_page_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class _LivePhotoWidgetState extends State<_LivePhotoWidget> {
200200
_scrollNotificationObserver?.removeListener(_handleScrollNotification);
201201
_controller.pause();
202202
_controller.removeListener(_notify);
203+
_showVideo.dispose();
203204
super.dispose();
204205
}
205206

lib/src/widget/builder/video_page_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class _VideoPageBuilderState extends State<VideoPageBuilder> {
9090
?..removeListener(videoPlayerListener)
9191
..pause()
9292
..dispose();
93+
isPlaying.dispose();
9394
super.dispose();
9495
}
9596

0 commit comments

Comments
 (0)