Skip to content

Commit 67ecae8

Browse files
GCA for GitHub config (#2334)
Configuring GCA for GitHub with a styleguide that makes sense for Codelabs. I think. ## Pre-launch Checklist - [x] I read the [Effective Dart: Style] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Effective Dart: Style]: https://dart.dev/guides/language/effective-dart/style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
1 parent 1442a00 commit 67ecae8

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

.gemini/config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Minimize verbosity.
2+
have_fun: false
3+
code_review:
4+
# For now, use the default of MEDIUM for testing. Based on desired verbosity,
5+
# we can change this to LOW or HIGH in the future.
6+
comment_severity_threshold: MEDIUM
7+
pull_request_opened:
8+
# Explicitly set help to false in case the default changes in the future, as
9+
# having a help message on every PR would be spammy.
10+
help: false
11+
# These tend to be verbose, and since we expect PR authors to clearly
12+
# describe their PRs this would be at best duplicative.
13+
summary: false

.gemini/styleguide.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Flutter Codelabs repository
2+
3+
This repository contains the code for Flutter codelabs. Each project has a copy
4+
of a project at multiple different steps of the codelab.
5+
6+
## Coding standards
7+
8+
### Formatting & Style
9+
10+
* **`dart format`**: The official Dart formatter is the standard. Most IDEs can be configured to run this automatically on save.
11+
* **Line Length**: While the default is 80 characters, many projects use up to 120. Consistency is key.
12+
* **Trailing Commas**: Use trailing commas on the last item in a parameter or argument list. This improves readability and makes for cleaner version control diffs.
13+
* **Linter**: The `flutter_lints` package is the official linter. It helps enforce style, identify potential errors, and improve code quality. It should be included in your `pubspec.yaml`.
14+
15+
### Naming Conventions
16+
17+
* **`UpperCamelCase`**: For classes, enums, typedefs, and extensions.
18+
* **`lowerCamelCase`**: For variables, constants, methods, and parameters.
19+
* **`snake_case`**: For files, directories, and packages.
20+
* **Private Members**: Use a leading underscore (`_`) for private members of a library (e.g., `_myPrivateVariable`).
21+
22+
### Code Organization
23+
24+
* **DRY (Don't Repeat Yourself)**: Abstract reusable code into widgets, functions, or classes.
25+
* **Split Large Widgets**: Break down large `build` methods into smaller, more manageable widgets. This improves readability and performance.
26+
* **Directory Structure**: A common and effective structure is to separate code by feature or layer:
27+
* `lib/src`: For internal library code.
28+
* `lib/src/models`: Data classes.
29+
* `lib/src/widgets` or `lib/src/views`: UI components.
30+
* `lib/src/controllers` or `lib/src/blocs`: Business logic.
31+
* `lib/src/services`: API clients, database access, etc.
32+
33+
### Widget Best Practices
34+
35+
* **`const` is King**: Use `const` for widgets and constructors whenever possible. This is a significant performance optimization, as it prevents unnecessary widget rebuilds.
36+
* **`StatelessWidget` vs. `StatefulWidget`**: Prefer `StatelessWidget` unless you have mutable state that changes over the lifetime of the widget.
37+
* **`ListView.builder`**: For long or dynamic lists, always use `ListView.builder` to ensure that only the visible items are built and rendered.
38+
* **Conditional Rendering**: Use collection `if` for conditionally including a widget in a list of children.
39+
40+
### State Management
41+
42+
* While Flutter offers `setState` for local state, for app-level state it's recommended to use a dedicated state management solution like Provider, BLoC, or Riverpod.
43+
* The key principle is to separate UI from business logic.
44+
45+
### General Dart Best Practices
46+
47+
* **Type Safety**: Avoid `dynamic` when possible. Use strong typing. Use `is` for type checking and avoid `as` to prevent runtime exceptions.
48+
* **Tear-offs**: If you're calling a function with the same arguments, you can "tear-off" the method instead of creating a new lambda. For example, use `myList.forEach(print)` instead of `myList.forEach((item) => print(item))`.
49+
50+
These standards are widely adopted in the Flutter community and are a great starting point for any project. For more in-depth information, the official [Effective Dart](https://dart.dev/effective-dart) guide is an excellent resource.

0 commit comments

Comments
 (0)