Update Android part of flutter_view to use the new platform message c… (#8729)

* update Android part of flutter_view to use the new platform message channel.

* addressed comments

* addressed comments
This commit is contained in:
Sarah Zakarias
2017-03-14 09:38:09 +01:00
committed by GitHub
parent 789c2f1f7a
commit 616a7bed0f
2 changed files with 26 additions and 14 deletions

View File

@@ -31,29 +31,32 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
static const String _channel = "increment";
static const String _pong = "pong";
static const String _emptyMessage = "";
static const PlatformMessageChannel<String> platform =
const PlatformMessageChannel<String>(_channel, const StringCodec());
int _counter = 0;
Future<String> handlePlatformIncrement(String message) async {
_incrementCounter();
return _emptyMessage;
@override
void initState() {
super.initState();
platform.setMessageHandler(_handlePlatformIncrement);
}
void _incrementCounter() {
Future<String> _handlePlatformIncrement(String message) async {
setState(() {
_counter++;
});
return _emptyMessage;
}
void _sendFlutterIncrement() {
PlatformMessages.sendString(_channel, _emptyMessage);
platform.send(_pong);
}
@override
Widget build(BuildContext context) {
PlatformMessages.setStringMessageHandler(_channel,
handlePlatformIncrement);
return new Scaffold(
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,