Closed ngocmanh1609 closed 4 years ago
It is intended behavior of BlocProvider or its internal implementation InheritedWidget
.
Former example is correct.
You can also use BlocProvider.builder()
, which offers builder: (context, bloc) {}
. You can use the context
to get BLoC , and you can use the bloc
of course.
@override
Widget build(BuildContext context) {
return BlocProvider<LoginBloc>.builder(
creator: (_, _bag) => LoginBloc(),
builder: (context, bloc) => Scaffold(
primary: true,
appBar: EmptyAppBar(),
body: _buildBody(),
));
}
I seem to understand more about InheritedWidget
and its context
usage, sorry I just start learning Flutter recently and I found that your library is a good thing to combine with reactive programming (rxDart
) 😅
Thanks for replying me @mono0926 🙏
Hi @mono0926 👋 Nice to meet you and thank for useful library that helped me so much in work. 😁
But I have a concern and I dont know if it's a bug. For example, I have an app with 2 screens: Splash screen and Login screen. When I define BlocProvider (
LoginBloc
) for LoginScreen, I cannot define it inside LoginScreen, and I must define it inroute
, otherwiseInvalid arguments
error will be raisedInvalid argument(s): LoginBloc is not provided to LoginScreen. Context used for Bloc retrieval must be a descendant of BlocProvider.
:This is just a minor problem but I dont know if it can be fixed, thank you 😁