animated-stream-list
animated-stream-list copied to clipboard
DiffUtil.eq always null in isolate
While trying to use the animated stream list package in my project, I am finding that DiffUtil.eq
is always null inside the _myersDiff
method, which is called in a separate isolate. This results in undesired behavior, such as animating out the wrong list item on the UI when removing an item.
Before spawning the isolate, DiffUtil.eq
is correctly set to the function I pass to AnimatedStreamList
for the equals
parameter. Inside the spawned isolate, DiffUtil.eq
is null, meaning _myersDiff
defaults to using (a, b) => a == b
for comparison.
From my (minimal) knowledge of isolates, I think this is the expected behavior when spawning an isolate since the isolate does not share memory with the main thread.
Here are a few thoughts I've had on ways to resolve this issue:
-
Pass the equality function to
_myersDiff
in the spawned isolate arguments. I think this might be the best option, but I know there are some important semantics that need to be considered when passing arguments to an isolate, as mentioned in #5 by @JulianAssmann. -
Schedule
_myersDiff
to run as a microtask instead of a separate isolate, as mentioned in #4 by @feedrdev. I think this would be a pretty simple and easy solution to the problem and would work fine for reasonably sized lists. -
Require the user to override the
==
operator in the class for which the stream passed toAnimatedStreamList
emits. I think this is unnecessarily intrusive to the user and probably the least ideal option.
I'm happy to implement any of these solutions and create a pull request, but was hoping to get some consensus first.