Browse Source

fixes Issue #82

devmil 4 years ago
parent
commit
dab4d27195
1 changed files with 10 additions and 2 deletions
  1. 10 2
      example/lib/isolate.dart

+ 10 - 2
example/lib/isolate.dart

@@ -43,15 +43,23 @@ class MyHomePage extends StatefulWidget {
 }
 
 class FakeTerminalBackend extends TerminalBackend {
-  final _exitCodeCompleter = Completer<int>();
+  // we do a late initialization of those backend members as the backend gets
+  // transferred into the Isolate.
+  // It is not allowed to e.g. transfer closures which we can not guarantee
+  // to not exist in our member types.
+  // The Isolate will call init() once it starts (from its context) and that is
+  // the place where we initialize those members
+  late final _exitCodeCompleter;
   // ignore: close_sinks
-  final _outStream = StreamController<String>();
+  late final _outStream;
 
   @override
   Future<int> get exitCode => _exitCodeCompleter.future;
 
   @override
   void init() {
+    _exitCodeCompleter = Completer<int>();
+    _outStream = StreamController<String>();
     _outStream.sink.add('xterm.dart demo');
     _outStream.sink.add('\r\n');
     _outStream.sink.add('\$ ');