This plugin adds support for communication between Flutter applications on Tizen platform.
First, import the package in dart file.
import 'package:messageport_tizen/messageport_tizen.dart';
Use TizenMessagePort.createLocalPort
method to create local port.
String portName = 'servicePort';
LocalPort localPort = await TizenMessagePort.createLocalPort(portName);
To register callback when message arrives to the local port, use LocalPort.register()
method.
void onMessage(Object message, [RemotePort remotePort]) {
print('Message received: ' + message.toString());
}
...
localPort.register(onMessage);
Use LocalPort.unregister()
to unregister port when it is no longer needed.
localPort.unregister();
To connect to already registered port in remote application, use TizenMessagePort.connectToRemotePort()
method.
String portName = 'servicePort';
String remoteAppId = 'remote.app.id';
RemotePort remotePort = await TizenMessagePort.connectToRemotePort(remoteAppId, portName);
To send message to remote applcation use RemotePort.send()
method.
final message = {"a": 1, "b": 2, "c": 3};
try{
await remotePort.send(message);
} catch (e) {
print('Could not send message: ${e.toString()}");
}
To send message with local port use RemotePort.send()
method. Local port received by remote application can be used to send a response.
final message = "This is a string message";
try{
await remotePort.sendWithLocalPort(message, localPort);
} catch (e) {
print('Could not send message: ${e.toString()}");
}
Data types that can be transferred using this plugin:
- null
- bool
- numbers: int, double
- String
- Uint8List, Int32List, Int64List, Float64List
- List of supported values
- Map from supported values to supported values
Plugin uses Flutter's StandardMessageCodec to encode transferred data into binary. Data can contain any value or collection type supported by Flutter's standard method codec.
To learn more about how to use this plugin, please check example application.
To learn more about Tizen Message Port API visit following guides: