buijs-dev / klutter

Framework for Flutter + Kotlin Multiplatform
MIT License
226 stars 5 forks source link

Streams api support #5

Closed raspberry-jenshen closed 1 year ago

raspberry-jenshen commented 2 years ago

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.

buijs-dev commented 2 years ago

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 commented 1 year ago

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

erksch commented 6 months ago

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

buijs-dev commented 5 months ago

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

See the stateless-ui recipe in the cookbook.

erksch commented 5 months ago

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.

buijs-dev commented 5 months ago

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.