Flutter is Google’s open source tookit to help create beautiful, responsive, and natively compiled applications for mobile, web and desktop.
Ready to get started? By the end of this guide, you’ll understand how to make a snap of your Flutter app that can be published in the Snap Store, showcasing it to millions of Linux users.
For a brief overview of the snap creation process, including how to install snapcraft and how it’s used, see Snapcraft overview. For a more comprehensive breakdown of the steps involved, take a look at Creating a snap.
Snaps are defined in a single YAML file placed in the root folder of your project. We’re going to an example template project, but we’ll show a more complex example later.
The following shows the entire snapcraft.yaml file super-cool-app, our simple template project:
name: super-cool-app version: '1.0' summary: Super Cool App description: Super Cool App that does everything! confinement: strict base: core18 parts: super-cool-app: plugin: flutter source: https://github.com/kenvandine/super-cool-app.git flutter-target: lib/main.dart apps: super-cool-app: command: super_cool_app extensions: [flutter-dev]
Don’t worry, we’ll break this down.
snapcraft.yaml file starts with a small amount of human-readable metadata, which usually can be lifted from the GitHub description or project README.md. This data is used in the presentation of your app in the Snap Store.
name: super-cool-app version: '1.0' summary: Super Cool App description: Super Cool App that does everything!
name must be unique in the Snap Store. Valid snap names consist of lower-case alphanumeric characters and hyphens. They cannot be all numbers and they also cannot start or end with a hyphen.
version string can be an arbitrary version, such as
1.0 in our example, or keywords such as
git, to import a version string from a git tag or commit, for instance. Versions carry no semantic meaning in snaps.
summary can not exceed 79 characters. You can use a chevron ‘>’ in the
description key to declare a multi-line description.
The next section describes the level of confinement applied to your app.
Snaps are containerised to ensure more predictable application behaviour and greater security. Unlike other container systems, the shape of this confinement can be changed through a set of interfaces. These are declarations that tell the system to give permission for a specific task, such as accessing a webcam or binding to a network port.
It’s best to start a snap with the confinement in warning mode, rather than strictly applied. This is indicated through the
devmode keyword. When a snap is in devmode, runtime confinement violations will be allowed but reported. These can be reviewed by running
Because devmode is only intended for development, snaps must be set to
strict confinement before they can be published as “stable” in the Snap Store. Once an app is working well in devmode, you can review confinement violations, add appropriate interfaces, and switch to strict confinement (our example uses strict because we know it’s working as expected).
The base keyword declares which base snap to use with your project. A base snap is a special kind of snap that provides a run-time environment alongside a minimal set of libraries that are common to most applications:
See Base snaps for more details.
Parts define what sources are needed to assemble your app. Parts can be anything: programs, libraries, or other needed assets.
parts: super-cool-app: plugin: flutter source: https://github.com/kenvandine/super-cool-app.git flutter-target: lib/main.dart
In this case, we have one: the super-cool-app source code, which is going to be built using the flutter plugin. Parts can retrieve data from local directories, remote git repositories, or tarballs, and the Flutter plugin performs all the tasks necessary to build the code.
See Environment variables for details on locations you can use from within snapcraft.yaml.
Apps are the commands and services exposed to end users. We use this section to link the binary built in the previous step, confusingly called
build, to be the super_cool_app command:
apps: super-cool-app: command: super_cool_app extensions: [flutter-dev]
If your command name matches the snap
name, users will be able run the command directly.
If the names differ, then apps are prefixed with the snap
flutter-gallery.command-name, for example). This is to avoid conflicting with apps defined by other installed snaps.
If you don’t want your command prefixed you can request an alias for it on the Snapcraft forum. These are set up automatically when your snap is installed from the Snap Store.
extensions keyword is used to easily incorporate Flutter’s common set of requirements. See Snapcraft extensions for further details.
If your application is intended to run as a service you simply add the line
daemon: simple after the command keyword. This will automatically keep the service running on install, update, and reboot.
First, make sure you’ve installed Snapcraft and create a new directory for your Flutter project.
Inside that directory, type
snapcraft init. This creates an additional subdirectory, called
snap, and inside that creates a template snapcraft.yaml file.
Edit the created snapcraft.yaml to contain the Flutter example shown earlier.
After you’ve created the snapcraft.yaml, you can build the snap by simply executing the snapcraft command in the project directory:
$ snapcraft Using 'snapcraft.yaml': Project assets will be searched for from the 'snap' directory. Launching a VM. Launched: snapcraft-super-cool-app [...] Pulling flutter-extension [...] Building super-cool-app [...] Staging flutter-extension Staging gnome-3-28-extension Staging super-cool-app Priming flutter-extension Priming gnome-3-28-extension Priming super-cool-app 'grade' property not specified: defaulting to 'stable'. Snapping | Snapped super-cool-app_1.0_amd64.snap
The build process may take some time as both Flutter and the Dart SDK from Flutter are downloaded and installed into the build environment, but they won’t be downloaded again with subsequent builds unless the environment is reset.
The resulting snap can be installed locally. This requires the
--dangerous flag because the snap is not signed by the Snap Store, or if you’re testing pre-confinement, the
--devmode flag acknowledges that you are installing an unconfined application:
$ sudo snap install super-cool-app_1.0_amd64.snap --dangerous
You can then try it out:
Removing the snap is simple too:
$ sudo snap remove super-cool-app
You now have a snap you can deploy and upload to the Snap Store. See Releasing your app for more details, and to get a deeper insight into the snap building process, start with the Snapcraft checklist.
Last updated 6 months ago. Help improve this document in the forum.