Skip to content

Commit

Permalink
Check if mounted before calling markNeedsBuild()
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Jun 14, 2023
1 parent 606c94c commit d527b51
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/src/reactive_value_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ extension ReactiveValueNotifier<T> on ValueNotifier<T> {
'to schedule the value to update after `build` has completed, use '
'`SchedulerBinding.instance.scheduleTask(updateTask, Priority.idle)` '
'or similar.');
// If the element has not been garbage collected, mark the element
// as needing to be rebuilt
elementRef.target?.markNeedsBuild();
// If the element has not been garbage collected (causing
// `elementRef.target` to be null), or unmounted
if (elementRef.target?.mounted ?? false) {
// Mark the element as needing to be rebuilt
elementRef.target!.markNeedsBuild();
}
// Remove the listener -- only listen to one change per `build`
removeListener(listenerWrapper.listener!);
};
Expand Down

0 comments on commit d527b51

Please sign in to comment.