• Home
  • Insight
  • Blog
  • Business
  • Entertainment
  • Health
  • Politics
  • Shop
    • Gift Shop
    • Value Shop
    • Store
    • Bargain Shop
    • Discount
  • Sports
  • Tech
  • Travel
  • USA
  • Video
  • World
    • Asia
    • Africa
    • South America
    • North America
    • Europe
    • Oceania
Sunday, March 15, 2026
No Result
View All Result
Subscribe Now
  • Home
  • Insight
  • Blog
  • Business
  • Entertainment
  • Health
  • Politics
  • Shop
    • Gift Shop
    • Value Shop
    • Store
    • Bargain Shop
    • Discount
  • Sports
  • Tech
  • Travel
  • USA
    Headless victim in 1976 New York cold case identified through DNA: police

    Headless victim in 1976 New York cold case identified through DNA: police

    What’s Good? – The New York Times

    What’s Good? – The New York Times

    Israel’s Deadly Blockade Traps 7 U.S. Doctors in Gaza

    Israel’s Deadly Blockade Traps 7 U.S. Doctors in Gaza

    Carney announces billions for defense and infrastructure in Canada’s North

    Carney announces billions for defense and infrastructure in Canada’s North

    Right-wing media’s Mamdani outrage fuels GOP anti-Muslim rhetoric

    Right-wing media’s Mamdani outrage fuels GOP anti-Muslim rhetoric

    12-year-old girl dies days after collapsing following fight near school bus stop

    12-year-old girl dies days after collapsing following fight near school bus stop

    Speaker Mike Johnson Sketches ‘Course Correction’ in DHS Deportation Policy

    Speaker Mike Johnson Sketches ‘Course Correction’ in DHS Deportation Policy

    Where Was ‘War Machine’ Filmed? Discover the ‘War Machine’ 2026 Filming Locations for Alan Ritchson’s Netflix Movie

    Where Was ‘War Machine’ Filmed? Discover the ‘War Machine’ 2026 Filming Locations for Alan Ritchson’s Netflix Movie

    L.A. City Council candidate stays in race after report that he stabbed a boy at age 12

    L.A. City Council candidate stays in race after report that he stabbed a boy at age 12

  • Video
  • World
    • Asia
    • Africa
    • South America
    • North America
    • Europe
    • Oceania
The Insight Post
  • Home
  • Insight
  • Blog
  • Business
  • Entertainment
  • Health
  • Politics
  • Shop
    • Gift Shop
    • Value Shop
    • Store
    • Bargain Shop
    • Discount
  • Sports
  • Tech
  • Travel
  • USA
    Headless victim in 1976 New York cold case identified through DNA: police

    Headless victim in 1976 New York cold case identified through DNA: police

    What’s Good? – The New York Times

    What’s Good? – The New York Times

    Israel’s Deadly Blockade Traps 7 U.S. Doctors in Gaza

    Israel’s Deadly Blockade Traps 7 U.S. Doctors in Gaza

    Carney announces billions for defense and infrastructure in Canada’s North

    Carney announces billions for defense and infrastructure in Canada’s North

    Right-wing media’s Mamdani outrage fuels GOP anti-Muslim rhetoric

    Right-wing media’s Mamdani outrage fuels GOP anti-Muslim rhetoric

    12-year-old girl dies days after collapsing following fight near school bus stop

    12-year-old girl dies days after collapsing following fight near school bus stop

    Speaker Mike Johnson Sketches ‘Course Correction’ in DHS Deportation Policy

    Speaker Mike Johnson Sketches ‘Course Correction’ in DHS Deportation Policy

    Where Was ‘War Machine’ Filmed? Discover the ‘War Machine’ 2026 Filming Locations for Alan Ritchson’s Netflix Movie

    Where Was ‘War Machine’ Filmed? Discover the ‘War Machine’ 2026 Filming Locations for Alan Ritchson’s Netflix Movie

    L.A. City Council candidate stays in race after report that he stabbed a boy at age 12

    L.A. City Council candidate stays in race after report that he stabbed a boy at age 12

  • Video
  • World
    • Asia
    • Africa
    • South America
    • North America
    • Europe
    • Oceania
No Result
View All Result
No Result
View All Result
Home Mobile

How to manage your Flutter monorepos

by Theinsightpost
August 2, 2022
in Mobile
0 0
0
How to manage your Flutter monorepos


Monorepos are extremely helpful when working with larger codebases. But they also come with additional management costs. In this article, we will go through the process of managing a monorepo with a tool like Melos and set up our repository for CI/CD with Codemagic.

This article is written by Nils Reichardt.

Introduction to monorepos

Nowadays, many companies and projects use the structure of a monorepo. A few examples include Flutter itself, FlutterFire (a set of Flutter packages for Firebase), Riverpod, PlusPlugins by the Flutter community, and Very Good Ventures in projects like I/O Photo Booth.

