Skip to content

Latest commit

 

History

History
87 lines (62 loc) · 2.33 KB

README.md

File metadata and controls

87 lines (62 loc) · 2.33 KB

messageport_tizen

pub package

This plugin adds support for communication between Flutter applications on Tizen platform.

Usage

First, import the package in Dart file.

import 'package:messageport_tizen/messageport_tizen.dart';

Create local port

Use LocalPort.create() method to create a local port.

String portName = 'servicePort';
LocalPort localPort = await LocalPort.create(portName);

To register callback to be called when message arrives to the local port, use LocalPort.register() method.

void onMessage(Object message, [RemotePort remotePort]) {
  print('Message received: $message');
}
...
localPort.register(onMessage);

Use LocalPort.unregister() to unregister port when it is no longer needed.

localPort.unregister();

Connect to remote port

To connect to already registered port in remote application, use RemotePort.connect() method.

String portName = 'servicePort';
String remoteAppId = 'remote.app.id';
RemotePort remotePort = await RemotePort.connect(remoteAppId, portName);

Send message

To send message to remote applcation, use RemotePort.send() method.

final message = {'a': 1, 'b': 2, 'c': 3};
try{
  await remotePort.send(message);
} catch (error) {
  print('Could not send message: $error');
}

Send message with local port

To send message with local port information, 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 (error) {
  print('Could not send message: $error');
}

Supported data types

This plugin uses Flutter's StandardMessageCodec to encode transferred data into binary. The data can contain any value or collection type supported by Flutter's standard method codec.

  • null
  • bool
  • int, double
  • String
  • Uint8List, Int32List, Int64List, Float64List
  • Lists and Maps of the above

To learn more about the Tizen Message Port API, visit Tizen Docs: Message Port.