# Add a Dark Theme Setting to a Flutter App from a Linear Issue

An agent finds a Flutter app already has the requested theme setting, adds no feature code, and adds 10 tests proving it saves and applies at startup.

[Run this on Rush](https://cloud.getrush.ai/run/add-dark-theme/flutter/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Before writing anything, the agent searches `lib/` for `themeMode`, `ThemeProvider` and `SpUtil`, and reads `lib/main.dart`, `pubspec.yaml` and the files under `lib/setting/`. The feature is already there: `ThemePage`, reached from the settings screen, offers 跟随系统 / 开启 / 关闭 (follow system, on, off), `ThemeProvider` saves the choice through `sp_util`, a wrapper over `shared_preferences`, and `main.dart` reads it at startup into `MaterialApp.themeMode`.

So it writes tests instead of a second implementation. `test/setting/theme_setting_test.dart` checks that `setTheme` stores each mode and notifies listeners, an unreadable value falls back to system, each saved value is applied when `MyApp` starts, and tapping each option on `ThemePage` takes effect and is saved.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "A Linear issue labeled agent says: \"Add a Dark Theme Setting to a Flutter App. Add a theme setting with system, light and dark options on the settings screen, saved with shared_preferences and applied at startup.\" Do the work in this repository, add tests for it, run flutter analyze and flutter test, and open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on simplezhli/flutter_deer at 720e8d2: 2 files changed, 96 insertions(+): `pubspec.yaml` (+2, `shared_preferences` as a dev dependency so tests can set its initial values) and a new `test/setting/theme_setting_test.dart` (+94). The issue text was written for the trial, and the run found the feature already done. The sandbox had no Flutter, so the agent installed the stable SDK 3.47.9 and `unzip` before the baseline. `flutter analyze` printed `No issues found!` before and after, and `flutter test` went from `00:30 +182 ~26: All tests passed!` to `00:32 +192 ~26: All tests passed!`.

For the reviewer: whether tests alone close the issue, or the options should read system, light and dark (and be localized) instead of the hardcoded 开启 / 关闭. The label mapping is repeated in three files, which the agent left alone.

## Run it on every Linear issue labeled agent

An automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` runs the `linear-label-to-pr` recipe's prompt when someone in your Rush org labels a settings request. An issue that asks for the options to read system, light and dark, localized, gets that instead of tests for the 跟随系统 / 开启 / 关闭 page that already exists.

## Why run it on Rush?

The honest answer to this issue was that the work was already done. The run checked before building, so the pull request adds proof instead of a parallel `ThemeMode` store, and it turns an untested feature into ten tests that fail if the startup read or the save ever breaks.

## Frequently asked questions

### Why add shared_preferences if sp_util already uses it?

It was only a transitive dependency. The tests call `SharedPreferences.setMockInitialValues`, so the agent declared it under `dev_dependencies`; the app's own dependencies are unchanged.

### Did flutter pub get change anything else?

It rewrote `macos/Flutter/GeneratedPluginRegistrant.swift` and `windows/flutter/generated_plugins.cmake`. The agent reverted both, so neither is in the diff.

## More Flutter jobs

- [Add Deep Links to a Flutter App](https://getrush.ai/run/add-deep-links/flutter/)
- [Set Up Dependabot for a Flutter App's Pub, Gradle and Actions Dependencies](https://getrush.ai/run/add-dependabot/flutter/)
- [Add Fastlane to a Flutter App](https://getrush.ai/run/add-fastlane/flutter/)

## More jobs like this: Turn a Linear label into a PR

- [Add Data-Aware Scheduling to Airflow DAGs](https://getrush.ai/run/add-data-aware-scheduling/airflow/)
- [Add Database Indexes to a Drizzle Schema from a Linear Issue](https://getrush.ai/run/add-database-indexes/drizzle/)
- [Add Missing Foreign Key Indexes With an Ecto Migration](https://getrush.ai/run/add-database-indexes/ecto/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
