Skip to content

[flutter_tools] Format plugin example template to match dart format#188382

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
theprantadutta:fix/plugin-example-dart-format
Jul 14, 2026
Merged

[flutter_tools] Format plugin example template to match dart format#188382
auto-submit[bot] merged 5 commits into
flutter:masterfrom
theprantadutta:fix/plugin-example-dart-format

Conversation

@theprantadutta

@theprantadutta theprantadutta commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

The plugin example app generated by flutter create -t plugin fails dart format. The example/lib/main.dart it produces contains a line that exceeds 80 columns:

platformVersion =
    await _<plugin>Plugin.getPlatformVersion() ?? 'Unknown platform version';

This comes from the plugin-hook block in templates/app/lib/main.dart.tmpl. #187443 formatted the --empty block of this same file, but the plugin-hook block was left untouched. This PR wraps the line after ?? to match dart format's output, so newly generated plugins are formatted out of the box.

I confirmed the other flutter create templates (app default + --empty, module, package, plugin_ffi) are already clean, so this is the last remaining template that failed formatting.

Fixes #175960.

Adds a regression test (has correct content and formatting with plugin template in create_test.dart) that generates a plugin and asserts every generated .dart file is already dart format-clean, mirroring the existing app and module template formatting tests.

Pre-launch Checklist

The plugin example app's main.dart, generated from the plugin-hook block
in app/lib/main.dart.tmpl, had a line exceeding 80 columns. As a result
`flutter create -t plugin` produced an example/lib/main.dart that failed
`dart format`. Wrap the line after `??` to match dart format's output.

Part of flutter#175960. Follows up on flutter#187443, which formatted the --empty app
template's main.dart in the same file.
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jun 23, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the formatting of the main.dart.tmpl template file by splitting a line containing a null-coalescing operator into two lines. There are no review comments, and I have no feedback to provide.

Generates a plugin with `flutter create -t plugin` and asserts every
generated .dart file is already formatted, mirroring the existing app and
module template formatting tests. Guards against the example app
formatting drift fixed in this PR.

Part of flutter#175960.
@theprantadutta

Copy link
Copy Markdown
Contributor Author

Added a regression test in create_test.darthas correct content and formatting with plugin template — that generates a plugin via flutter create -t plugin and asserts every generated .dart file is already dart format-clean. It mirrors the existing app template and module template formatting tests, and it guards against exactly this drift (it fails on the unformatted example app, passes with the fix). So this no longer relies on a test exemption.

@bkonyi bkonyi added the CICD Run CI/CD label Jun 29, 2026
@bkonyi
bkonyi self-requested a review June 29, 2026 15:28
@bkonyi bkonyi added the team-tool Owned by Flutter Tool team label Jun 29, 2026
@bkonyi
bkonyi requested a review from chingjun June 29, 2026 15:29
bkonyi
bkonyi previously approved these changes Jun 29, 2026
chingjun
chingjun previously approved these changes Jun 29, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 29, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 29, 2026
@auto-submit

auto-submit Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/188382, because - The status or check suite Mac_arm64 tool_tests_commands has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Linux tool_tests_commands has failed. Please fix the issues identified (or deflake) before re-applying this label.

@theprantadutta

Copy link
Copy Markdown
Contributor Author

Thanks for the approvals @bkonyi @chingjun! Looks like autosubmit got removed because Mac_arm64 tool_tests_commands failed — the same suite is green on the Windows shards and the new test is platform-independent, so this looks like a flake. Could someone re-run that shard and re-add autosubmit once it's green? Thanks!

@bkonyi

bkonyi commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@theprantadutta it looks like this is a legitimate test failure in flutter/packages/flutter_tools/test/commands.shard/permeable/create_test.dart: has correct content and formatting with plugin template. There's some code that isn't formatted correctly and is causing a test expectation to fail.

@theprantadutta
theprantadutta dismissed stale reviews from chingjun and bkonyi via 4291067 July 3, 2026 15:04
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 3, 2026
@github-actions github-actions Bot removed the team-tool Owned by Flutter Tool team label Jul 3, 2026
@theprantadutta

Copy link
Copy Markdown
Contributor Author

You're right @bkonyi, thanks for catching that — and apologies for calling it a flake earlier. The new regression test caught a real leftover: the plugin's own generated test file. templates/plugin/test/projectName_test.dart.tmpl has

final {{pluginDartClass}}Platform initialPlatform = {{pluginDartClass}}Platform.instance;

which lands at 81 columns with the test's flutter_project name, so dart format wraps it. My earlier verification missed it because I had only format-checked example/ and used a shorter project name.