But what is a monorepo? A monorepo is a single version-controlled repository that can store many different projects.

Advantages of a monorepo

A monorepo has some useful advantages:

  • Code reuse: A monorepo enables you to split your codebase into small independent packages, which is great for code reuse and testing
  • Better CI: With a monorepo, you can easily trigger the CI when changing something else in your repository (for example, you can trigger Flutter integration tests when making changes to the back end)
  • Dependency management: You have local packages without needing a dependency manager, like pub.dev
  • Enforces layered architecture: You can require yourself and your team to apply a layered architecture by splitting the layers into multiple packages
  • Keeps everything stored in one place: New developers simply clone the monorepo and have everything in one repository

Disadvantages of a monorepo

Like everything in life, a monorepo does have some disadvantages:

  • More overhead: You need to set up tools to manage the repository
  • No per-project access control: When you have everything in one repository, everyone with repository access can access everything

Note: These are just a few of the advantages and disadvantages of a monorepo. There are many more things to consider when comparing a monorepo and multirepos.

Scope of this article

Now that you have a basic understanding of a monorepo, let’s set the scope for this article since monorepos are a big topic. You can store your front end, back end, internal tools, website, and more in your monorepo. Google is known for having the largest codebase in the world — they have everything in one repository. So covering everything about monorepos in one article would be too much.

This article will focus specifically on Flutter/Dart monorepos, which involve splitting your app into small independent packages.

Example app

To provide a practical example, we are using the Flutter counter app with a few adjustments.

apps/
  counter_app
packages/
  counter_widgets
  counter_lint

In apps, we have apps that we actually deploy. We could also have an internal app, website, etc.

In packages, we have our local packages.

You can check out the full source here.

As just mentioned, tools are extremely helpful for managing your monorepo. You will face challenges such as the following:

  • Getting the dependencies for all packages
  • Checking linting for all packages
  • Checking formatting for all packages
  • Running tests for all packages
  • Running build_runner in all packages
  • Merge code coverage for all packages

You could write your own bash script or CLI to help manage these tasks. However, this costs you some time. In order to deal with these tasks more quickly, you can use community tools, like Melos, Very Good CLI, or Sidekick. In this article, we are going to use Melos. Melos is also used by repositories like FlutterFire, AWS Amplify (Flutter), Flame, and Plus Plugins.

Setting up Melos

First, you need to install Melos by running the following command in your terminal:

dart pub global activate melos

To configure Melos, we need to create a top-level melos.yaml file. The structure currently looks like this:

apps/
  counter_app
packages/
  counter_widgets
  counter_lint
melos.yaml

Now, we set up the melos.yaml file with a basic configuration:

# The name of the project (required) is used for display purposes within IO environments and IDEs.
name: counter

# A list of paths to local packages that are included in the Melos workspace. Each entry can be a specific path or a glob pattern.
packages:
  - "apps/*"
  - "packages/**"

# Recommended option for projects with Dart 2.17.0 or greater.
#
# This enables a new mechanism for linking local packages, which integrates
# better with other tooling (e.g. dart tool, Flutter tool, IDE plugins) than the
# mechanism currently being used by default. Please read the documentation for
# usePubspecOverrides before enabling this feature.
#
# See https://melos.invertase.dev/getting-started#setup
command:
  bootstrap:
    usePubspecOverrides: true

After setting up the melos.yaml file, run the bootstrap command to initialize Melos for your project:

Bootstrapping has two primary roles:

  1. Installing all package dependencies (internally using pub get)
  2. Locally linking any packages together

In melos.yaml, we can also define our commands, which are executed in every Dart/Flutter package inside our defined Melos workspace.

scripts:
  analyze:
    run: melos exec -- "flutter analyze"
    description: Run `flutter analyze` in all packages
  
  format:
    run: melos exec -- "flutter format . --set-exit-if-changed"
    description: Run `flutter format .` in all packages

  test:
    # Only run the test command when the package has a test directory
    run: melos exec --dir-exists=test -- "flutter test"
    description: Run `flutter test` in all packages

We are now able to execute our script with melos run SCRIPT_NAME. To run the flutter analyze command in all packages, we can use this command:

You can add any script you want in the melos.yaml file, like the build_runner. Check out the Melos documentation to find out more about the scripts configuration.

Also, take a look at melos-code, a VS Code extension for Melos that helps you to work with Melos and VS Code.

Setting up your Flutter monorepo for CI/CD

You should be able to manage your monorepo locally with Melos. However, you might need to configure your CI/CD environment to fully support your monorepo. We are going to use Codemagic as a CI/CD provider.

Sign up

Scope of our CI

Our CI pipeline should perform the following checks for every pull request:

  • Run the melos run analyze command
  • Run the melos run format command
  • Run the melos run test command
  • Upload the results of failed Golden tests

