-
Notifications
You must be signed in to change notification settings - Fork 24
Flutter to Native communication
App uses pigeon package to generate type-safe communication messages.
Interfaces are defined in pigeons.dart file. Adding interfaces to that file and regenerating Pigeons (see README for instructions on that) will generate pigeons.g.dart on dart side and Pigeons.java on Android side. Those generated calls can then be used to call methods on each other side.
Caveats:
- Pigeon methods can only accept and return classes. To use primitive type as argument or return type, use one of the available wrapper classes (
NumberWrapper
,BooleanWrapper
etc.) - Pigeon does not support generics. That is why manually convert objects from/to maps when sending list of objects over Pigeon (for example see PebbleScanDevice.
To use Flutter -> Native pigeon, just construct it and call its methods (for example UiConnectionControl().connectToWatch(address);
).
Tu use Native -> Flutter pigeon, implement the interface and then call MyInterface.setup(implementation);
. Make sure that you call MyInterface.setup(null);
whenever object that implements the interface is disposed to not leak memory.
It is recommended that you create a wrapper class that transforms pigeons into nicer classes that can used via hooks. For example see connectionStateProvider.