Reputation: 79
I'm working on a large Flutter project where each feature is organized into its own package. In the main directory, I want to run flutter pub get
to install dependencies for all the packages at once. Currently, I have to go into each package's directory and run the command manually. Is there a way to automate this process or run flutter pub get
across all modules from the root?
I’ve tried using shell scripts and some IDE tools, but they seem to only work on individual packages. I expected to run flutter pub get
in the root directory and have it cascade through all sub-packages.
Upvotes: 1
Views: 302
Reputation: 2363
The best way it's to create a workspace, you'll need to create a root folder and a pubspec.yaml
in that root with the structure:
name: my_workspace
environment:
sdk: ^3.5.0 # Must be ^3.5.0 or later for workspace to be allowed
workspace:
- pkgs/package_1 # The workspace-packages must be subdirectories
- pkgs/package_2
- pkgs/package_3
- app
- app2
dependencies:
dev_dependencies:
And the pubspec.yaml
in your packages you just need to add resolution:workspace
i.e. :
name: package_1
description: "A new Flutter package project."
version: 0.0.1
homepage:
environment:
sdk: ^3.5.3
flutter: ">=1.17.0"
resolution: workspace
Please note that this is a work in progress in dart language: https://github.com/dart-lang/pub/issues/4127
Upvotes: 1