Created
June 17, 2021 17:28
-
-
Save enzoftware/6638ffc30443c2a9e9cf222e0757c3ef to your computer and use it in GitHub Desktop.
Add flutter to android app
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
// Android | |
startActivity( | |
FlutterActivity | |
.withCachedEngine("my_engine_id") | |
.build(this)) | |
val mc = BasicMessageChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL, StringCodec.INSTANCE) | |
mc.send(Gson().toJson(quote)) | |
----- | |
// Flutter | |
static const BasicMessageChannel<String> platform = | |
BasicMessageChannel<String>('flutter.dev/add2toApp', StringCodec()); | |
Map<dynamic, dynamic> _data = {}; | |
@override | |
void initState() { | |
super.initState(); | |
platform.setMessageHandler(_handlePlatformIncrement); | |
} | |
Future<String> _handlePlatformIncrement(String message) async { | |
final response = await json.decode(message); | |
setState(() { | |
_data = response; | |
}); | |
return message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment