在一个肘中使用两个存储库-Flutter Bloc
我想知道我是否可以在一个cubit 中实例化两个存储库?像这样:
class LoginCubit extends Cubit<LoginState> {
LoginCubit(this._authRepository, this._authenticationRepository)
: super(const LoginState());
final FirebaseAuthRepository _authenticationRepository;
final AuthRepository _authRepository;
我想使用我的Cubit时该怎么办:
BlocProvider(create: (_) => LoginCubit(context.read<AuthRepository, FirebaseAuthRepository>()),
我会遇到此linter错误:
- &gt; 2位置论点预期,但发现1个。尝试添加丢失的参数。
I was wondering if I could instantiate two Repositories in one Cubit ? Like so :
class LoginCubit extends Cubit<LoginState> {
LoginCubit(this._authRepository, this._authenticationRepository)
: super(const LoginState());
final FirebaseAuthRepository _authenticationRepository;
final AuthRepository _authRepository;
I get stuck on what to do when I'd like to use my cubit :
BlocProvider(create: (_) => LoginCubit(context.read<AuthRepository, FirebaseAuthRepository>()),
I get this linter error :
-> 2 positional argument(s) expected, but 1 found. Try adding the missing arguments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在CUBIT中拥有多个存储库绝对没有问题。您的构造函数是问题所在。您需要将两个变量传递给Cubits构造函数。 IE:
那么您如何获得这些参数可能会有所不同...
您可以执行EG:
或:
或者您获得两个存储库...
我是否建议您查看名为
Getit
的服务定位器软件包以及名为注射
的软件包。那这些事情将为您解决...Absolutely no problem to have multiple repositories in a Cubit. Your constructor call is the problem. You need to pass two variables to the cubits constructor. I.e.:
Then how you get those parameters can differ...
You could do e.g.:
or:
or however you get your two repositories...
May I suggest you to look into the service locator package named
getIt
together with the package namedinjectable
. Then those things will be solved for you...