How to handle global things with Clean Architecture in Flutter apps?


I have completed Reso Coder tutorial about Clean Architecture with TDD in Flutter Apps. But there are two points interesting for me:

  1. If we have global widgets like Loading, Failure, Empty Case and so on, in which layer and how we can store them to access from any feature? is it okay to create folder like widgets in core folder to store these widgets?

  2. If we have the same API calls, or same local data in different pages, in different features, how can we store them? is it okay to create independent features that have not views itself, just contains domain and data layer for other features?

This is my repository:


By checking your repo I’m guessing you are talking about your FailureWidget and LoadingWidget and by "global widgets" you meant widgets used in multiple features of your application. Now to answer your questions :

In my opinion you can definitely put widgets shared in multiple features in the core/ folder but I would recommend to keep some sort of coherence with your different layers. By that I mean that widgets should be putted inside a presentation subfolder because only your presentation layer should depend on those.

  |- core/
  |  |- presentation/
  |  |  |- loading_widget.dart
  |  |  |- failure_widget.dart

Same goes for API calls you want to re-use in multiple features, you can put them inside a data/ subfolder of core/.

  |- core/
  |  |- data/
  |  |- data_sources/

Answered By – Guillaume Roux

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *