Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to place custom helper classes in Flutter BLoC architecture

Is there a best practice for the location of custom helper classes in Flutter using BLoC architecture?

This is my package structure:

/data
  /data_providers
  /models
  /repositories
/logic
  /blocs
  /cubits
/presentation
  /screens
  /widgets
/resources

Example: I have a custom helper class Tuple which is only used in my model /data/models/User.dart.

I see the following options:

  • place class Tuple above or below class User in /data/models/User.dart
  • create the file /data/models/Tuple.dart and place class Tuple there
  • create the new package /helpers in the root directory, create the file /helpers/Tuple.dart and place class Tuple there
  • or do you have other recommendations?

Of course all solutions are functionable. The question is: What is best practice?

like image 391
Vega180 Avatar asked Oct 14 '25 10:10

Vega180


1 Answers

Indeed there is no standard best practice to put it. In my own opinion, create a separate folder called utils or util or helper or helpers and put it there. This is reasonable, since helpers are themselves not a model (so may not be put into models/*.dart.

like image 75
ch271828n Avatar answered Oct 17 '25 05:10

ch271828n



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!