mojo 0.4.28

  • Installing
  • Versions
  • 4

Dart Mojo Applications #

Mojo Application API #


Application Packaging #

All Dart sources for a Mojo application are collected in a specially formatted snapshot file, which is understood by Dart's content handler in the Mojo shell. This section describes what the various parts of that package are, and how they all make it to the right place.

GN Template #

Dart Mojo applications are built with the GN template 'dart_pkg' defined in //mojo/public/dart/rules.gni. Here is an example:

dart_pkg("foo") {
  app_name_override = "dart_foo"
  app = "lib/main.dart"
  sources = [
  deps = [

mojom("foo_mojom") {
  sources = [

There are several parts. See the documentation in //mojo/public/dart/rules.gni for all the details.

pub packages #

Dart Mojo applications may use packages from the pub package repository at

The "foo" example above has uses_pub set to true. Suppose the "foo" package's pubspec.yaml is as follows:

name: foo
version: 0.0.1
description: Foo
  crypto: ">=0.9.0 <0.10.0"

The script //mojo/public/tools/git/ should be run before build time, e.g. as a "runhooks" action during gclient sync. The script traverses a directory tree looking for pubspec.yaml files. On finding one, in the containing directory, it runs pub get. This creates a "packages/" directory in the source tree adjacent to the pubspec.yaml file containing the downloaded Dart packages. pub get also creates a pubspec.lock file that locks down pub packages to specific versions. This pubspec.lock file must be checked in in order to have hermetic builds.

During the build, The dart_pkg rule looks for a "packages/" directory, and ensures that its contents are available when running the application.

Generated bindings #

The script //mojo/public/tools/bindings/generators/ and the templates under //mojo/public/tools/bindings/generators/dart_templates govern how .mojom files are compiled into Dart code.

Consider the foo.mojom file used by our example:

module foo;

struct Foo {
  int32 code;
  string? description;

This contents of this file are in the foo module. The Dart source generated for this file will end up under, e.g. //out/Debug/gen/dart- pkg/foo/lib/foo/network_error.mojom.dart, along with the other Dart sources generated for .mojom files with the "foo" DartPackage annotation in the foo module.

Resulting file #

The dart_pkg rule has two results. The first result is a Dart snapshot file zipped up into a .mojo file in the build output directory---something like //out/Release/foo.mojo. This file is understood by the Dart content handler and is suitable for deployment. The second result is a directory layout of the "foo" app that can be served by a webserver. When the URL of lib/main.dart is given to the mojo_shell, the app will be run in the Dart content handler.

They layout for our "foo" example will be the following:

//packages/crypto/...  # Dart's crypto pub package.
//packages/mojo/...  # Mojo SDK Dart libraries.

Where //packages/mojo contains Dart's Mojo bindings, //packages/crypto contains the crypto pub package, and //lib/foo/ contains the bindings generated for foo.mojom.

Mojo's Dart content handler sets the package root for a Dart application to be the packages directory. Therefore, Dart sources in this application can use the following imports:

import 'package:crypto/crypto.dart';
import 'package:foo/foo/foo.mojom.dart';
import 'package:mojo/application.dart';

0.4.28 #

MOJO_SDK: 56ddb774e386f2e021b1ac58965db050b0e5353c

0.4.27 #

MOJO_SDK: 9397aa588d55e96077c3859d4a136e4e6adf57ea

0.4.26 #

MOJO_SDK: 38c5dbd1426e105d42d6b070b8e4089c9db957eb

0.4.25 #

MOJO_SDK: ee5b33cba0face525d425d6bd8682e5de038ad73

0.4.24 #

MOJO_SDK: ff47297bfaed2660b106a67d6693343b0bc8356b

0.4.23 #

MOJO_SDK: ef5cd660ec6f1c50eaff62c81ea7662662d04e15

0.4.22 #

MOJO_SDK: f56fd59ec51e1ecdd52fb848ceff1b6b6fe7f7fa

0.4.21 #

MOJO_SDK: c200560ac45a79b61b8e8c0444af471789f5669f

0.4.20 #

MOJO_SDK: 705723c25a51b30a89b6431a6377b09e4069561e

0.4.19 #

MOJO_SDK: 7c72e53d105c346dd82cbdbeb12d9e3f0712093d

0.4.18 #

MOJO_SDK: 31c5037ab2c63649632c9f2d4227ebe6f22015a4

0.4.17 #

MOJO_SDK: 1484e831758d05c7af0f27c199d24e3bbdc6383f

0.4.16 #

MOJO_SDK: 1308cd12434c9536a28592ff09399a57ef7f4f77

0.4.15 #

MOJO_SDK: c9e15130499cc859050668ea6f78485001c96251

0.4.14 #

MOJO_SDK: b3aaccc8d9408bc645ee633e7030c605f333be95

0.4.13 #

MOJO_SDK: 2ae2bccb82f37947c69ab5d6e06c2d109690a394

0.4.12 #

MOJO_SDK: ebf435275996a69482ea342aa3ae881aecd6c90e

0.4.11 #

MOJO_SDK: 3f50c60f8af5bb485f248ceea2407a59f09caad5

0.4.10 #

0.4.9 #

0.4.8 #

0.4.7 #

0.4.6 #

0.4.5 #

0.4.4 #

0.4.3 #

0.4.2 #

0.4.1 #

0.3.2 #

0.3.1 #

0.3.0 #

0.2.1 #

0.2.0 #

0.1.0 #

0.0.25 #

0.0.23 #

0.0.22 #

0.0.18 #

0.0.17 #

0.0.16 #

0.0.15 #

0.0.14 #

0.0.13 #

0.0.12 #

0.0.11 #

0.0.10 #

0.0.8 #

  • Update version to match sky package. 0.0.7 was skipped.

0.0.6 #

  • Fix interface name capitalization bug in Dart bindings
  • Add support for interface control messages (queryVersion, requireVersion)

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  mojo: ^0.4.28

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:mojo/application.dart';
import 'package:mojo/bindings.dart';
import 'package:mojo/core.dart';
Version Uploaded Documentation Archive
0.4.28 Aug 17, 2016 Go to the documentation of mojo 0.4.28 Download mojo 0.4.28 archive
0.4.27 Jul 1, 2016 Go to the documentation of mojo 0.4.27 Download mojo 0.4.27 archive
0.4.26 Jun 28, 2016 Go to the documentation of mojo 0.4.26 Download mojo 0.4.26 archive
0.4.25 Jun 13, 2016 Go to the documentation of mojo 0.4.25 Download mojo 0.4.25 archive
0.4.24 Jun 2, 2016 Go to the documentation of mojo 0.4.24 Download mojo 0.4.24 archive
0.4.23 May 23, 2016 Go to the documentation of mojo 0.4.23 Download mojo 0.4.23 archive
0.4.22 May 18, 2016 Go to the documentation of mojo 0.4.22 Download mojo 0.4.22 archive
0.4.21 May 13, 2016 Go to the documentation of mojo 0.4.21 Download mojo 0.4.21 archive
0.4.20 May 6, 2016 Go to the documentation of mojo 0.4.20 Download mojo 0.4.20 archive
0.4.19 Apr 7, 2016 Go to the documentation of mojo 0.4.19 Download mojo 0.4.19 archive

All 34 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.