klutter icon indicating copy to clipboard operation
klutter copied to clipboard

Streams api support

Open raspberry-jenshen opened this issue 3 years ago • 1 comments

Wow, what a great project :)

You've done really impressive work.

What do you think about supporting streams API? It's commonly used in flutter plugins.

Kotlin multiplatform side: fun observeLocation() : Flow<Location>

Dart side:

Stream<Location> observeLocation(); https://api.flutter.dev/flutter/services/EventChannel-class.html

I've done it for my own plugin. Would be great to have such a feature supported by Klutter. Thanks in advance.

raspberry-jenshen avatar Aug 09 '22 12:08 raspberry-jenshen

Thank you for the kind words!

I have looked into using event channels and it is definitely possible to add support for it. Can't say if/when it could be added though.

Could you provide a link to your plugin? I am interested to see your solution.

buijs-dev avatar Aug 09 '22 14:08 buijs-dev

Eventchannel support is available from klutter 2023.1.1.beta (dart 0.3.0).

buijs-dev avatar May 23 '23 17:05 buijs-dev

Can you provide an example on how to use the EventChannel support Klutter?

erksch avatar May 23 '24 22:05 erksch

Can you provide an example on how to use the EventChannel support Klutter?

See the stateless-ui recipe in the cookbook.

buijs-dev avatar May 24 '24 06:05 buijs-dev

I see. Your @Controller annotated Kotlin class has to subclass Publisher. This creates an EventChannel with the name of the controller. The corresponding generated Dart class subclasses Subscriber.

The recipe you mentioned has no generated android or iOS plugin classes. Is this correct? The EventChannel would need to be wired in the plugin native files.

erksch avatar May 24 '24 21:05 erksch

The compiler plugin will generate all the boilerplate code for Android and iOS. Just run kradle build (or gradlew install -p platform) first to see it.

buijs-dev avatar May 24 '24 21:05 buijs-dev