Fixed in 4291067 by dropping the redundant type annotation (final initialPlatform = {{pluginDartClass}}Platform.instance;) rather than pre-wrapping — a pre-wrapped line would get rejoined by the formatter for short plugin names, so keeping the line short for any realistic name is the only shape that works on both ends. Verified locally: flutter create -t plugin flutter_projectdart format --set-exit-if-changed across the entire project (not just example/) is clean, and the previously failing has correct content and formatting with plugin template test now passes.

One heads-up while verifying: with very short names (e.g. abc) two pre-existing pre-wrapped constructs still collapse (class Mock{{pluginDartClass}}Platform with ... implements ... in this same file, and the ?? 'Unknown platform version' wrap in the example) — that's inherent to name-length-dependent wrapping and exists on master today, so I left it alone; happy to file a follow-up issue if it's worth tracking.

@bkonyi bkonyi added the CICD Run CI/CD label Jul 3, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 8, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Jul 8, 2026
bkonyi
bkonyi previously approved these changes Jul 8, 2026
@bkonyi
bkonyi requested a review from chingjun July 8, 2026 15:35
chingjun
chingjun previously approved these changes Jul 8, 2026
@bkonyi

bkonyi commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@theprantadutta there still appears to be formatting issues that are causing test failures.

@theprantadutta
theprantadutta dismissed stale reviews from chingjun and bkonyi via 1085413 July 9, 2026 15:53
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 9, 2026
@theprantadutta

Copy link
Copy Markdown
Contributor Author

Thanks for the ping @bkonyi — root-caused it from the LUCI log. The master merge rolled in a newer formatter that now separates dart:/package: import sections with a blank line, and the plugin-hook block in main.dart.tmpl was generating import 'dart:async'; directly under the material import, so the example's main.dart stopped being format-clean. Fixed in 1085413 by adding the blank line in the template (both the platform-channel and ffi variants — the template sections render adjacent to the shared material import). The rendered output now matches the formatter's own output from the failing run byte-for-byte, so the plugin template test should go green on the next CI run.

@bkonyi bkonyi added the CICD Run CI/CD label Jul 10, 2026
@bkonyi
bkonyi requested a review from chingjun July 14, 2026 15:47
@chingjun chingjun added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 14, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jul 14, 2026
Merged via the queue into flutter:master with commit 8428a40 Jul 14, 2026
172 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 14, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jul 15, 2026
flutter/flutter@846664b...fc1ad95

2026-07-15 [email protected] [iOS] Migrate FlutterKeyboardInsetManager to Swift (flutter/flutter#189425)
2026-07-15 [email protected] Roll Dart SDK from 05bf153370c4 to 0c408ff6dce9 (4 revisions) (flutter/flutter#189487)
2026-07-15 [email protected] Implement UberSDF lines to replace LineContents-based AA lines (flutter/flutter#188514)
2026-07-15 [email protected] Fix stale eagerWinner reference in GestureArenaManager when rejected before arena close (flutter/flutter#187008)
2026-07-15 [email protected] Disable some Windows tests that are flaking on CI (flutter/flutter#189477)
2026-07-15 dmgr Added unified check-run user manual (flutter/flutter#189453)
2026-07-15 [email protected] Roll Skia from 88954ef8f36d to ab2410bc857c (9 revisions) (flutter/flutter#189474)
2026-07-14 [email protected] [agents] Refactor shepherd-prs skill into a pure Markdown runbook using native gh CLI (flutter/flutter#189095)
2026-07-14 [email protected] Add missing name to mirroring workflow (flutter/flutter#189439)
2026-07-14 [email protected] Add support for WASM deferred loading. (flutter/flutter#189308)
2026-07-14 [email protected] fix `templateDefaultGradleVersion` todo (flutter/flutter#189466)
2026-07-14 [email protected] Roll Fuchsia Linux SDK from oOETA0ISPouDt2xBo... to lLFbh5kFWbUGgC9Ek... (flutter/flutter#189469)
2026-07-14 [email protected] Use ServicesBinding.instance.exitApplication instead of exit(0) in multiple_windows example (flutter/flutter#189364)
2026-07-14 [email protected] Add CpuArch to the Device class (flutter/flutter#189207)
2026-07-14 [email protected] Fix space formatting in cherry-pick label for flutter_cp.dart (flutter/flutter#189463)
2026-07-14 [email protected] Roll pub packages (flutter/flutter#189454)
2026-07-14 [email protected] [flutter_tools] Format plugin example template to match dart format (flutter/flutter#188382)
2026-07-14 [email protected] Move renamed x64->ARM benchmarks out of bringup (flutter/flutter#189400)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure Flutter's templates use the latest dart format

3 participants