Update: 2026-06-25 02:28:33
This commit is contained in:
@@ -34,7 +34,7 @@ class SnackbarController {
|
||||
/// The animation controller that the route uses to drive the transitions.
|
||||
///
|
||||
/// The animation itself is exposed by the [animation] property.
|
||||
late final AnimationController _controller;
|
||||
AnimationController? _controller;
|
||||
|
||||
SnackbarStatus? _currentStatus;
|
||||
|
||||
@@ -88,7 +88,9 @@ class SnackbarController {
|
||||
}
|
||||
|
||||
void _configureOverlay() {
|
||||
_overlayState = Overlay.of(Get.overlayContext!);
|
||||
final ctx = Get.overlayContext;
|
||||
if (ctx == null) return;
|
||||
_overlayState = Overlay.of(ctx);
|
||||
_overlayEntries.clear();
|
||||
_overlayEntries.addAll(_createOverlayEntries(_getBodyWidget()));
|
||||
_overlayState!.insertAll(_overlayEntries);
|
||||
@@ -96,8 +98,7 @@ class SnackbarController {
|
||||
}
|
||||
|
||||
void _configureSnackBarDisplay() {
|
||||
assert(!_transitionCompleter.isCompleted,
|
||||
'Cannot configure a snackbar after disposing it.');
|
||||
if (_transitionCompleter.isCompleted) return;
|
||||
_controller = _createAnimationController();
|
||||
_configureAlignment(snackbar.snackPosition);
|
||||
_snackbarStatus = snackbar.snackbarStatus;
|
||||
@@ -106,7 +107,7 @@ class SnackbarController {
|
||||
_animation = _createAnimation();
|
||||
_animation.addStatusListener(_handleStatusChanged);
|
||||
_configureTimer();
|
||||
_controller.forward();
|
||||
_controller?.forward();
|
||||
}
|
||||
|
||||
void _configureTimer() {
|
||||
@@ -126,11 +127,15 @@ class SnackbarController {
|
||||
/// the transition controlled by the animation controller created by
|
||||
/// `createAnimationController()`.
|
||||
Animation<Alignment> _createAnimation() {
|
||||
assert(!_transitionCompleter.isCompleted,
|
||||
'Cannot create a animation from a disposed snackbar');
|
||||
final ctrl = _controller;
|
||||
if (ctrl == null) {
|
||||
return AlignmentTween(begin: _initialAlignment, end: _endAlignment).animate(
|
||||
kAlwaysCompleteAnimation,
|
||||
);
|
||||
}
|
||||
return AlignmentTween(begin: _initialAlignment, end: _endAlignment).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
parent: ctrl,
|
||||
curve: snackbar.forwardAnimationCurve,
|
||||
reverseCurve: snackbar.reverseAnimationCurve,
|
||||
),
|
||||
@@ -152,9 +157,10 @@ class SnackbarController {
|
||||
}
|
||||
|
||||
Animation<double> _createBlurFilterAnimation() {
|
||||
final ctrl = _controller!;
|
||||
return Tween(begin: 0.0, end: snackbar.overlayBlur).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
parent: ctrl,
|
||||
curve: const Interval(
|
||||
0.0,
|
||||
0.35,
|
||||
@@ -165,11 +171,12 @@ class SnackbarController {
|
||||
}
|
||||
|
||||
Animation<Color?> _createColorOverlayColor() {
|
||||
final ctrl = _controller!;
|
||||
return ColorTween(
|
||||
begin: const Color(0x00000000), end: snackbar.overlayColor)
|
||||
.animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
parent: ctrl,
|
||||
curve: const Interval(
|
||||
0.0,
|
||||
0.35,
|
||||
@@ -300,18 +307,21 @@ class SnackbarController {
|
||||
}
|
||||
|
||||
void _removeEntry() {
|
||||
assert(
|
||||
!_transitionCompleter.isCompleted,
|
||||
'Cannot remove entry from a disposed snackbar',
|
||||
);
|
||||
if (_transitionCompleter.isCompleted) return;
|
||||
|
||||
_cancelTimer();
|
||||
|
||||
final ctrl = _controller;
|
||||
if (ctrl == null) {
|
||||
_removeOverlay();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_wasDismissedBySwipe) {
|
||||
Timer(const Duration(milliseconds: 200), _controller.reset);
|
||||
Timer(const Duration(milliseconds: 200), ctrl.reset);
|
||||
_wasDismissedBySwipe = false;
|
||||
} else {
|
||||
_controller.reverse();
|
||||
ctrl.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,11 +330,13 @@ class SnackbarController {
|
||||
element.remove();
|
||||
}
|
||||
|
||||
assert(!_transitionCompleter.isCompleted,
|
||||
'Cannot remove overlay from a disposed snackbar');
|
||||
_controller.dispose();
|
||||
if (_controller != null) {
|
||||
_controller!.dispose();
|
||||
}
|
||||
_overlayEntries.clear();
|
||||
_transitionCompleter.complete();
|
||||
if (!_transitionCompleter.isCompleted) {
|
||||
_transitionCompleter.complete();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _show() {
|
||||
@@ -332,6 +344,8 @@ class SnackbarController {
|
||||
return future;
|
||||
}
|
||||
|
||||
bool get _isConfigured => _controller != null;
|
||||
|
||||
static void cancelAllSnackbars() {
|
||||
_snackBarQueue._cancelAllJobs();
|
||||
}
|
||||
@@ -366,7 +380,8 @@ class _SnackBarQueue {
|
||||
}
|
||||
|
||||
Future<void> _closeCurrentJob() async {
|
||||
if (_currentSnackbar == null) return;
|
||||
await _currentSnackbar!.close();
|
||||
final current = _currentSnackbar;
|
||||
if (current == null || !current._isConfigured) return;
|
||||
await current.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user