Bloc: Why does Sink not trigger my Stream function?

Asked

Viewed 33 times

0

I have a problem, which I believe is understanding the concept in the use of Bloc. I understood that a Sink with a linked stream will always trigger the stream if an add ( "some information" );

But it’s not happening in this case. Why?

class CreateSuggestionsBloc extends BlocBase {
  final CreateSuggestionsRepository repo;
  final String word;

  var blocPage1 = CreateSuggestionsModule.to.getBloc<CreateSuggestionsBlocStep1>();
  var blocPage2 = CreateSuggestionsModule.to.getBloc<CreateSuggestionsBlocStep2>();
  var blocPage3 = CreateSuggestionsModule.to.getBloc<CreateSuggestionsBlocStep3>();

  CreateSuggestionsBloc(this.repo,{this.word}){ 
     responseOut = dataSuggestion.switchMap(observableSuggestionPost); 
  }

  String email;
  String password;

  int _data1;
  int _data2;
  int _data3;

  var dataSuggestion = BehaviorSubject<Suggestion>();

  Suggestion get dataValue => dataSuggestion.value;
  Stream<int> responseOut;
  Sink<Suggestion> get dataIn => dataSuggestion.sink;

  void register( {item, data} ){
    if ( item == 1 ){
      _data1 = data;
    } else if ( item == 2 ){
      _data2 = data;
    } else if ( item == 3 ){
      _data3 = data;
    }
  }

  void saveall(){
    print( 'blocPage.word = [' + this.word + ']' );
    print( 'blocPage1.Data = ' + blocPage1.data.toString() );
    print( 'blocPage2.Data = ' + blocPage2.data.toString() );
    print( 'blocPage3.Data = ' + blocPage3.data.toString() );
    dataIn.add( new Suggestion( userId: '0',
           name: blocPage1.data.toString(),
           description: blocPage3.data.toString(),           
           languageId: blocPage2.data.toString() ) );    
    print( 'Save all data' );
  }

  Stream<int> observableSuggestionPost(Suggestion data) async* {
    yield 0;
    try{
    //TODO: Implements repository save data
    var response = await repo.createSuggestions(data.toJson());
    yield 1;
    }catch(e){
      throw e;
    }
  }


  @override
  void dispose() {
    dataSuggestion.close();
    super.dispose();
  }

}

In this section does not trigger observableSuggestionPost, what I may be forgetting.

dataIn.add( new Suggestion( userId: '0',
           name: blocPage1.data.toString(),
           description: blocPage3.data.toString(),           
           languageId: blocPage2.data.toString() ) ); 

The above section should trigger the following section, but this does not occur. Why?

Stream<int> observableSuggestionPost(Suggestion data) async* {
yield 0;
try{
//TODO: Implements repository save data
var response = await repo.createSuggestions(data.toJson());
yield 1;
}catch(e){
  throw e;
}}
  • where you are subscribed to listen to new events from this stream?

  • 1

    you are giving the "observe" with the function switchMap have tried with the listen? (I don’t remember if it’s the listen or the doOnListen)

  • @mrocigno did not try with Listen. I will study about it. It is already a path :) Provisionally I am calling the function in the creation of the page, but, I will analyze this possibility. Thanks!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.