Configure CI/CD for a monorepo

Set up Codemagic

First, you need a Codemagic account. If you don’t have one already, you can sign up for Codemagic with your Git provider. Set up Codemagic with the Workflow Editor or the codemagic.yaml file. If you need a step-by-step guide, you can follow this article to set up your monorepo for Codemagic.

The Workflow Editor is simple to use for a basic app. However, for a monorepo, it’s better to use codemagic.yaml because we can run our own commands with Melos. For this reason, this article only covers the setup for the codemagic.yaml file.

Set up Melos for CI/CD

Setting up Melos in CI/CD is similar to setting it up for your local machine.

  1. Run dart pub global activate melos
  2. Run melos bootstrap

Let’s check out the basic configuration in the codemagic.yaml file:

workflows:
  ci:
    name: CI
    instance_type: mac_mini
    # Setting the timeout for a build to 15 minutes.
    max_build_duration: 15
    environment:
      # Using the latest Flutter version.
      flutter: stable
    # This workflow should trigger when a new pull request opens or updates.
    triggering:
      events:
        - pull_request
    scripts:
      - name: Add Dart SDK to PATH
         script: |
           echo PATH="$PATH":"$FLUTTER_ROOT/.pub-cache/bin" >> $CM_ENV
           echo PATH="$PATH":"$FLUTTER_ROOT/bin" >> $CM_ENV           
      
      - name: Melos Bootstrap
         script: |
           dart pub global activate melos
           melos bootstrap           

If you take closer look at the script, you’ll notice these lines:

echo 'export PATH="$PATH":"$FLUTTER_ROOT/.pub-cache/bin"' >> $CM_ENV 
echo 'export PATH="$PATH":"$FLUTTER_ROOT/bin"' >> $CM_ENV 

We need to add the paths to the Dart SDK to PATH to be able to run dart commands. Otherwise, we will get an error, like dart: command not found.

Run Melos scripts

Let’s add our Melos scripts to the codemagic.yaml file. This is how codemagic.yaml looks now:

workflows:
  ci:
    name: CI
    instance_type: mac_mini
    # Setting the timeout for a build to 15 minutes.
    max_build_duration: 15
    environment:
      # Using the latest Flutter version.
      flutter: stable
    # This workflow should trigger when a new pull request opens or updates.
    triggering:
      events:
        - pull_request
    scripts:
      - name: Add Dart SDK to PATH
         script: |
           echo PATH="$PATH":"$FLUTTER_ROOT/.pub-cache/bin" >> $CM_ENV
           echo PATH="$PATH":"$FLUTTER_ROOT/bin" >> $CM_ENV           
      
      - name: Melos Bootstrap
         script: |
          dart pub global activate melos
          melos bootstrap          

      - name: Run Analyze
         script: melos run analyze

      - name: Run Format
         script: melos run format

      - name: Run Tests
         script: melos run test

Get the results of failed Golden tests

With Golden tests, you can render a widget and compare it with a screenshot. To understand more about Golden tests, check out this blog article on how to run Flutter Golden (Snapshot) tests with Codemagic CI/CD. If you have Golden tests in your Flutter repo, you may want to access the results of failed Golden tests. When you use a monorepo, you need to check every package for the results of failed Golden tests. To do this, you can just run this script:

...
- name: Run Tests
  script: |
    melos run test
    
    # Upload results of failed Golden tests if test command failed.
    if [ $? -ne 0 ]; then
      # Finds all "failures" folders and copies them to the export
      # directory. Therefore, we are able to view the results of the
      # failed Golden tests.
      #
      # The command will use the exit code 0 (success) even when there are
      # no failures folders.
      find * -path '**/failures' -execdir bash -c "cp -r failures $FCI_EXPORT_DIR" ;
      
      # Because we caught the exit code of the test command, we need to
      # set manually again.
      exit 1
    fi    

Configure path conditions

At the moment, we run our CI for every pull request no matter what changed in this pull request, even when we just change the documentation files or files in our back end (assuming we also have our back end in our monorepo).

However, you are using up unnecessary Codemagic build minutes.

To use your build minutes more efficiently, you can set path conditions. With path conditions, you can define that the CI should only run when changes have been made for specific paths.

Just use the when keyword to configure the paths:

...
environment:
  # Using the latest Flutter version.
  flutter: stable
when:
  changeset:
    includes:
      # Only run the CI when a file in one of the following directories
      # changed.
      - "apps/**"
      - "packages/**"
      - "codemagic.yaml"
    excludes:
      # Don't run the CI when only .md files have changed.
      - "**/*.md"
# This workflow should trigger when a new pull request opens or updates.
triggering:
...

You can also check out the Codemagic documentation on running builds and builds steps conditionally for more information about conditional runs.

