Skip to content

Commit

Permalink
fix: #62
Browse files Browse the repository at this point in the history
  • Loading branch information
LinXunFeng committed Nov 15, 2023
1 parent f90ab90 commit d14fab2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/src/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ class GridViewOnceObserveNotification
/// Sequence:
/// [ObserverScrollStartNotification] -> [ObserverScrollDecisionNotification]
/// -> [ObserverScrollEndNotification].
class ObserverScrollNotification extends Notification {}
class ObserverScrollNotification extends Notification {
@override
void dispatch(BuildContext? target) {
bool isMounted = target?.mounted ?? false;
if (!isMounted) {
return;
}
super.dispatch(target);
}
}

/// A notification that a scrolling task has started due to calling the jumpTo
/// or animateTo method of [ObserverController].
Expand Down
4 changes: 4 additions & 0 deletions lib/src/utils/src/observer_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ class ObserverUtils {

/// Safely call findRenderObject method.
static RenderObject? findRenderObject(BuildContext? context) {
bool isMounted = context?.mounted ?? false;
if (!isMounted) {
return null;
}
try {
// It throws an exception when getting renderObject of inactive element.
return context?.findRenderObject();
Expand Down

0 comments on commit d14fab2

Please sign in to comment.