All 7 Flutter App Architecture with Modular Feature Folders questions
More in Flutter App Architecture with Modular Feature Folders
Advertisement
Back to results for “Flutter App Architecture with Modular Feature Folders”
Flutter › Flutter App Architecture with Modular Feature Folders

How should shared code, such as common reusable widgets, utility functions, and core services, be organized within a feature based folder structure, given that this kind of code is not genuinely specific to just one single individual feature?

Intermediate

Answer

Shared code that is genuinely used across several different features, such as common reusable widgets, generic utility functions, or core infrastructure services like a shared networking client, is typically organized within a separate dedicated top level folder, often named something like core or shared, kept clearly and deliberately distinct from the individual feature specific folders, and establishing a clear team wide convention distinguishing exactly what genuinely belongs in this shared location versus what should instead remain properly scoped within one single specific feature folder helps meaningfully prevent that shared folder from gradually and messily accumulating an excessive, disorganized amount of only loosely related, poorly justified code over time.
lib/
  core/
    widgets/
    services/
    utils/
  features/
    checkout/
    profile/
Real-world example A team establishes a clear convention that a specific widget only genuinely moves into the shared core folder once it is actually being reused by at least two entirely separate features, preventing that shared folder from prematurely accumulating a large number of widgets that are actually only ever used by one single specific feature.

Common follow-ups: What criteria should determine whether a specific piece of code truly belongs in a shared folder versus within a single feature?;How do you handle a widget that starts out specific to one feature but later genuinely needs to be reused elsewhere?