Bird
Raised Fist0
Fluttermobile~20 mins

CI/CD for Flutter - Mini App: Build & Ship

Choose your learning style10 modes available
Build: Flutter CI/CD Setup Guide
This screen guides users through setting up Continuous Integration and Continuous Deployment (CI/CD) for a Flutter app using GitHub Actions.
Target UI
-----------------------------------
| Flutter CI/CD Setup Guide         |
|---------------------------------|
| 1. Connect your GitHub repo      |
| 2. Add workflow YAML file        |
| 3. Configure build and test      |
| 4. Deploy to Firebase App Distribution |
|                                 |
| [Start Setup]                   |
-----------------------------------
Display a title and numbered steps for CI/CD setup
Include a button labeled 'Start Setup' at the bottom
When the button is tapped, show a dialog with a short explanation of GitHub Actions
Use Flutter widgets only, with clear layout and spacing
Starter Code
Flutter
import 'package:flutter/material.dart';

class CiCdSetupScreen extends StatelessWidget {
  const CiCdSetupScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter CI/CD Setup Guide'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // TODO: Add numbered steps here
            // TODO: Add Spacer and Start Setup button
          ],
        ),
      ),
    );
  }
}
Task 1
Task 2
Task 3
Task 4
Solution
Flutter
import 'package:flutter/material.dart';

class CiCdSetupScreen extends StatelessWidget {
  const CiCdSetupScreen({super.key});