Conclusion

Monorepos are great for larger codebases. However, as you may have noticed in this article, they require a bit more effort to manage. Nevertheless, you should now be able to manage your own Flutter monorepo with Melos and configure your CI/CD.

You can check out the full source of the repository here.

If you have configuration problems with Codemagic, just ask for help in the Codemagic Slack.


This article is written by Nils Reichardt, Co-Founder of Sharezone, a collaborative school planner for Android, iOS, Web and macOS with +300.000 registered users. He fell in love with Flutter since the first beta release in March 2018. You can find Nils on Twitter, GitHub and LinkedIn.





Source link

ShareTweetSend
Previous Post

iQOO 9T launching today in India! From specs to price, all you need to know is here

Next Post

France and parts of England experience driest July on record as new heatwave nears

Related News

ROI of AI in Manufacturing: Costs, Speed & Accuracy
Mobile

ROI of AI in Manufacturing: Costs, Speed & Accuracy

March 14, 2026
Avocado Health introduces AI-Powered text coaching for parents
Mobile

Avocado Health introduces AI-Powered text coaching for parents

March 13, 2026
India AI Impact Summit 2026: The Global South Takes Centre Stage in Shaping the Future of AI — Mobile App Development | Design
Mobile

India AI Impact Summit 2026: The Global South Takes Centre Stage in Shaping the Future of AI — Mobile App Development | Design

March 12, 2026
Mobile AppSec in CI/CD: Implementation Guide for DevSecOps
Mobile

Mobile AppSec in CI/CD: Implementation Guide for DevSecOps

March 11, 2026
Next Post
France and parts of England experience driest July on record as new heatwave nears

France and parts of England experience driest July on record as new heatwave nears

Discussion about this post

Subscribe To Our Newsletters

    Customer Support


    1251 Wilcrest Drive
    Houston, Texas
    77042 USA
    Call-832.795.1420
    e-mail – news@theinsightpost.com

    Subscribe To Our Newsletters

      Categories

      • Africa
      • Africa-East
      • African Sports
      • American Sports
      • Arts
      • Asia
      • Australia
      • Business
      • Business Asia
      • Business- Africa
      • Canada
      • Defense
      • Education
      • Egypt
      • Energy
      • Entertainment
      • Europe
      • European Soccer
      • Finance
      • Germany
      • Ghana
      • Health
      • Insight
      • International
      • Investing
      • Japan
      • Latest Headlines
      • Life & Living
      • Markets
      • Mobile
      • Movies
      • New Zealand
      • Nigeria
      • Politics
      • Scholarships
      • Science
      • South Africa
      • South America
      • Sports
      • Tech
      • Travel
      • Travel-Africa
      • UK
      • USA
      • Weather
      • World
      No Result
      View All Result

      Recent News

      Ancient Dogs Started Diversifying 11,000 Years Ago, Long Before the Modern Breeds We Know Today

      Ancient Dogs Started Diversifying 11,000 Years Ago, Long Before the Modern Breeds We Know Today

      March 15, 2026
      Another 3 members of Iran’s women’s soccer team decide against staying in Australia as refugees

      Another 3 members of Iran’s women’s soccer team decide against staying in Australia as refugees

      March 15, 2026
      Crown Prince Reza Pahlavi ready to lead Iran transition government

      Crown Prince Reza Pahlavi ready to lead Iran transition government

      March 15, 2026
      Larkey’s Kangaroos shut off Power for convincing win

      Larkey’s Kangaroos shut off Power for convincing win

      March 15, 2026
      • Home
      • Advertise With Us
      • About Us
      • Corporate
      • Consumer Rewards
      • Forum
      • Privacy Policy
      • Social Trends

      Theinsightpost ©2026 | All Rights Reserved. Theinsightpost is an Elnegy LLC company, registered in Texas, USA

      Welcome Back!

      Login to your account below

      Forgotten Password?

      Retrieve your password

      Please enter your username or email address to reset your password.

      Log In

      Add New Playlist

      We are using cookies to give you the best experience on our website.

      You can find out more about which cookies we are using or switch them off in .

      No Result
      View All Result
      • Home
      • Insight
      • Blog
      • Business
      • Entertainment
      • Health
      • Politics
      • Shop
        • Gift Shop
        • Value Shop
        • Store
        • Bargain Shop
        • Discount
      • Sports
      • Tech
      • Travel
      • USA
      • Video
      • World
        • Asia
        • Africa
        • South America
        • North America
        • Europe
        • Oceania

      Theinsightpost ©2026 | All Rights Reserved. Theinsightpost is an Elnegy LLC company, registered in Texas, USA

      The Insight Post
      Powered by  GDPR Cookie Compliance
      Privacy Overview

      This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

      Strictly Necessary Cookies

      Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

      Cookie Policy

      More information about our Cookie Policy