Bloc: MultiBlocProvider and lint rule always_specify_types

Created on 15 Sep 2019  路  2Comments  路  Source: felangel/bloc

Thanks for this great package. I love using blocs in Flutter with it! One question regarding the MultiBlocProvider and a lint rule:

Currently I'm not sure if it's possible to use the MultiBlocProvider with the lint rule always_specify_types. At least I'm not sure which types I have to specify here.

In this code snippet there is an dart analysis problem Specify type annotations. for the type of the array after providers. Unfortunately, BlocProvider as a type is not enough.:

MultiBlocProvider(
  // ignore: always_specify_types
  providers: [
    BlocProvider<GameFilterBloc>(
      builder: (BuildContext context) => GameFilterBloc(
        gamesRepository: GamesRepository(),
      )..dispatch(FetchGamesForFilter()),
    ),
    BlocProvider<CollectorListBloc>(
      builder: (BuildContext context) => CollectorListBloc(
        collectorRepository: RepositoryProvider.of<CollectorRepository>(context),
        searchFilter: CollectorSearchFilter(context),
        gameFilterBloc: BlocProvider.of<GameFilterBloc>(context),
      )..dispatch(InitPokedex()),
    )
  ],
  child: PokemonCollectorPage(),
),

Does the MultiBlocProvider currently not work with the rule or what should be specified here?

question

Most helpful comment

Thanks for the quick response, this is working. The problem was a missing import. I had already tried this variant, but Bloc was unknown, which I didn't notice.

Maybe I should also think again if the rule makes sense for me.

All 2 comments

Hi @DFelten 馃憢
Thanks for opening an issue!

If you really want to always specify types you can do:

MultiBlocProvider(
  providers: <BlocProvider<Bloc<dynamic, dynamic>>>[
    BlocProvider<GameFilterBloc>(
      builder: (BuildContext context) => GameFilterBloc(
        gamesRepository: GamesRepository(),
      )..dispatch(FetchGamesForFilter()),
    ),
    BlocProvider<CollectorListBloc>(
      builder: (BuildContext context) => CollectorListBloc(
        collectorRepository: RepositoryProvider.of<CollectorRepository>(context),
        searchFilter: CollectorSearchFilter(context),
        gameFilterBloc: BlocProvider.of<GameFilterBloc>(context),
      )..dispatch(InitPokedex()),
    )
  ],
  child: PokemonCollectorPage(),
),

I personally don't use that lint rule because I don't think it provides much value and just makes the code more verbose. You can always see what the type is in VSCode or Android Studio just by hovering over the instance.

Hope that helps 馃憤

Thanks for the quick response, this is working. The problem was a missing import. I had already tried this variant, but Bloc was unknown, which I didn't notice.

Maybe I should also think again if the rule makes sense for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RobPFarley picture RobPFarley  路  3Comments

abinvp picture abinvp  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments

clicksocial picture clicksocial  路  3Comments

rsnider19 picture rsnider19  路  3Comments