Rxdart: Help : This code works on rxdart: ^0.22.6 but failed at ^0.23.0 and up

Created on 16 Dec 2020  路  4Comments  路  Source: ReactiveX/rxdart

The error message :

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type 'SwitchMapStreamTransformer<dynamic, List<Map<dynamic, dynamic>>>' is not a subtype of type 'StreamTransformer<ItemModelEvent, List<Map<dynamic, dynamic>>>' of 'streamTransformer'

The code :

_events
        .where(
            (event) => (event as ItemModelEvent).event == BlocEvents.getChips)
        .switchMap((i) async* {
      // print('debug reload');
      yield await sqlite
          .searchTableGetAllChips(modulename); // import from _sliverchips
    }).listen((result) {
      _streamchipsdata.add(result);
    });

What is the breaking changes in switchMap from 0.22.x to 0.23.x ? How to fix it ?

Thanks in advance for helping

help wanted waiting for response

All 4 comments

_events.cast<ItemModelEvent>.where(...)

@hoc081098 Thanks, I'm mobile right now will let you know if it works, thanks a lot for trying to help

@hoc081098 the vscode shows error :

The prefix '_events' can't be used here because it is shadowed by a local declaration.
Try renaming either the prefix or the local declaration.

below is the complete changes that shows error above

_events
        .cast<ItemModelEvent>
        .where(
            (event) => (event as ItemModelEvent).event == BlocEvents.getChips)
        .switchMap((i) async* {
      // print('debug reload');
      yield await sqlite
          .searchTableGetAllChips(modulename); // import from _sliverchips
    }).listen((result) {
      _streamchipsdata.add(result);
    });

BTW _events is

final PublishSubject _events = PublishSubject<ItemModelEvent>();

Any clue ?

Thanks

Ok I think I got it

_events
        .cast<ItemModelEvent>()
        .where(
            (event) => (event as ItemModelEvent).event == BlocEvents.getChips)
        .switchMap((i) async* {
      // print('debug reload');
      yield await sqlite
          .searchTableGetAllChips(modulename); // import from _sliverchips
    }).listen((result) {
      _streamchipsdata.add(result);
    });

Should be

_events.cast<ItemModelEvent>()

Thanks @hoc081098, now should change all my event handling and hope it fix it

Was this page helpful?
0 / 5 - 0 ratings