title: Flutter Event Channel Stream causes crash of app (Lost connection to device)
body: <p>I was following along a tutorial described in this <a href="https://medium.com/@svenasse/flutter-event-channels-89623ce6c017" rel="nofollow noreferrer">article</a>.<br>
  The code of the article can be found here: <a href="https://github.com/seamusv/event_channel_sample" rel="nofollow noreferrer">https://github.com/seamusv/event_channel_sample</a>.<br>
  I basically do the same only that i use kotlin instead of java.</p>
  
  <p>In native code (MainActivity.kt):</p>
  
  <pre><code>class MainActivity: FlutterActivity() {
    private val STREAM_TAG = "alarm.eventchannel.sample/stream";
  
    private var timerSubscription : Disposable? = null
  
    override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      GeneratedPluginRegistrant.registerWith(this)
  
      EventChannel(getFlutterView(), STREAM_TAG).setStreamHandler(
        object : EventChannel.StreamHandler {
          override fun onListen(arguments: Any?, events: EventChannel.EventSink) {
            Log.w("TAG", "adding listener")
            this@MainActivity.timerSubscription = Observable.interval(0, 1, TimeUnit.SECONDS)
               .subscribe (
                 {  
                   Log.w("Test", "Result we just received: $it");
                   events.success(1);
                 }, // OnSuccess
                 { error -&gt; events.error("STREAM", "Error in processing observable", error); }, // OnError
                 { println("Complete"); } // OnCompletion
               )
          }
  
          override fun onCancel(arguments: Any?) {
            Log.w("TAG", "adding listener")
            if (this@MainActivity.timerSubscription != null) {
              this@MainActivity.timerSubscription?.dispose()
              this@MainActivity.timerSubscription = null
            }
          }
        }
      )
  
    }
  }
  </code></pre>
  
  <p>In my main.dart i do the following:</p>
  
  <pre><code>int _timer = 0;
    StreamSubscription _timerSubscription = null;
  
  void _enableTimer() {
    if (_timerSubscription == null) {
      _timerSubscription = stream.receiveBroadcastStream().listen(_updateTimer);
    }
  }
  
  void _disableTimer() {
    if (_timerSubscription != null) {
      _timerSubscription.cancel();
      _timerSubscription = null;
    }
  }
  
  void _updateTimer(timer) {
    debugPrint("Timer $timer");
    setState(() =&gt; _timer = timer);
  }
  </code></pre>
  
  <p>In the build function i also create a button which then calls _enableTimer() onPressed.</p>
  
  <pre><code>new FlatButton(
    child: const Text('Enable'),
    onPressed: _enableTimer,
  )
  </code></pre>
  
  <p>Whenever i now press the button to call _enableTimer() the app crashes and i get the output "Lost connection to device"...<br>
  Am i doing something wrong or is this a bug in a newer version of Flutter since the article is from December 2017?</p>