Dart/Flutter Code Style
Dart Style Guide
AppFlowy follows the official Dart Style Guide.Analysis Options
Linting rules are configured inanalysis_options.yaml:
Formatting
1
Use dartfmt
Format code with
dartfmt (built into flutter format):2
Enable format on save
In VS Code (
settings.json):Key Conventions
Naming
- Classes
- Variables
- Constants
- Private
Use
UpperCamelCase for class names:Trailing Commas
Always use trailing commas for better formatting:Prefer Final
Usefinal for variables that don’t change:
Return Types
Always declare return types explicitly:BLoC Pattern
AppFlowy uses the BLoC pattern for state management:- Events are immutable and describe actions
- States are immutable and describe UI state
- BLoCs handle business logic, not UI
Widget Structure
Organize widgets consistently:File Organization
1
One class per file
Each file should contain one main public class.
2
File naming
Use
snake_case for file names:3
Import ordering
Order imports as follows:
Comments and Documentation
- Doc comments
- Implementation comments
- TODO comments
Use
/// for public API documentation:Rust Code Style
Rust Style Guide
AppFlowy follows the official Rust Style Guide.Rustfmt Configuration
Formatting is configured inrust-lib/rustfmt.toml:
Formatting
1
Use rustfmt
Format code with
rustfmt:2
Check formatting
3
Enable format on save
In VS Code (
settings.json):Clippy Linting
Use Clippy for additional linting:CI/CD pipelines enforce Clippy warnings. Fix all warnings before submitting PRs.
Key Conventions
Naming
- Types
- Functions
- Constants
- Lifetimes
Use
UpperCamelCase for types:Error Handling
UseResult for fallible operations:
Option Handling
Prefer combinators over pattern matching:Struct Organization
Module Organization
1
File naming
Use
snake_case for module files:2
Module declaration
In
lib.rs or mod.rs:3
Import ordering
Comments and Documentation
- Doc comments
- Module docs
- Implementation comments
Use
/// for public API documentation:Async Code
Use async/await for asynchronous operations:Testing
Organize tests clearly:General Best Practices
Keep Functions Small
Functions should do one thing well. Aim for under 50 lines.
Avoid Deep Nesting
Use early returns and helper functions to reduce nesting.
Write Tests
Test new code and maintain existing test coverage.
Document Public APIs
All public functions and types should have documentation.
Pre-commit Checks
Before committing, run:- Dart/Flutter
- Rust
CI/CD Enforcement
The following checks run automatically on all PRs:- Code formatting (Dart and Rust)
- Linting (dartanalyzer, Clippy)
- Unit tests
- Integration tests
- Build verification
Next Steps
Testing
Learn about testing practices
Contributing
Contribute to AppFlowy
Architecture
Understand the architecture
Building
Build AppFlowy from source