animated-stream-list
animated-stream-list copied to clipboard
Isolate spawning fails
I have the following issue:
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Invalid argument(s): Illegal argument in isolate message : (object is a closure - Function '<anonymous closure>':.)
E/flutter (19379): #0 Isolate._spawnFunction (dart:isolate-patch/isolate_patch.dart:549:55)
E/flutter (19379): #1 Isolate.spawn (dart:isolate-patch/isolate_patch.dart:389:7)
E/flutter (19379): <asynchronous suspension>
E/flutter (19379): #2 compute (package:flutter/src/foundation/_isolates_io.dart:23:41)
E/flutter (19379): <asynchronous suspension>
E/flutter (19379): #3 DiffUtil.calculateDiff (package:animated_stream_list/src/myers_diff.dart:14:19)
E/flutter (19379): #4 _AnimatedStreamListState.startListening.<anonymous closure> (package:animated_stream_list/src/animated_stream_list.dart:55:12)
E/flutter (19379): #5 Stream.asyncExpand.onListen.<anonymous closure> (dart:async/stream.dart:572:30)
E/flutter (19379): #6 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (19379): #7 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (19379): #8 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (19379): #9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (19379): #10 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
E/flutter (19379): #11 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
E/flutter (19379): #12 _MapStream._handleData (dart:async/stream_pipe.dart:232:10)
E/flutter (19379): #13 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
E/flutter (19379): #14 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (19379): #15 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (19379): #16 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (19379): #17 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (19379): #18 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter (19379): #19 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
E/flutter (19379): #20 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
E/flutter (19379): #21 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (19379): #22 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (19379): #23 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (19379): #24 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter (19379): #25 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (19379): #26 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (19379): #27 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (19379): #28 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter (19379): #29 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (19379): #30 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter (19379):
Performing hot restart...
Restarted application in 2,207ms.
I/flutter (19379): Navigation model initilaized
I/flutter (19379): new state
E/flutter (19379): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Invalid argument(s): Illegal argument in isolate message : (object is a closure - Function '<anonymous closure>':.)
E/flutter (19379): #0 Isolate._spawnFunction (dart:isolate-patch/isolate_patch.dart:549:55)
E/flutter (19379): #1 Isolate.spawn (dart:isolate-patch/isolate_patch.dart:389:7)
E/flutter (19379): <asynchronous suspension>
E/flutter (19379): #2 compute (package:flutter/src/foundation/_isolates_io.dart:23:41)
E/flutter (19379): <asynchronous suspension>
E/flutter (19379): #3 DiffUtil.calculateDiff (package:animated_stream_list/src/myers_diff.dart:14:19)
E/flutter (19379): #4 _AnimatedStreamListState.startListening.<anonymous closure> (package:animated_stream_list/src/animated_stream_list.dart:55:12)
E/flutter (19379): #5 Stream.asyncExpand.onListen.<anonymous closure> (dart:async/stream.dart:572:30)
E/flutter (19379): #6 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (19379): #7 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (19379): #8 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (19379): #9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (19379): #10 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
E/flutter (19379): #11 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
E/flutter (19379): #12 _MapStream._handleData (dart:async/stream_pipe.dart:232:10)
E/flutter (19379): #13 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
E/flutter (19379): #14 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (19379): #15 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (19379): #16 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (19379): #17 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (19379): #18 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter (19379): #19 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
E/flutter (19379): #20 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
E/flutter (19379): #21 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (19379): #22 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (19379): #23 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (19379): #24 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter (19379): #25 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (19379): #26 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (19379): #27 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (19379): #28 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter (19379): #29 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (19379): #30 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter (19379):
it comes from an adaptation of the example code, using my own Todo class:
class NewList extends StatelessWidget {
// const NewList({Key key}) : super(key: key);
Stream<List<Todo>> todoListStream;
Function(BuildContext) addTodo;
NewList(this.todoListStream, this.addTodo);
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(
// title: const Text("Animated Stream List"),
// ),
body: SafeArea(
child: _buildStreamList(todoListStream),
),
floatingActionButton: FloatingActionButton(
onPressed: () => addTodo(context),
child: const Icon(Icons.add),
),
);
}
Widget _buildStreamList(Stream<List<Todo>> todoListStream) {
return AnimatedStreamList<Todo>(
streamList: todoListStream,
itemBuilder: itemBuilder,
itemRemovedBuilder: itemBuilder,
// equals: (todo1, todo2) => todo1.id == todo2.id,
);
}
Widget _buildItem(Todo item, BuildContext context, [int index]) {
return item.build(
context, () => index != null ? item.check(context) : null);
}
Widget itemBuilder(
Todo todo, int index, BuildContext context, Animation<double> animation) {
return FadeTransition(
opacity: animation,
child: _buildItem(todo, context, index),
);
}
}
any ideas?
Do you also have the code for your Todo class?
This seems to be caused by calling compute
in the calculateDiff
function in meyers_diff.dart
. It is a wrapper for using isolates and you can only send some datatypes to them because they have to be serialized.
From the documentation of compute
:
There are limitations on the values that can be sent and received to and from isolates. These limitations constrain the values of Q and R that are possible. See the discussion at SendPort.send.
and of send
The content of message can be: primitive values (null, num, bool, double, String), instances of SendPort, and lists and maps whose elements are any of these. List and maps are also allowed to be cyclic.
In the special circumstances when two isolates share the same code and are running in the same process (e.g. isolates created via Isolate.spawn), it is also possible to send object instances (which would be copied in the process). This is currently only supported by the dart vm.
So maybe it's a problem if you have any closures (such as final Function onCompleted
) in your Todo class.
Also, does it work if you set the equals
parameter? Because for me it doesn't, which may be caused by the same issue. I think, that #2 can't be fixed because of this either, I tried it and got the same error, likely, because I can't pass a templated closure to the isolate via _DiffArguments<E>
.