Bloc: BlocSupervisor doesn't have a default constructor

Created on 17 Jul 2019  路  2Comments  路  Source: felangel/bloc

hey when i update the version 0.13.0 to 0.19.1 there has some error
1.BlocProvider miss the bloc params
2.BlocSupervisor doesn't have a default constructor

can you show me how to fix it! tks

question

Most helpful comment

Hey @Huai-Dc !

BlocProvider from flutter_bloc

According to the changelogs and the sources that you can read.

  • Since the version 0.16.0 the BlocProvider expose a builder and a bool dispose property.

  • Since the version 0.17.0 the BlocProvider is automatically disposing the bloc (can be forced with bool dispose property).

  • Since the version 0.19.0 flutter_bloc is now extending classes from the provider with different constructors.

As you can see here, BlocProvider can now be constructed two different ways.

BlocProvider with builder

If you want to let the provider to auto-dispose the bloc you can use the new implementation of the default constructor:

BlocProvider(
   builder: (context)=> MyBloc(),
);

BlocProvider with value

If you still want to manage the lifecycle of your bloc you can use the named constructor BlocProvider.value(/*omitted*/) :

MyBloc mybloc = MyBloc();

/* ... */

BlocProvider.value(
   value: myBloc,
);

Migration

So if you are coming from 0.13.0 you can easily migrate from :

BlocProvider(
   bloc: myBloc,
);

to

BlocProvider.value(
   value: myBloc
);

BlocSupervisor from bloc

According to the doc :

  • Since version 0.14.0 the BlocSupervisor have been improved.

Migration

So the constructor of BlocSupervisor is no longer exposed but you can still use it by migrating from :

BlocSupervisor().delegate = /*...*/;

to

BlocSupervisor.delegate = /*...*/;

All 2 comments

Hey @Huai-Dc !

BlocProvider from flutter_bloc

According to the changelogs and the sources that you can read.

  • Since the version 0.16.0 the BlocProvider expose a builder and a bool dispose property.

  • Since the version 0.17.0 the BlocProvider is automatically disposing the bloc (can be forced with bool dispose property).

  • Since the version 0.19.0 flutter_bloc is now extending classes from the provider with different constructors.

As you can see here, BlocProvider can now be constructed two different ways.

BlocProvider with builder

If you want to let the provider to auto-dispose the bloc you can use the new implementation of the default constructor:

BlocProvider(
   builder: (context)=> MyBloc(),
);

BlocProvider with value

If you still want to manage the lifecycle of your bloc you can use the named constructor BlocProvider.value(/*omitted*/) :

MyBloc mybloc = MyBloc();

/* ... */

BlocProvider.value(
   value: myBloc,
);

Migration

So if you are coming from 0.13.0 you can easily migrate from :

BlocProvider(
   bloc: myBloc,
);

to

BlocProvider.value(
   value: myBloc
);

BlocSupervisor from bloc

According to the doc :

  • Since version 0.14.0 the BlocSupervisor have been improved.

Migration

So the constructor of BlocSupervisor is no longer exposed but you can still use it by migrating from :

BlocSupervisor().delegate = /*...*/;

to

BlocSupervisor.delegate = /*...*/;

thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rsnider19 picture rsnider19  路  3Comments

clicksocial picture clicksocial  路  3Comments

wheel1992 picture wheel1992  路  3Comments

krusek picture krusek  路  3Comments

Reidond picture Reidond  路  3Comments