2019-08-13 17:11:30 +07:00
# flutter-action
2026-03-18 15:40:24 +01:00
Flutter environment for use in GitHub Actions.
It works on Linux, Windows, and macOS.
2019-08-13 17:11:30 +07:00
2024-12-03 19:58:13 +01:00
Originally created by [Alif Rachmawadi]. Maintained by [Bartek Pacia].
2024-03-31 17:24:22 +01:00
The following sections show how to configure this action.
2024-04-01 04:03:05 +02:00
## Specifying Flutter version
2019-08-13 17:11:30 +07:00
2024-04-01 04:03:05 +02:00
### Use specific version and channel
2022-01-06 09:55:43 +00:00
2019-08-13 17:11:30 +07:00
```yaml
steps:
2024-03-31 19:30:30 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
2024-04-01 04:03:05 +02:00
channel: stable
2024-03-31 19:30:30 +02:00
flutter-version: 3.19.0
2024-04-01 04:03:05 +02:00
- run: flutter --version
```
2026-03-18 13:18:09 +00:00
### Use version from pubspec.yaml or FVM config
2024-04-01 04:03:05 +02:00
This is inspired by [`actions/setup-go` ](https://github.com/actions/setup-go ).
```yaml
steps:
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-04-01 04:03:05 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
2024-03-31 19:30:30 +02:00
channel: stable
2026-03-18 13:18:09 +00:00
flutter-version-file: pubspec.yaml # path to pubspec.yaml or .fvmrc or .fvm/fvm_config.json
2024-03-31 19:30:30 +02:00
- run: flutter --version
2020-04-09 14:40:15 +02:00
```
2024-04-01 04:03:05 +02:00
> [!IMPORTANT]
>
> For `flutter-version-file` to work, you need to have the exact Flutter version
> defined in your pubspec.yaml:
>
> **Good**
>
> ```yaml
> environment:
> sdk: ">=3.3.0 <4.0.0"
> flutter: 3.19.0
> ```
>
> **Bad**
>
> ```yaml
> environment:
> sdk: ">=3.3.0 <4.0.0"
> flutter: ">= 3.19.0 <4.0.0"
> ```
2024-12-03 20:05:47 +01:00
> [!NOTE]
2024-04-01 04:03:05 +02:00
>
2024-04-01 04:09:25 +02:00
> Using `flutter-version-file` requires [`yq`](https://github.com/mikefarah/yq),
2026-03-18 15:40:24 +01:00
> which is not pre-installed in `windows` runners.
> This action installs `yq` automatically if `flutter-version-file` is specified,
> so no action is required from you.
2020-04-09 14:40:15 +02:00
2024-04-01 04:07:29 +02:00
### Use latest release for particular channel
2020-04-09 14:40:15 +02:00
```yaml
steps:
2024-03-31 19:30:30 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable # or: beta, master (or main)
- run: flutter --version
2020-04-09 14:40:15 +02:00
```
2024-04-01 04:03:05 +02:00
### Use latest release for particular version and/or channel
2020-06-19 16:13:08 +02:00
```yaml
2021-04-26 14:24:54 +00:00
steps:
2024-03-31 19:30:30 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: dev
2024-04-01 04:03:05 +02:00
flutter-version: 1.22.x
2024-03-31 19:30:30 +02:00
- run: flutter --version
2020-06-19 16:13:08 +02:00
```
2024-04-01 04:03:05 +02:00
### Use particular version on any channel
2020-11-25 14:07:49 +05:00
```yaml
2021-04-26 14:56:05 +00:00
steps:
2024-03-31 19:52:05 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: any
2024-04-01 04:03:05 +02:00
flutter-version: 3.x
2024-03-31 19:30:30 +02:00
- run: flutter --version
2020-11-25 14:07:49 +05:00
```
2024-04-01 04:03:05 +02:00
### Use particular git reference on master channel
2023-10-11 10:55:21 +02:00
```yaml
steps:
2024-03-31 19:52:05 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: master
2024-04-01 04:03:05 +02:00
flutter-version: 5b12b74 # tag, commit or branch
2024-03-31 19:30:30 +02:00
- run: flutter --version
2023-10-11 10:55:21 +02:00
```
2025-06-10 15:21:26 +08:00
### Use a Flutter mirror by set ENV
You can get more infomation from [Flutter official docs ](https://docs.flutter.dev/community/china ).
```yaml
steps:
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2025-06-10 15:21:26 +08:00
- name: Set up Flutter
env:
FLUTTER_STORAGE_BASE_URL: https://storage.flutter-io.cn
uses: subosito/flutter-action@v2
with:
channel: master
flutter-version: 5b12b74 # tag, commit or branch
- run: flutter --version
```
2024-12-03 21:04:13 +01:00
### Use alternative Flutter repository
This action supports "alternative Flutters" in addition to the official
[`flutter/flutter` ](https://github.com/flutter/flutter ), for example:
2025-03-24 21:47:02 +01:00
- [Flock ](https://github.com/join-the-flock/flock.git )
2026-03-18 15:40:24 +01:00
- [a Flutter fork that supports HarmonyOS ](https://gitee.com/harmonycommando_flutter/flutter.git )
2024-12-03 21:04:13 +01:00
```yaml
steps:
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-12-03 21:04:13 +01:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: master
flutter-version: 3.24.0
2025-03-24 21:47:02 +01:00
git-source: https://github.com/join-the-flock/flock.git
2024-12-03 21:04:13 +01:00
- run: flutter --version
```
### Apply a patch
2026-03-18 15:40:24 +01:00
Sometimes you find a bug in Flutter and fix it yourself (you're a rockstar!),
and then submit a patch/PR to Flutter repository.
However, everyone knows that code review takes time, but your app needs the fix _ now _ .
2024-12-03 21:04:13 +01:00
You can apply your patch like this:
```yaml
steps:
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-12-03 21:04:13 +01:00
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.22.2
channel: stable
- run: |
flutter --version
cd ${{ env.FLUTTER_ROOT }}
curl https://patch-diff.githubusercontent.com/raw/flutter/flutter/pull/137874.patch | git apply
git status
```
2024-12-03 21:06:22 +01:00
> [!NOTE]
2024-12-03 21:04:13 +01:00
>
> This was first discussed in [this issue](https://github.com/subosito/flutter-action/issues/310).
## Build targets
2024-03-31 17:24:22 +01:00
Build **Android ** APK and app bundle:
2019-08-16 19:02:42 +07:00
```yaml
steps:
2024-03-31 19:30:30 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
2024-12-03 21:04:13 +01:00
flutter-version: 3.24.0
2024-03-31 19:30:30 +02:00
- run: flutter pub get
- run: flutter test
- run: flutter build apk
- run: flutter build appbundle
2019-08-16 19:02:42 +07:00
```
2024-04-01 04:03:05 +02:00
### Build for iOS
> [!NOTE]
>
> Building for iOS requires a macOS runner.
2021-04-26 14:56:05 +00:00
```yaml
jobs:
2024-03-31 19:30:30 +02:00
main:
2021-04-26 14:56:05 +00:00
runs-on: macos-latest
steps:
2024-03-31 19:30:30 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
- run: flutter pub get
- run: flutter test
- run: flutter build ios --release --no-codesign
2021-04-26 14:56:05 +00:00
```
2024-04-01 04:03:05 +02:00
### Build for the web
2019-08-16 19:02:42 +07:00
```yaml
steps:
2024-03-31 19:30:30 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
2024-04-01 04:03:05 +02:00
channel: stable
2024-03-31 19:30:30 +02:00
- run: flutter pub get
- run: flutter test
- run: flutter build web
2021-04-26 14:56:05 +00:00
```
2024-04-01 04:03:05 +02:00
### Build for Windows
2021-04-26 14:56:05 +00:00
```yaml
2022-01-06 09:55:43 +00:00
jobs:
2024-03-31 19:30:30 +02:00
main:
runs-on: windows-latest
steps:
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
- run: flutter build windows
2019-08-16 19:02:42 +07:00
```
2024-04-01 04:03:05 +02:00
### Build for Linux desktop
2022-01-06 11:16:06 +00:00
```yaml
jobs:
2024-03-31 19:30:30 +02:00
main:
runs-on: ubuntu-latest
steps:
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
- run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build libgtk-3-dev
- run: flutter build linux
2022-01-06 11:16:06 +00:00
```
2024-04-01 04:03:05 +02:00
### Build for macOS desktop
> [!NOTE]
>
> Building for macOS requires a macOS runner.
2022-01-06 11:16:06 +00:00
```yaml
jobs:
2024-03-31 19:30:30 +02:00
main:
runs-on: macos-latest
steps:
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
2024-04-01 04:03:05 +02:00
channel: stable
2024-03-31 19:30:30 +02:00
- run: flutter build macos
2022-01-06 11:16:06 +00:00
```
2024-03-31 17:24:22 +01:00
## Caching
2024-03-31 19:30:30 +02:00
Integration with [`actions/cache` ](https://github.com/actions/cache ):
2022-01-07 04:47:25 +00:00
2026-03-16 16:24:34 +08:00
> [!IMPORTANT]
2026-03-18 17:23:45 +01:00
> `subosito/flutter-action` now uses `actions/cache@v5` internally.
> If you use self-hosted runners, make sure they are updated
> to Actions Runner `2.327.1` or newer before enabling cache support.
2026-03-16 16:24:34 +08:00
2022-01-07 04:47:25 +00:00
```yaml
steps:
2024-03-31 19:30:30 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
# optional parameters follow
2026-03-18 15:31:10 +01:00
pub-cache: true # optional, defaults to empty (falls back to cache value for backward compatibility)
2024-03-31 19:30:30 +02:00
cache-key: "flutter-:os:-:channel:-:version:-:arch:-:hash:" # optional, change this to force refresh cache
cache-path: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:" # optional, change this to specify the cache path
2025-06-24 14:50:48 -07:00
pub-cache-key: "flutter-pub-:os:-:channel:-:version:-:arch:-:hash:" # optional, change this to force refresh cache of dart pub get dependencies
2024-03-31 19:30:30 +02:00
pub-cache-path: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:" # optional, change this to specify the cache path
- run: flutter --version
2022-01-07 04:47:25 +00:00
```
2022-07-25 19:35:02 +07:00
2026-03-18 15:31:10 +01:00
> [!NOTE]
>
2026-03-18 17:23:45 +01:00
> **The `cache` and `pub-cache` inputs are independent and control different caches:**
> - `cache: true/false` - controls whether to cache the Flutter SDK installation
> - `pub-cache: true/false` - controls whether to cache the pub dependencies
2026-03-18 15:31:10 +01:00
>
> **Backward Compatibility:** When `pub-cache` is not specified (empty), it falls back to the `cache` value.
2026-03-18 17:23:45 +01:00
> This means existing workflows with `cache: true` automatically cache both Flutter SDK and pub dependencies.
2026-03-18 15:31:10 +01:00
>
> You can use them in any combination:
2026-03-18 17:23:45 +01:00
> - Both enabled: `cache: true` (`pub-cache` defaults to true for backward compatibility)
2026-03-18 15:31:10 +01:00
> - Both enabled explicitly: `cache: true` and `pub-cache: true`
> - Only Flutter SDK: `cache: true` and `pub-cache: false`
> - Only pub dependencies: `cache: false` and `pub-cache: true` for self-hosted runners
> - Neither: `cache: false` and `pub-cache: false` (or omit both)
2024-03-31 19:30:30 +02:00
Note: `cache-key` , `pub-cache-key` , and `cache-path` have support for several
dynamic values:
2022-07-25 19:35:02 +07:00
- `:os:`
- `:channel:`
- `:version:`
2022-07-26 12:08:35 +07:00
- `:arch:`
2022-07-25 19:35:02 +07:00
- `:hash:`
- `:sha256:`
2022-09-08 08:41:22 +07:00
2025-06-24 14:41:32 -07:00
### Using cache outputs
> [!NOTE]
2026-03-16 16:24:34 +08:00
> `PUB-CACHE-HIT` and `CACHE-HIT` directly use the `cache-hit` output from `actions/cache@v5`, which is the following:
2025-06-24 14:41:32 -07:00
> - `cache-hit` - A string value to indicate an exact match was found for the key.
> - If there's a cache hit, this will be 'true' or 'false' to indicate if there's an exact match for `key`.
> - If there's a cache miss, this will be an empty string.
2026-03-16 16:24:34 +08:00
Example usage (inspired by [actions/cache@v5 ](https://github.com/actions/cache/blob/v5/README.md#skipping-steps-based-on-cache-hit ) and [#346 ](https://github.com/subosito/flutter-action/pull/346 )) to skip `melos bootstrap` if there was a pub cache hit:
2025-06-24 14:41:32 -07:00
2026-03-18 15:40:24 +01:00
```yaml
2025-06-24 14:41:32 -07:00
steps:
- name: Checkout repository
2026-03-18 15:40:24 +01:00
uses: actions/checkout@v6
2025-06-24 14:41:32 -07:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
id: flutter-action
with:
channel: stable
cache: true
- name: Conditionally run melos bootstrap
if: steps.flutter-action.outputs.PUB-CACHE-HIT != 'true'
run: melos bootstrap
- name: Continue with build
run: flutter build apk
```
## Outputs
2022-09-08 08:41:22 +07:00
Use outputs from `flutter-action` :
```yaml
steps:
2024-03-31 19:30:30 +02:00
- name: Clone repository
2026-03-18 15:40:24 +01:00
- uses: actions/checkout@v6
2024-03-31 19:30:30 +02:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
id: flutter-action
with:
channel: stable
2024-04-01 04:03:05 +02:00
- name: Print outputs
shell: bash
run: |
2024-03-31 19:30:30 +02:00
echo CACHE-PATH=${{ steps.flutter-action.outputs.CACHE-PATH }}
echo CACHE-KEY=${{ steps.flutter-action.outputs.CACHE-KEY }}
echo CHANNEL=${{ steps.flutter-action.outputs.CHANNEL }}
echo VERSION=${{ steps.flutter-action.outputs.VERSION }}
echo ARCHITECTURE=${{ steps.flutter-action.outputs.ARCHITECTURE }}
echo PUB-CACHE-PATH=${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
echo PUB-CACHE-KEY=${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}
2025-06-24 14:41:32 -07:00
echo CACHE-HIT=${{ steps.flutter-action.outputs.CACHE-HIT }}
echo PUB-CACHE-HIT=${{ steps.flutter-action.outputs.PUB-CACHE-HIT }}
2022-09-08 08:41:22 +07:00
```
2024-04-01 04:07:29 +02:00
2024-04-02 21:25:52 +09:00
If you don't need to install Flutter and just want the outputs, you can use the
`dry-run` option:
```yaml
steps:
- name: Clone repository
2026-03-18 15:40:24 +01:00
- uses: actions/checkout@v6
2024-04-02 21:25:52 +09:00
- name: Set up Flutter
uses: subosito/flutter-action@v2
id: flutter-action
with:
channel: stable
dry-run: true
- run: |
echo CACHE-PATH=${{ steps.flutter-action.outputs.CACHE-PATH }}
echo CACHE-KEY=${{ steps.flutter-action.outputs.CACHE-KEY }}
echo CHANNEL=${{ steps.flutter-action.outputs.CHANNEL }}
echo VERSION=${{ steps.flutter-action.outputs.VERSION }}
echo ARCHITECTURE=${{ steps.flutter-action.outputs.ARCHITECTURE }}
echo PUB-CACHE-PATH=${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
echo PUB-CACHE-KEY=${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}
2025-06-24 14:41:32 -07:00
echo CACHE-HIT=${{ steps.flutter-action.outputs.CACHE-HIT }}
echo PUB-CACHE-HIT=${{ steps.flutter-action.outputs.PUB-CACHE-HIT }}
2024-04-02 21:25:52 +09:00
shell: bash
```
2025-06-24 14:41:32 -07:00
2025-06-24 23:48:20 +02:00
[Alif Rachmawadi]: https://github.com/subosito
[Bartek Pacia]: https://github.com/bartekpacia