Skip to content

Setting Up Shared Dependencies

What you'll learn

  • Generating the shared dependencies package with barrel exports
  • Choosing your state management solution (Bloc, Provider, or Riverpod)
  • How centralized dependencies prevent version conflicts
  • Importing shared packages across your monorepo

Prerequisites

Step 1: Generate the Shared Dependencies

bash
archipelago generate shared_dependencies

You will be prompted for:

  • appNameMyApp (must match your monorepo app name)
  • stateManagementbloc, provider, or riverpod
  • isForMonorepotrue

Or use a config file:

json
{
  "appName": "MyApp",
  "stateManagement": "bloc",
  "isForMonorepo": true
}
bash
archipelago generate shared_dependencies --config deps_config.json

Step 2: Understand the Generated Structure

shared/
└── dependencies/
    ├── lib/
    │   ├── dependencies.dart          # Main barrel export
    │   └── src/
    │       ├── di.dart                # GetIt + injectable exports
    │       ├── state.dart             # State management exports
    │       ├── routing.dart           # GoRouter exports
    │       └── common.dart            # Equatable, dartz, etc.
    └── pubspec.yaml                   # All shared dependencies

Step 3: How Barrel Exports Work

Instead of every package declaring its own dependency on get_it, equatable, etc., they all import from one place:

dart
// In any feature package
import 'package:dependencies/dependencies.dart';

// This gives you access to:
// - GetIt, Injectable (DI)
// - Bloc/Cubit or Provider or Riverpod (state management)
// - GoRouter (routing)
// - Equatable, dartz (common utilities)

Step 4: Add the Dependency

In each feature's pubspec.yaml:

yaml
dependencies:
  dependencies:
    path: ../../shared/dependencies

Step 5: State Management Choice

The stateManagement variable determines which packages are included:

ChoicePackages Included
blocflutter_bloc, bloc, bloc_concurrency
providerprovider
riverpodflutter_riverpod, riverpod_annotation

This is set once at generation time. All features in your monorepo use the same state management solution.

Step 6: Adding New Shared Dependencies

When you need a new package available across features, add it to the shared dependencies package:

yaml
# shared/dependencies/pubspec.yaml
dependencies:
  freezed_annotation: ^2.4.0
  json_annotation: ^4.8.0

Then re-export it:

dart
// shared/dependencies/lib/src/common.dart
export 'package:freezed_annotation/freezed_annotation.dart';
export 'package:json_annotation/json_annotation.dart';

Common Customizations

CustomizationWhere to Change
Add a shared packagepubspec.yaml + barrel export file
Change state managementRegenerate with different stateManagement
Add category exportsCreate new file in lib/src/, export from barrel
Pin versionsLock versions in pubspec.yaml

Next Steps

Built by Banua Coder