Flutter 🐦

Hero image for Flutter 🐦

Project Structure

Generally speaking, a Flutter application can include multi-platforms codebase structure as a cross-platform framework. So it’s important to follow the corresponding project structure when it comes to a specific platform, for instances:

The following structure and directories must be followed for the core Flutter directories (lib/):

project-flutter
β”œβ”€ android/
β”œβ”€ ios/
β”œβ”€ web/
β”œβ”€ assets/
β”œβ”€ lib/
β”‚  β”œβ”€ di/
β”‚  β”œβ”€ api/
β”‚  β”œβ”€ l10n/
β”‚  β”œβ”€ helpers/
β”‚  β”œβ”€ models/
β”‚  β”œβ”€ presenters/
β”‚  β”œβ”€ repositories/
β”‚  β”œβ”€ preferences/
β”‚  β”œβ”€ usecases/
β”‚  β”œβ”€ views/
β”‚  β”œβ”€ main.dart
β”‚  └─ app.dart
β”œβ”€ integration_test/
β”œβ”€ test/
β”œβ”€ pubspec.yaml
β”œβ”€ Makefile
└─ README.md
  • assets: static assets (images, videos, fonts…) included for the application to use at the compile time.
  • android/, ios/, web/: containing all the platform specific configurations corresponding to Android, iOS, Web compilation.
  • lib: the core domain logics and presentation for the whole Flutter application. Depending on the choice of architecture, there could be more or less of the presenter directories added.
  • integration_test: contains all the integration test suites.
  • test: contains all the unit test suites.
  • pubspec.yaml: specifies dependencies that the project requires, such as particular packages (and their versions), fonts, or assets files (images, video…).
  • Makefile: use a Makefile to define executable CLI scripts.
  • README.md: contains all the prerequisites and setup guideline.

Development Environment

Code Editor

There is no specific editor is enforced at the team level. Flutter developers can pick what they are comfortable with but also what does not hinder their productivity.

The following options are the most widely used:

In additions, you will need:

  • XCode for iOS code inspection and editing.

Version Managers

Due to the diversity of projects the team works on, each application usually requires different versions of Flutter. Versions managers allow to install and switch between different versions effortlessly.

The following version manager(s) is recommended:

  • fvm is the preferred version manager for Flutter.

Naming

The team uses and respects the standardized naming conventions from Effective Dart style. The below guidelines are slight variations on specific areas.

  • Constants must be written in UPPER_SNAKE_CASE.

    // Bad
    const int defaultIndex = -1;
    
    // Good
    const int DEFAULT_INDEX = -1;
    
  • Capitalize acronyms and abbreviations no matter the length of letters.

    // Bad
    class HTTPRequest {}
    class DBIOPort {}
    class TVVcr {}
    
    // Good
    class HttpRequest {}
    class DbIoPort {}
    class TvVcr {}