Solved by OnePub

Here we try to detail some of the common problems encountered in Dart/Flutter development and how you can use OnePub to solve them.

A single place for your team to find packages

Like most of us, you probably store you code in a git repo such as GitHub.

To reduce code duplication you need to make it easy for team members to find and use the code and its documentation.

The likes of GitHub doesn't make this terribly easy.

The OnePub search is designed specifically for searching Dart packages. Publishing a package on OnePub makes it easy to find and trivial to add as a dependency.

onepub pub add <my private package>

No more screwing around with git branch references that go stale! Using OnePub, means that running 'dart pub upgrade' will automatically find the latest package version.

A common home for API documentation

Like pub.dev, when you publish a private package to OnePub we generate and host your API documentation for your whole team.

Search for your package in OnePub and click the 'api reference' link to go to the documentation.

Watch for package updates

Added a watch to a public or private package to receive an email notification each time a new version of the package is published to OnePub or pub.dev!

Share code between my own projects

Often you have code that you need to share between a number of your own projects.

You can solve this problem by using a 'path' dependency, a 'git' dependency or even a mono-repo, but each of these has shortcomings and requires significant additional management overhead and in some cases constant tweaking of your pubspec.yaml depending on what actions you are performing.

The OnePub solution is;

Move the shared code into its own Dart package.

It's often best to create a series of small packages rather than a swiss army knife.

Publish the new code you want to share:

cd mysharingproject
onepub pub private
flutter pub publish

Now you have shared your code, you can add a dependency from any other project.

cd myotherproject
onepub pub add mysharingproject
flutter pub get

And that's it.

Share code with teammates

This is of course a core reason for using OnePub.

The process to share your code with teammates is exactly the same as for sharing code between projects.

cd mysharedproject
onepub pub private
flutter pub publish

You will of course need to invite your colleagues to OnePub - invite a colleague

To use your published package, your colleague needs to:

flutter pub global activate onepub
onepub login
cd teammatesproject
onepub pub add mysharedproject
flutter pub get

Patch a public package/Vendor a package

The Dart ecosystem has 10 of thousands of packages, however, not all of them are perfectly maintained. Sometimes you might need to patch a public package and you just can't wait for the maintainer to release and update.

The answer is to create your own private version of the package. Once the maintainer publishes the official version you can revert back to the public version of the package.

To create your own private version:

  • Fork the existing public package and clone it to your machine.

  • Make any necessary changes to the code.

  • Publish the code to OnePub.

You can use the existing package name as OnePub resolves conflicts.

git clone <some public package>
cd <some public package>
onepub pub private
flutter pub publish

You now have your own private version of the package. You and your colleagues can now use the private version until the new public one has been released.

To add a dependency on the private version of the package.

cd myproject
onepub pub add <some public package>
flutter pub get

OnePub will update the dependency to point to your private version of the package.

We strongly recommend that you run the unit tests of the public package to ensure that the unpublished version isn't broken in some way.

Fix 'version solving failed'

One of the most frustrating issues when adding dependency with Dart is the classic 'DLL hell' problem. With Dart, this problem is revealed by the dreaded 'version solving failed'.

Version solving fails, when you depend on two packages that both depend on different versions of a transient dependency.

You should start by contacting the package maintainers and ask them to publish a new release with more up to date dependencies.

Failing that or whilst you are waiting, you can vendor your own copy of one or more dependencies.

In a similar fashion as the above 'Patch a Public Package' section, we are going to update a package dependency of a public package and publish our own private version until the maintainer releases an updated version.

To create your own private version:

  • Fork the existing public package and clone it to your machine.

  • Update the set of dependencies (read up on dart pub upgrade command).

  • Publish the code to OnePub.

You can use the existing package name as OnePub resolves conflicts.

git clone <some public package>
cd <some public package>
onepub pub private
flutter pub publish

To add a dependency on the private version of the package.

cd myproject
onepub pub add <some public package>
flutter pub get

OnePub will update the dependency to point to your private version of the package.

We strongly recommend that you run the unit tests of the public package to ensure that the unpublished version isn't broken in some way.

You could also raise a PR against the original package to help the maintainer out.

Create a CLI toolkit

At OnePub, we use the DCli console SDK for Dart to automate our development and production environments.

Using OnePub we publish the CLI apps we build with DCli to our private OnePub repository.

Now any of out team can install our CLI tooling with a single command:

onepub pub global activate <name of cli tool>

Building and deploying CLI tooling with DCli and OnePub is easy:

dart pub global activate dcli
dcli install
dcli create --template=full mycliapp

The dcli create command creates a sample CLI app which you can modify to do something useful.

A single Dart project can contain multiple CLI apps.

To publish your CLI project add an executables section to your pubspec.yaml, listing each dart script in your project's bin directory.

Now publish your project to OnePub

onepub pub private
dart pub publish

Now any of you team can activate your CLI tooling via:

dart pub global activate onepub
onepub login
onpub pub global activatate mycliapp

The global activate adds the Dart libraries listed in your pubspec.yaml's exectuables section to the PATH.

If you mycliapp package has a library called bin/start_mysql.dart then you can now run the script by typing:

start_mysql

Last updated