Why is the value from the stream not displayed when I first open the view?

29 Views Asked by At

_tachysDist is populated with a value when bloc created, and in the stream builder on debugPrint(snapshot.data) it prints the value from the stream. But when I open the view, the value is not displayed. After that I can type in there and it responds to the validation i.e. works. But why isn't the value from the stream displayed when the view is opened for the first time?

in bloc

EditRapportBloc(this.rData)
      : _tachysDist = BehaviorSubject<String>.seeded(rData.tachysDist);

late final BehaviorSubject _tachysDist;

Stream<String> get tachysDist => _tachysDist.stream.transform(validateTachysDist);
      
Function(String) get changeTachysDist => _tachysDist.sink.add;

final validateTachysDist = StreamTransformer<String, String>.fromHandlers(
    handleData: (value, sink) {
      if (value.length > 5) {
        sink.addError('error');
        return;
      }
      sink.add(value);
    },
);

in view

StreamBuilder<String>(
    stream: bloc.tachysDist,
    builder: (context, snapshot) {
      debugPrint(snapshot.data); // data is present!
      return TextField(
        keyboardType: TextInputType.number,
        onChanged: bloc.changeTachysDist,
      );
    },
);
0

There are 0 best solutions below