CI/CD helps you automatically build, test, and deliver your Flutter app. It saves time and reduces mistakes.
CI/CD for Flutter
name: flutter_ci
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: 'stable'
- run: flutter pub get
- run: flutter test
- run: flutter build apk --releaseThis example uses GitHub Actions to run CI/CD for Flutter.
It runs on every push or pull request to check and build the app.
flutter pub get flutter test flutter build apk --release
name: flutter_ci
on: push
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.7.0'
- run: flutter pub get
- run: flutter test
- run: flutter build ios --releaseThis GitHub Actions workflow runs when you push code. It checks out your code, sets up Flutter, gets packages, runs tests, and builds the Android app.
name: flutter_ci
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: 'stable'
- run: flutter pub get
- run: flutter test
- run: flutter build apk --releaseUse a CI service like GitHub Actions, GitLab CI, or Bitrise for Flutter CI/CD.
Always run tests before building to catch errors early.
For iOS builds, you need a macOS runner and proper signing setup.
CI/CD automates building and testing your Flutter app.
Use workflows to run commands like flutter pub get, flutter test, and flutter build.
This helps deliver better apps faster and with fewer mistakes.
Practice
Solution
Step 1: Understand CI/CD basics
CI/CD stands for Continuous Integration and Continuous Delivery, which automates building and testing.Step 2: Apply to Flutter context
In Flutter, CI/CD runs commands like flutter pub get, flutter test, and flutter build automatically.Final Answer:
To automate building, testing, and deploying the app -> Option AQuick Check:
CI/CD automates app build and test = A [OK]
- Thinking CI/CD is manual coding
- Confusing UI design with CI/CD
- Believing CI/CD only runs on devices
Solution
Step 1: Identify test command in Flutter
The command to run tests in Flutter isflutter test.Step 2: Differentiate from other commands
flutter build apkbuilds the app,flutter pub getfetches packages, andflutter runruns the app on a device.Final Answer:
flutter test -> Option AQuick Check:
Run tests = flutter test = A [OK]
- Using 'flutter build apk' to run tests
- Confusing 'flutter pub get' with testing
- Trying to run tests with 'flutter run'
steps:
- uses: actions/checkout@v3
- name: Install Flutter
uses: subosito/flutter-action@v2
- name: Get dependencies
run: flutter pub get
- name: Run tests
run: flutter test
- name: Build APK
run: flutter build apk --releaseWhat will happen if tests fail?
Solution
Step 1: Understand GitHub Actions default behavior
If a command likeflutter testfails, the workflow stops by default.Step 2: Apply to given steps
Since tests run before build, failure stops the workflow and APK build does not run.Final Answer:
The workflow stops and APK is not built -> Option CQuick Check:
Test failure stops workflow = D [OK]
- Assuming APK builds even if tests fail
- Thinking tests are skipped automatically
- Believing workflow retries tests
- name: Build APK run: flutter build apk --release shell: bash
But the build fails with "flutter: command not found". What is the likely cause?
Solution
Step 1: Analyze error message
"flutter: command not found" means the system cannot find the Flutter tool.Step 2: Identify missing setup
This usually happens if Flutter SDK is not installed or its path is not set in the environment before running the build.Final Answer:
Flutter SDK is not installed or not added to PATH -> Option DQuick Check:
Command not found = missing Flutter setup = C [OK]
- Blaming command syntax for 'command not found'
- Thinking shell type causes missing command
- Assuming emulator is needed for build
flutter pub get to cache packages in GitHub Actions?Solution
Step 1: Understand caching in GitHub Actions
actions/cache@v3 caches files between workflow runs to speed up repeated steps.Step 2: Apply caching to Flutter dependencies
Flutter packages are stored in ~/.pub-cache; caching this folder keyed by pubspec.yaml hash speeds up flutter pub get.Final Answer:
Use actions/cache@v3 with path ~/.pub-cache and key based on pubspec.yaml -> Option BQuick Check:
Cache ~/.pub-cache with actions/cache = B [OK]
- Running flutter clean which clears cache
- Building APK before fetching dependencies
- Uploading pubspec.yaml as artifact instead of caching
Ready to prove it?
Pass the test and this pattern moves unknown
