在调用 BlocProvider.of() 函数之前,需要确认 RegisterCubit 的实例已经被添加到了当前 context 中。例如:
return BlocProvider(
create: (BuildContext context) => RegisterCubit(),
child: MaterialApp(
title: 'My App',
home: MyHomePage(),
),
);
在以上示例中,将 RegisterCubit 添加到了应用的根 Widget 中,并将 MyApp 包装在了这个 BlocProvider 中。这样,在后续的代码中调用 BlocProvider.of