Skip to content

Instantly share code, notes, and snippets.

@SamTobias
Last active May 20, 2022 17:52
Show Gist options
  • Save SamTobias/99a55cb16de7babc8c4f01b3554ffc38 to your computer and use it in GitHub Desktop.
Save SamTobias/99a55cb16de7babc8c4f01b3554ffc38 to your computer and use it in GitHub Desktop.
Flutter Alternate Package Publishing

Flutter Alternate Package Publishing

Introduction

The standard way of publishing a Flutter/Dart package is publishing it publicly on pub.dev, but what if you need to create a private package to reuse code in yours apps, or if a company wants to share common code between its proprietary apps?

TL;DR

  • Same product: Keep packages in the same repository
  • Company-wide: Use different Git repositories or pay for a private package repository server

Keep in same Git repository (a.k.a. Monorepo)

The easier way is to create packages in the same repository of the app. It's very used to test a example app when creating packages and plugins. To add it to your app, just indicate the path to dependency:

dependencies:
  plugin1:
    path: ../plugin1/

Cons: To reuse packages in different apps, you would need to keep all the apps in the same repository.

Docs (flutter.dev)

Private Git repositories

You can add dependencies directly from its repositories

dependencies:
  plugin1:
    git:
      url: git://github.com/private-repository/plugin1.git

Cons: You can't use semantic versioning to keep the app updated for bugfixes and previnting major versions with breaking changes. You must reference a specific branch or tag to add a specific package version, or refer to main branch to have an always up-to-date version, which can have breaking changes.

Docs (flutter.dev)

Private package repository server

You can upload your packages privately to a package repository server

Options:

dependencies:
  plugin1:
    hosted: https://some-package-server.com
    version: ^1.4.0

Cons: It's a payed service

Docs:

Self-hosted package repository

There isn't an official way of self-hosting currently.

pub.dev repository on GitHub provide a guide to run it as a standalone server, but a recent issue says it's outdated. There's also other official repositories, pub-dartlang and pub_server, which are deprecated.

ByteDance, owner of TikTok, provides a way to self-host a pub server with unpub, "a self-hosted private Dart Pub server for Enterprise, with a simple web interface to search and view packages information." I haven't tested it yet so I can't say if it's a good option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment