readStream method

Stream readStream({
  1. required String route,
  2. Map<String, dynamic>? params,
  3. StreamSource source = StreamSource.remoteOnly,
  4. bool persevere = true,
})

Read and stream data for a read route added on the server side

Similar to read and it does stream changes.

Returns a Stream.

route The path of the route.

params Additional data (optional), here can be added a filter to indicate to the server which data will be received.

persevere Default: true (optional). If persevere is true and this route was created in the server with addRouteFor.authenticatedUsers (requires authentication) but clearAuthentication() is called, then this route will wait for the authentication to come back. In case of false the route will be canceled right after clearAuthentication() is called (only if this route requires authentication). This is no-op in case this route doesn't require authentication (addRoute.forAllUsers).

source (optional) Default: StreamSource.remoteOnly.

If StreamSource.remoteOnly shows only realtime events from the server (recommended).

If StreamSource.cacheAndRemote Uses the last emitted event (from another stream with same route and params) as the first event, only in case it's available.

Example

     late StreamSubscription myTextMessagesSubscription;

     @override
     void initState() {
       super.initState();
       myTextMessagesSubscription = AsklessClient.instance.readStream(
         route: "my-text-messages",
         params: { "contains" : "thanks" },
         source: StreamSource.remoteOnly,
         persevere: true,
       ).listen((event) {
         print(event);
       });
     }

     @override
     void dispose() {
       /// remember to cancel() on dispose()
       myTextMessagesSubscription.cancel();
       super.dispose();
     }

Implementation

Stream readStream({required String route, Map<String, dynamic>? params, StreamSource source = StreamSource.remoteOnly, bool persevere = true}) {
  return getIt.get<ListeningHandler>().stream(
    listenCli: ListenCli(route: route, params: params),
    source: source,
    persevere: persevere,
  );
}