  void _showInfoDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: const Text('About GitHub Actions'),
        content: const Text('GitHub Actions lets you automate your Flutter app build, test, and deployment steps whenever you push code. It helps keep your app updated and tested automatically.'),
        actions: [
          TextButton(
            onPressed: () => Navigator.of(context).pop(),
            child: const Text('Close'),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter CI/CD Setup Guide'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text('1. Connect your GitHub repo', style: TextStyle(fontSize: 18)),
            const SizedBox(height: 12),
            const Text('2. Add workflow YAML file', style: TextStyle(fontSize: 18)),
            const SizedBox(height: 12),
            const Text('3. Configure build and test', style: TextStyle(fontSize: 18)),
            const SizedBox(height: 12),
            const Text('4. Deploy to Firebase App Distribution', style: TextStyle(fontSize: 18)),
            const Spacer(),
            SizedBox(
              width: double.infinity,
              child: ElevatedButton(
                onPressed: () => _showInfoDialog(context),
                child: const Text('Start Setup'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

This screen uses a simple Column to list the four main steps for setting up CI/CD with Flutter and GitHub Actions. Each step is a Text widget with spacing in between for clarity.

The Spacer pushes the button to the bottom of the screen, making the layout clean and balanced.

The ElevatedButton triggers a dialog that briefly explains what GitHub Actions is, helping beginners understand the automation concept.

Padding around the content ensures the text and button are not too close to screen edges, improving readability and touch comfort.

Final Result
Completed Screen
-----------------------------------
| Flutter CI/CD Setup Guide         |
|---------------------------------|
| 1. Connect your GitHub repo      |
|                                 |
| 2. Add workflow YAML file        |
|                                 |
| 3. Configure build and test      |
|                                 |
| 4. Deploy to Firebase App Distribution |
|                                 |
|                                 |
| [Start Setup]                   |
-----------------------------------
Tapping 'Start Setup' opens a dialog explaining GitHub Actions automation
Dialog has a Close button to dismiss it
Stretch Goal
Add a dark mode toggle switch in the app bar to switch between light and dark themes.
💡 Hint
Use a StatefulWidget and ThemeMode to toggle themes. Add a Switch widget in the AppBar actions.

Practice

(1/5)
1. What is the main purpose of using CI/CD in Flutter app development?
easy
A. To automate building, testing, and deploying the app
B. To write Flutter code faster manually
C. To design app UI without coding
D. To run the app only on physical devices

Solution

  1. Step 1: Understand CI/CD basics

    CI/CD stands for Continuous Integration and Continuous Delivery, which automates building and testing.
  2. Step 2: Apply to Flutter context

    In Flutter, CI/CD runs commands like flutter pub get, flutter test, and flutter build automatically.
  3. Final Answer:

    To automate building, testing, and deploying the app -> Option A
  4. Quick Check:

    CI/CD automates app build and test = A [OK]
Hint: CI/CD means automate build and test steps [OK]
Common Mistakes:
  • Thinking CI/CD is manual coding
  • Confusing UI design with CI/CD
  • Believing CI/CD only runs on devices
2. Which of the following is the correct command to run Flutter tests in a CI workflow?
easy
A. flutter test
B. flutter pub get
C. flutter build apk
D. flutter run

Solution

  1. Step 1: Identify test command in Flutter

    The command to run tests in Flutter is flutter test.
  2. Step 2: Differentiate from other commands

    flutter build apk builds the app, flutter pub get fetches packages, and flutter run runs the app on a device.
  3. Final Answer:

    flutter test -> Option A
  4. Quick Check:

    Run tests = flutter test = A [OK]
Hint: Tests run with 'flutter test' command [OK]
Common Mistakes:
  • Using 'flutter build apk' to run tests
  • Confusing 'flutter pub get' with testing
  • Trying to run tests with 'flutter run'
3. Given this GitHub Actions snippet for Flutter CI:
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 --release

What will happen if tests fail?
medium
A. The workflow retries tests automatically
B. APK is built regardless of test results
C. The workflow stops and APK is not built
D. Tests are skipped and APK is built

Solution

  1. Step 1: Understand GitHub Actions default behavior

    If a command like flutter test fails, the workflow stops by default.
  2. Step 2: Apply to given steps

    Since tests run before build, failure stops the workflow and APK build does not run.
  3. Final Answer:

    The workflow stops and APK is not built -> Option C
  4. Quick Check:

    Test failure stops workflow = D [OK]
Hint: Failed test stops workflow before build [OK]
Common Mistakes:
  • Assuming APK builds even if tests fail
  • Thinking tests are skipped automatically
  • Believing workflow retries tests
4. You wrote this GitHub Actions step to build your Flutter app:
- name: Build APK
  run: flutter build apk --release
  shell: bash

But the build fails with "flutter: command not found". What is the likely cause?
medium
A. The shell should be powershell, not bash
B. The build command syntax is incorrect
C. The APK build requires emulator running
D. Flutter SDK is not installed or not added to PATH

Solution

  1. Step 1: Analyze error message

    "flutter: command not found" means the system cannot find the Flutter tool.
  2. 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.
  3. Final Answer:

    Flutter SDK is not installed or not added to PATH -> Option D
  4. Quick Check:

    Command not found = missing Flutter setup = C [OK]
Hint: Ensure Flutter SDK is installed and in PATH before build [OK]
Common Mistakes:
  • Blaming command syntax for 'command not found'
  • Thinking shell type causes missing command
  • Assuming emulator is needed for build
5. You want to speed up your Flutter CI workflow by caching dependencies. Which step should you add before flutter pub get to cache packages in GitHub Actions?
hard
A. Run flutter clean before flutter pub get
B. Use actions/cache@v3 with path ~/.pub-cache and key based on pubspec.yaml
C. Add flutter build apk before flutter pub get
D. Use actions/upload-artifact@v3 to upload pubspec.yaml

Solution

  1. Step 1: Understand caching in GitHub Actions

    actions/cache@v3 caches files between workflow runs to speed up repeated steps.
  2. 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.
  3. Final Answer:

    Use actions/cache@v3 with path ~/.pub-cache and key based on pubspec.yaml -> Option B
  4. Quick Check:

    Cache ~/.pub-cache with actions/cache = B [OK]
Hint: Cache ~/.pub-cache keyed by pubspec.yaml for faster builds [OK]
Common Mistakes:
  • Running flutter clean which clears cache
  • Building APK before fetching dependencies
  • Uploading pubspec.yaml as artifact instead of caching
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard