BlocProvider.of<BlocA>(context)
Its a common way to get a bloc instance of parent's BlocA.
But if i want to use in this way.
BlocProvider<BlocA>(
child: Child1(),
builder: (context){
return _blocAInstance;
},
)
class Child1 extends statelesswidget{
Container(child: Child2());
}
class Child2 extends statelesswidget{
@override
build(context){
var _blocAInstance = BlocProvider.of<BlocA>(context);
}
}
This will throw Exception.
Is there anyway to let Child2 get the top BlocA instance?
Hi @Liuzhiyang94 馃憢
Thanks for opening an issue!
This should work just fine. Can you please provide a link to a sample project which illustrates the problem you鈥檙e having? Thanks 馃憤
Closing for now but feel free to comment with a sample app and I'm more than happy to help 馃憤
@felangel Thanks for reply. I found a bug in my code, BlocProvider.of works fine . Thanks.
Most helpful comment
@felangel Thanks for reply. I found a bug in my code,
BlocProvider.ofworks fine . Thanks.