About the Definition Order of Flutter pubspec.yaml dependencies

Tadashi Shigeoka ·  Thu, February 27, 2020

This is about how I personally want to arrange the dependencies defined in Flutter’s pubspec.yaml in alphabetical order (A-Z).

Flutter

Prerequisites

When you run flutter create project_name, the following dependencies definition is created in pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

Perhaps because it’s a Flutter project, flutter: is defined first, followed by cupertino_icons:.

I don’t think you’d mind this at project creation time, but as development progresses and packages increase, the definition order of dependencies started to bother me personally.

Arranging pubspec.yaml dependencies in Alphabetical Order

Here’s an example of rearranging the dependencies in pubspec.yaml from random definition to alphabetical order:

Before modification:

dependencies:
  flutter:
    sdk: flutter

  firebase_core: ^0.2.5
  firebase_analytics: ^1.0.4

  cupertino_icons: ^0.1.2

After modification:

dependencies:
  cupertino_icons: ^0.1.2
  firebase_analytics: ^1.0.4
  firebase_core: ^0.2.5
  flutter:
    sdk: flutter

That’s all about wanting to arrange the definition order of dependencies in pubspec.yaml in alphabetical order (A-Z) from the Gemba.

That’s all from the Gemba.