flutter_flutter/.gemini/styleguide.md
Jenn Magder b2cc192a31
Add Gemini Code Assist review config and style guide (#172785)
- Initial config files for [Gemini Code Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
These config files are modified versions of the one already added to the
flutter/packages repo: https://github.com/flutter/packages/pull/9632
based on [the official
docs](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
- Style guide has links to various contributing docs and style guides.
- Ignore paths associated with version pins and third_party to avoid
reviews on rolls and code that doesn't need modification. See
https://github.com/flutter/packages/pull/9647.
- Add a note to the PR template to provide some notice/guidance to
contributors about how to use automated feedback, to clarify the role of
the automated reviews and hopefully minimize potential issues in case
the bot leaves incorrect feedback. This is a direct copy of the comment
introduced in https://github.com/flutter/packages/pull/9632.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-07-28 18:05:22 +00:00

4.5 KiB

Flutter Style Guide

This style guide outlines the coding conventions for contributions to the flutter/flutter repository. It is based on the more comprehensive official style guide for the Flutter repository.

Best Practices

General Philosophy

  • Optimize for readability: Code is read more often than it is written.
  • Avoid duplicating state: Keep only one source of truth.
  • Write what you need and no more, but when you write it, do it right.
  • Error messages should be useful: Every error message is an opportunity to make someone love our product.

Dart Formatting

  • All Dart code is formatted using dart format. This is enforced by CI.
  • Constructors come first in a class definition, with the default constructor preceding named constructors.
  • Other class members should be ordered logically (e.g., by lifecycle, or grouping related fields and methods).

Miscellaneous Languages

Documentation

  • All public members should have documentation.
  • Answer your own questions: If you have a question, find the answer, and then document it where you first looked.
  • Avoid useless documentation: If the documentation just repeats the member's name, it's useless. Explain the why and the how.
  • Introduce terms: Don't assume the reader knows everything. Link to definitions.
  • Provide sample code: Use {@tool dartpad} for runnable examples.
  • Provide illustrations or screenshots for widgets.
  • Use /// for public-quality documentation, even on private members.

Further Reading

For more detailed guidance, refer to the following documents: