fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.23k stars 291 forks source link

Stream can be called only once #2372

Open mitissen opened 3 hours ago

mitissen commented 3 hours ago

Hi, i have a problem, that i can call a function using StreamSink on the rust side as parameter only once in dart.

Example:

pub fn my_method(
    sink: StreamSink<String>) {
   // Call sink.add(..) 
}

At the dart side:

Future<void> another_method(ValueSetter<String> callback) {
    // init rustLib 
     await for (final event in my_method()) {
      callback(event)
    }
}

I call the another_method in my flutter app. I works without a problem i can show a progress bar progress by using the callback in my UI.

BUT the desired behavior happens only the first time i call another_method. If i call another_method a second time the stream is already completed but the rust part is executed successfully.

So i see no progress bar progressing the second time :-)

Is this desired behavior because its a single subscription stream? But the stream is created every time the method is called, or am I wrong?

I've already tried closing the subscription and creating a new one every time another_method is called, but that doesn't seem to help

How can i call this function multiple times by using streams?

Best regards

fzyzcjy commented 2 hours ago

Hi, could you please provide a minimal reproducible sample?

If you call my_method multi times, each time it should have a separate stream and thus the dart callback be called separately.