Home:ALL Converter>About the BLoC class holding another BLoC class

About the BLoC class holding another BLoC class

Ask Time:2019-06-14T16:41:19         Author:ko2ic

Json Formatter

I would like to have BLoC in BloC. When using Provider Plugin, it is the following code and it works correctly.

something_widget.dart

  home: MultiProvider(
    providers: [
      Provider(
        builder: (_) => LoadingBloc(),
        dispose: (_, bloc) => bloc.dispose(),
      ),
      Provider(
        builder: (context) {
          var bloc = Provider.of<LoadingBloc>(context, listen: false);
          return SomethingBloc(SomethingRepository(),bloc);
        },
        dispose: (_, bloc) => bloc.dispose(),
      ),

something_bloc.dart

class SomethingBloc {
  final SomethingRepository repository;
  final LoadingBloc loadingBloc;

  SomethingBloc(this.repository, this.loadingBloc) {
    fetch("flutter");
  }

  final _valueController = StreamController<SearchResultDto>();

  Stream<SearchResultDto> get value => _valueController.stream;

  void fetch(String freeWord) {
    loadingBloc.loading(true);
    var stream = repository.fetch(freeWord).whenComplete(() {
      loadingBloc.loading(false);
    }).asStream();
    _valueController.sink.addStream(stream);
  }

  void dispose() {
    _valueController.close();
  }
}

The question is what problems can arise if it have BLoC in the BLoC class.

Author:ko2ic,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56594514/about-the-bloc-class-holding-another-bloc-class
Harshvardhan Joshi :

There's no way of knowing possible problems if it is already working as expected. This question does not seem to be a technical problem to me. \n\nIf you have any specific doubts then add them in the question, Otherwise just taking a wild guess on the possibility of problems is not going to help anyone.",
2019-06-14T08:56:03
yy