简体   繁体   中英

Difference implementing BlocProvider flutter

What's the difference providing to a bloc parameter an object and a class, for example:

BlocProvider<AuthBloc>(

bloc: AuthBloc(),

child: Child()

);

from:

_authBloc = BlocProvider.of<AuthBloc>(context);


BlocProvider<AuthBloc>(

bloc: _authBloc,

child: Child()

);

Thanks :), i hope you can help a lot of people with this doubth.

Case 1:

BlocProvider(

bloc: AuthBloc(),

child: Child()

);

In this case, you are creating a new instance of AuthBloc and passing it into the BlocProvider .

Case 2:

_authBloc = BlocProvider.of<AuthBloc>(context);


BlocProvider<AuthBloc>(

bloc: _authBloc,

child: Child()

);

In this case, you are not creating any new instance, instead fetching the previously created instance from the above tree using BlocProvider.of<AuthBloc>(context);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM