From 73c3ad51d320fe2d94e74b1a95fbf2e3614cf766 Mon Sep 17 00:00:00 2001 From: Luke Hutchison Date: Fri, 21 Jul 2023 13:19:51 -0600 Subject: [PATCH] Code cleanups (no functional changes) --- lib/src/reactive_value_notifier.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/reactive_value_notifier.dart b/lib/src/reactive_value_notifier.dart index c6d1b9f..7846f03 100644 --- a/lib/src/reactive_value_notifier.dart +++ b/lib/src/reactive_value_notifier.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -class _ListenerWrapper { +// Can't refer to listener while it is being declared, so we need this class +// to add a layer of indirection. +class _ListenerWrapper { void Function()? listener; } @@ -13,17 +15,16 @@ extension ReactiveValueNotifier on ValueNotifier { /// value. T reactiveValue(BuildContext context) { final elementRef = WeakReference(context as Element); - // Can't refer to listener while it is being declared, so need to add - // a layer of indirection. - final listenerWrapper = _ListenerWrapper(); + final listenerWrapper = _ListenerWrapper(); listenerWrapper.listener = () { assert( SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks, 'Do not mutate state (by setting the value of the ValueNotifier ' 'that you are subscribed to) during a `build` method. If you need ' - 'to schedule the value to update after `build` has completed, use ' - '`SchedulerBinding.instance.scheduleTask(updateTask, Priority.idle)` ' + 'to schedule a value update after `build` has completed, use ' + '`SchedulerBinding.instance.scheduleTask(updateTask, Priority.idle)`, ' + '`SchedulerBinding.addPostFrameCallback(updateTask)`, ' 'or similar.'); // If the element has not been garbage collected (causing // `elementRef.target` to be null), or unmounted