Skip to content

Instantly share code, notes, and snippets.

@romaomb
Created May 21, 2020 13:02
Show Gist options
  • Save romaomb/5ff4fff0bdbbb5e1b8405e3a74b2b0b8 to your computer and use it in GitHub Desktop.
Save romaomb/5ff4fff0bdbbb5e1b8405e3a74b2b0b8 to your computer and use it in GitHub Desktop.
EventChannel's sample implementation
import 'dart:async';
import 'package:flutter/services.dart';
class EventChannelSample {
final _channel = EventChannel('codes.romao.event');
StreamSubscription _channelSubscription;
EventChannelSample() {
_channelSubscription = _channel
.receiveBroadcastStream()
.listen((event) {
if (event is int) {
_handleNewEvent(event);
} else {
_handleUnknownEvent(event);
}
},
);
}
void _handleNewEvent(int event) {}
void _handleUnknownEvent(dynamic event) {}
void dispose() {
_channelSubscription.cancel();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment