Space logo

Space

The intelligent code collaboration platform

Space and SpaceCode will be discontinued on June 1, 2025. Learn more → →

How-To's

How to Use Dart and Flutter Package Repositories in Space

Read this post in other languages:

Dart and Flutter package repositories in Space

Are you worried about the security of your code? No longer want to rely on external sources for your Dart packages?

JetBrains Space offers a complete solution for private Dart package storage. Using it, you can securely store and manage your code and package dependencies, and let your team quickly access and share packages within your organization.

Whether you’re working on mobile, console, or Flutter projects, Space Packages makes it easy to store and share your Dart packages.

Read this article to discover how you can use Space Packages for your Dart or Flutter projects.

Why use Space for Dart package storage?

While Dart is currently used by only 9% of developers worldwide, Flutter, the cross-platform mobile framework built on top of Dart, is extremely popular, as confirmed by 46% of respondents to the State of Developer Ecosystem 2022 survey.

At Space, we recognize the importance of supporting popular package types and have added Dart to our list of supported packages, alongside commonly used types, including Container, Maven, NuGet, Python, Composer, npm, and even arbitrary files.

Using Space Packages as a part of the complete development platform, you will get:

  • Easy setup: You can create a private repository, or easily migrate from GitHub, GitLab, or Artifactory.
  • Packages integrated into your pipeline: Store your packages next to your source code and Automation builds, using a uniform interface, quick navigation, and a unified system of permissions.
  • More stable builds: Benefit from immutable versions, easy configurable Gradle build caches, and caching unreliable repositories.
  • Package sharing for any load: Space Packages are effective for both small teams and larger enterprises. Enjoy reasonable working time even with a high workload.

Get started for free

Store internal Dart package dependencies

You can use private Dart repositories in Space to store and share your custom packages safely, keeping your code accessible only to team members.

  1. In your Dart project in Space, create a private Dart repository. Follow this guide to learn more.
Create a Dart repository in JetBrains Space
  1. Set up a Space Automation job to publish packages to the private repository. Find more details in this guide.
job("Build, run tests, and publish") {
    container(displayName = "Run script", image = "dart:stable") {
        shellScript {
            content = """
                dart compile exe .\bin\dart_package.dart
                dart test .\test\dart_package_test.dart
                dart pub token add https://dart.pkg.jetbrains.space/acme-corp/p/my-project/my-dart-repo --env-var JB_SPACE_CLIENT_TOKEN
                dart pub publish -f
            """
        }
    }
}
  1. You can now reference packages from this private repository in your Dart projects.
Private Dart package repository in Space

Distribute Dart packages publicly

To distribute some of the internally stored packages publicly, create an additional public repository. To do so, you can use another Space repository as a target repository for publishing.

  1. Create a public Dart repository, and ensure you have selected Public access. This will be our target repository.
Distribute Dart packages publicly
  1. You now need an access token for your newly created target repository. Open it and click Get Started. You’ll see a helper window with tips on how to connect to this repository.
  2. Switch to Publish and click Generate write token. Copy the token to the clipboard.
Publish a package repository
  1. Open the Settings page of your source repository.
  2. Go to the Remote Repositories tab and add your target repository here.
Remote repositories
  1. For Authentication, choose Token and paste the token from step 3.
Create a new remote repository
  1. When you need to publish a package to the target public repository, go to the source repository, choose the package, and click Publish to remote repository.
Publish a remote repository
  1. That’s it! The package is now in the public repository.

Publish Flutter packages

The same usage scenarios apply to Flutter packages – they can be stored in the same Dart repository along with ordinary Dart packages. We’ll use the Dart package repository for storing Flutter packages as an example.

The only thing worth noting here is that there are no official Docker images for Flutter. You can either use unofficial images in your Automation builds or create your own custom image. An example of a job that uses the Flutter package manager might look like this:

job("Build, run tests, and publish") {
    container(displayName = "Run script", image = "cirrusci/flutter") {
        shellScript {
            content = """
                flutter test
                flutter pub token add https://packages.jetbrains.team/dart/p/sasmp/my-dart-repo --env-var JB_SPACE_CLIENT_TOKEN
                flutter pub publish -f
            """
        }
    }
}

The published Flutter package in a Space Packages repository will look like this:

Published Flutter package in a Space Packages repository

To view Flutter package dependencies, click on the “Dependencies” tab.

Mirror pub.dev repositories

If you use Space Automation to build your Dart projects, it makes sense to create a local mirror of pub.dev. It is a type of repository in Space Packages that works as a pull-through cache.  When a package is requested, Space first looks for the package locally and, if it’s not available, downloads it from a remote repository. Learn more.

We hope this makes it clear how Space Packages can help you manage and distribute your Dart packages more securely and efficiently. Whether you’re part of a small team or a larger enterprise, Space Packages can streamline your package management workflows and enable faster collaboration.

Get started for free

We’d love to hear your feedback on Space Dart repositories and Space Packages in general, so if there’s anything you’d like to share, please leave your comments below.

image description