我包裹我的脚手架,dart BlocProvider<ABloc,AState>
但是当我使用showDialog func 和showDialog时,我想从上下文访问 ABloc 或者BlocBuilder
不包含 bloc 并抛出错误,有没有办法在这种情况下访问 bloc (在我的对话框中,我显示提交的文本以获取用户名,所以我想访问 bloc)
class MyHomePageState extends StateLessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
lazy: false,
create: (context) => EditColorBloc(context.bloc<RetrieveColorBloc>()),
child: MainScafold());
}
}
Run Code Online (Sandbox Code Playgroud)
class MainScafold extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("sina"),
),
floatingActionButton:FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => showDialog(
context: context,
builder: (ctx) {
// show dialog and use
// context o BlocBuilder to …Run Code Online (Sandbox Code Playgroud)