Bloc: [Question] Using 'part' & 'part of' directives

Created on 30 Jul 2020  路  4Comments  路  Source: felangel/bloc

Hello!

I've seen a couple examples (like flutter_wizard and flutter_login) that, when managing their Blocs (with its respective events/states classes), it ends up using part and part of package-related directives, which are recommended to be avoided. Is there any particular reason to it? Maybe we are in the progress of moving them from it?

Also, whenever I create a New Bloc - through the vscode extension - it also uses the part/part of directives - though I've seen the examples gifs generating with relative imports. I've correctly restarted/reinstalled my extension and it's using the latest (5.0.0). Any idea why?

Thanks in advance!

example question

Most helpful comment

Hi @matuella 馃憢
Thanks for opening an issue!

As @RollyPeres mentioned in this case it's very beneficial because treating the events/states/bloc as a single file eliminates the need for extra files/code and also makes code generation simpler because you end up with a single my_bloc.g.dart or my_bloc.freezed.dart.

I'm in the process of rewriting all of the examples so they will all be consistent very soon 馃槃

All 4 comments

Hi @matuella 馃憢

They recommend against it simply because people have tendency to misuse those directives, but it doesn't mean they can't be used where they make sense. Bloc is using those directives to reduce boiler plate and the amount of files needed. Without this you'd need some extra boiler plate code inside an extra barrel file to export everything from the bloc, event and state files.

@RollyPeres
Got it! I was always wondering this myself, though I didn't have a strong opinion about those directives.
So, the vscode extension is correctly generating by using part and part of, right?

If that is the case, do you think that it's valid to standardize all of the examples by using one or another approach?

Hi @matuella 馃憢
Thanks for opening an issue!

As @RollyPeres mentioned in this case it's very beneficial because treating the events/states/bloc as a single file eliminates the need for extra files/code and also makes code generation simpler because you end up with a single my_bloc.g.dart or my_bloc.freezed.dart.

I'm in the process of rewriting all of the examples so they will all be consistent very soon 馃槃

Thanks for the quick answers!
That makes sense and, if there is anything, I would be glad to help this incredible library.

I will be closing it because, even though all examples are not updated, the library itself is working as intended.
Feel free to open it again if it makes sense in your development process.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clicksocial picture clicksocial  路  3Comments

MahdiPishguy picture MahdiPishguy  路  3Comments

craiglabenz picture craiglabenz  路  3Comments

abinvp picture abinvp  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments