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.
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