Skip to content

Commit 6e4cf7e

Browse files
author
LiWenjie
committed
Change the future.delay to Timer implementation, and make the ToastFuture.dismiss method eliminate the memory leak caused by future.delay not being executed.
把Future.delay改成Timer实现,使ToastFuture.dismiss方法可以消除Future.delay未被执行造成的内存泄漏。
1 parent 64f0b0e commit 6e4cf7e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/src/core/toast.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ ToastFuture showToastWidget(
147147

148148
future = ToastFuture._(entry, onDismiss, key, animationDuration);
149149

150-
Future.delayed(duration, () {
150+
future.timer = Timer(duration, (){
151151
future.dismiss();
152152
});
153153

lib/src/core/toast_future.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class ToastFuture {
55
final OverlayEntry _entry;
66
final VoidCallback _onDismiss;
77
bool _isShow = true;
8+
Timer timer;
89
final GlobalKey<__ToastContainerState> _containerKey;
910
final Duration animationDuration;
1011

@@ -31,5 +32,8 @@ class ToastFuture {
3132
} else {
3233
_entry.remove();
3334
}
35+
36+
timer?.cancel();
37+
timer = null;
3438
}
3539
}

0 commit comments

Comments
 (0)