Felipe Cabeza
Felipe Cabeza

Reputation: 33

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.

Upvotes: 1

Views: 378

Answers (1)

Darish
Darish

Reputation: 11481

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);

Upvotes: 2

Related Questions