Created
May 21, 2020 13:02
-
-
Save romaomb/5ff4fff0bdbbb5e1b8405e3a74b2b0b8 to your computer and use it in GitHub Desktop.
EventChannel's sample implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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