All jobs

Replace Deprecated Flutter APIs Across an App and Make the Analyzer Catch the Next Ones

Yes. An agent surfaces the deprecations your analysis_options hides, replaces withOpacity, MaterialStateProperty and WillPopScope, runs the tests, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts with why the deprecations are invisible. In an app like simplezhli/flutter_deer, analysis_options.yaml is a copy of the Flutter repository's own file, with strict-casts, strict-inference and strict-raw-types on and a long linter list, but under analyzer.errors it sets deprecated_member_use: ignore and deprecated_member_use_from_same_package: ignore, a choice the comment explains was made for the framework's own tests. So flutter analyze reports a clean tree while the code calls APIs the framework has already replaced. The workflow in .github/workflows/flutter-drive.yml pins subosito/flutter-action@v2 to Flutter 3.47.4 and runs driver tests on an iOS simulator and an Android emulator plus flutter test test/accessibility_test.dart; nothing runs the analyzer in CI.

It then finds the calls. With the two ignore lines removed, the analyzer lists them, and a grep agrees: withOpacity on colours in lib/widgets/my_button.dart, lib/widgets/my_flexible_space_bar.dart, lib/goods/widgets/goods_add_menu.dart, lib/order/widgets/order_item.dart, lib/order/page/order_info_page.dart and two demo pages; MaterialStateProperty and MaterialState in my_button.dart, lib/goods/page/goods_page.dart, lib/goods/widgets/goods_sort_bottom_sheet.dart and the two order files; and WillPopScope in lib/mvp/base_page.dart, lib/home/webview_page.dart and lib/widgets/double_tap_back_exit_app.dart. The generated code under lib/generated/json and lib/l10n is already excluded from analysis and stays that way. pubspec.yaml asks for Dart >=3.4.0 and Flutter >=3.19.0, so every replacement below is available on the version the workflow installs.

Each family gets its real replacement, not a suppression. withOpacity(x) becomes withValues(alpha: x), and MaterialStateProperty, MaterialState and MaterialStateProperty.resolveWith become WidgetStateProperty, WidgetState and WidgetStateProperty.resolveWith; both are covered by Flutter's data-driven fixes, so the agent runs dart fix --dry-run first to see what the tool will do and dart fix --apply to do it, then reads the diff. WillPopScope has no automatic fix because PopScope inverts the contract: instead of an onWillPop future that returns whether to pop, it takes canPop and onPopInvokedWithResult. The agent rewrites the three by hand, and double_tap_back_exit_app.dart, the press-back-twice-to-exit widget, gets the most care: canPop: false, a handler that records the first press, shows the existing toast and calls SystemNavigator.pop on the second press inside the interval, with the behaviour described in a comment.

The proof is the analyzer and the tests, on the same Flutter the workflow uses. The agent installs Flutter 3.47.4 stable in its sandbox, runs flutter pub get, then flutter analyze --fatal-infos with the ignore lines gone to show zero issues, and flutter test over test/, which holds widget_test.dart, net/dio_test.dart and the per-module accessibility tests. It also builds the app once with flutter build web as a compile check that needs no emulator. The pull request removes the two ignore lines so the next deprecation shows up on the day it lands, and adds an analyze job to the workflow that runs the analyzer and the unit tests on Ubuntu, far cheaper than the simulator jobs that run today.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Replace the deprecated Flutter APIs in this app. Read pubspec.yaml, analysis_options.yaml and every workflow under .github/workflows first, and note that analysis_options sets deprecated_member_use to ignore and that the workflow pins a Flutter version. Install that Flutter version, remove the two ignore lines for deprecated_member_use and run flutter analyze to list every deprecation. Use dart fix --dry-run and then dart fix --apply for the families it covers, such as withOpacity to withValues and MaterialStateProperty to WidgetStateProperty, and rewrite WillPopScope to PopScope by hand, keeping the press-back-twice behaviour in double_tap_back_exit_app.dart. Run flutter analyze --fatal-infos to show zero issues, run flutter test, and run flutter build web as a compile check. Keep the ignore lines removed, add an analyze job to the workflow that runs the analyzer and unit tests on Ubuntu, and open a pull request listing every replaced call by file.",
  "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

What comes back is a pull request on its own branch with the Dart changes in one commit, the two-line edit to analysis_options.yaml in a second and the workflow job in a third, so a reviewer can take the code change alone if they want to keep the analyzer quiet for now. The Dart diff is mechanical where dart fix did the work and a few lines each where PopScope replaced WillPopScope.

The description lists every replaced call by file and old-to-new API, quotes the flutter analyze --fatal-infos summary before and after, the flutter test summary and the web build result, and explains the PopScope rewrite of the back-twice widget in a short paragraph. The transcript at GET /o/{org}/sessions/{id}/messages keeps the full analyzer output from before the fix.

Before merging, a reviewer reads the three PopScope conversions, which are the only places behaviour could change, and runs the app once on a device to press back on the home page and on the webview. Everything else is a rename the analyzer has already checked. The new workflow job will then flag the next deprecated call on the pull request that introduces it.

Run it on every terminal hand-off

A developer who just upgraded Flutter and saw the deprecation warnings scroll past starts this from the terminal with this body and the app's repository in resources, then goes back to the feature they were on. The run uses the Flutter version the workflow pins, so the analyzer output and the fixes match what CI will see.

Send a request_id, a UUID, with the body so a retried start returns the run it already began. When the turn ends, GET /o/{org}/sessions/{id} names the pull request, and a follow-up to the same session can take on the next family the analyzer reports after a later upgrade.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Deprecations in a Flutter app are a slow leak: each upgrade adds a few, the analyzer is told to look away, and one day a release removes the API and the build fails. Working through them needs the right SDK installed, dart fix run and read, and three or four hand rewrites that change control flow. An agent does that in a sandbox with the exact Flutter version, and keeps the analyzer output that proves it is at zero.

The pull request ships with the evidence a reviewer needs, the before-and-after analyzer summary and the test run, and with the one change that keeps the problem fixed: the ignore lines gone and an analyzer job in CI. Several apps can be handled at once, each in its own sandbox with its own pull request.

Frequently asked questions

Why not just leave deprecated_member_use ignored?

Because the ignore hides the list, it does not shrink it. The comment in analysis_options.yaml explains the setting was copied from the Flutter repository, where it protects thousands of framework tests; in an app it only delays the day a removed API breaks the build. The pull request removes it and makes the analyzer run in CI so new deprecations show up one at a time.

Does dart fix handle all of it?

No. dart fix applies the framework's data-driven fixes, which cover withOpacity to withValues and the MaterialState family to WidgetState. WillPopScope to PopScope is not among them because the new widget inverts the contract, so the agent rewrites those three files by hand and describes each in the pull request.

Will the back button still work the same way?

That is the one behaviour to check. double_tap_back_exit_app.dart becomes PopScope with canPop: false and a handler that shows the toast on the first press and exits on the second within the interval, which is what the onWillPop version did. The webview page keeps going back in history before popping the route. The description names both for a manual check on a device.

Does it need an emulator?

No. The analyzer, dart fix, the unit and widget tests under test/ and a flutter build web compile check all run on Linux. The driver tests that need a simulator stay in the existing workflow jobs; the new analyze job runs beside them on Ubuntu.

More Flutter jobs

The same job on other stacks

Keep reading