git:20260331.a8cec9f to git:20260401.b1f912e

41 added, 50 removed. Audit A to A.

What this update changes in the checks

No check changed: every fixed check gives the same answer before and after this update.

A tripped check is a label, not a verdict: read the matched text and the lines below. This week's updates that newly trip a check.

---
- name: "effective-dart"
+ name: "applying-effective-dart"
description: "Dart 3 modern features and Effective Dart best practices including records, patterns, sealed classes, and extension types. Use when adopting Dart 3 syntax, improving code quality, or reviewing Dart code conventions."
metadata:
- last_modified: "2026-03-12 11:18:17 (GMT+8)"
+ last_modified: "2026-04-01 14:35:00 (GMT+8)"
---
# Dart 3 Latest Features and Effective Dart Best Practices Guide
## Goal
- This document amalgamates the powerful latest features of `Dart 3` with official `Effective Dart` best practices, equipping you with a comprehensive guide for writing highly efficient, safe, and maintainable Dart code.
+ Covers Dart 3 features and Effective Dart practices for writing safe, maintainable code.
## Instructions
- ### 1. Core Focus: Dart 3 Latest Features and Application Best Practices
- Dart 3 introduces numerous revolutionary syntax and type system upgrades, strictly enforcing Sound Null Safety comprehensively.
+ ### 1. Dart 3 Features
#### 1.1 Records
- Records permit the aggregation of multiple values of diverse types into a single object without the necessity of declaring a dedicated Class.
+ Records aggregate multiple typed values without requiring a dedicated class.
* **Best Practices**:
- * **Multiple Return Values**: When a function needs to return multiple values, prioritize Records rather than constructing throwaway wrapper classes (Data Classes).
- * **Named Fields**: When returning more than two values or when semantics are ambiguous, utilize named fields to elevate readability.
+ * **Multiple Return Values**: Prefer Records over throwaway wrapper classes.
+ * **Named Fields**: Use named fields when returning more than two values or when semantics are ambiguous.
```dart
// ✅ Recommended Usage
({double lat, double lon}) getLocation(String city) {
return (lat: 25.0330, lon: 121.5654);
}
```
#### 1.2 Patterns and Destructuring
- Patterns can scrutinize and synchronously destructure data, drastically simplifying attribute extraction from Records, Lists, Maps, and custom objects.
+ Patterns match and destructure data from Records, Lists, Maps, and custom objects.
* **Best Practices**:
- * **Destructuring during variable declaration**: If you need to extract values from a Record or List, destructure them directly upon declaration.
- * **Replacing complex if statements**: Employ the `if-case` syntax to concurrently validate formatting and extract variables.
+ * **Destructuring on declaration**: Extract values from Records or Lists directly at assignment.
+ * **Replace complex if-statements**: Use `if-case` to validate shape and extract variables simultaneously.
```dart
// ✅ Recommended Usage
final json = {'user': ['Zack', 25]};
if (json case {'user': [String name, int age]}) {
print('User $name is $age years old.');
}
```
#### 1.3 `switch` Expressions and Exhaustive Checking
- Dart 3 introduces `switch` expressions (superseding portions of switch statements) and provides compile-time exhaustive checking for specific types (e.g., `sealed` classes, Enums).
+ `switch` expressions return values and provide compile-time exhaustiveness for sealed classes and enums.
* **Best Practices**:
- * **Assignment as an expression**: When you need to return diverging values based on different conditions, use Switch expressions to make the code far more concise.
- * **Omit `default`**: If you have already exhaustively addressed an Enum or `sealed` class, do not append a `default` branch. Thus, when new types are appended in the future, the compiler will error out and remind you to update your logic.
+ * **Use as expression**: Assign diverging values concisely with switch expressions.
+ * **Omit `default`**: On sealed/enum types, omit `default` so the compiler catches unhandled cases when new variants are added.
- #### 1.4 Class Modifiers (Class Modifiers)
- Dart 3 introduced modifiers like `sealed`, `interface`, `base`, and `final`, allowing you to control class inheritance and implementation with heightened granularity.
+ #### 1.4 Class Modifiers
+ Dart 3 class modifiers control inheritance and implementation boundaries.
* **Best Practices**:
- * **`sealed`**: Utilized for constructing Algebraic Data Types (ADTs). Subclasses within the same library can inherit from it, while external inheritance is obstructed. Paired with `switch`, it forces exhaustive checking. This is phenomenally well-suited for defining States or Result/Error types.
- * **`interface`**: Utilize this when you exclusively desire the class to act as a contract via `implements`, but do not want its implementation details inherited via `extends`.
- * **`final`**: Completely prohibiting external libraries from inheriting (`extends`) or implementing (`implements`), ensuring the defensive integrity of the class.
+ * **`sealed`**: For Algebraic Data Types (ADTs). Enables exhaustive switch checking. Ideal for State or Result/Error types.
+ * **`interface`**: Allows `implements` only; prevents `extends`.
+ * **`final`**: Prevents both `extends` and `implements` from external libraries.
- ### 2. Effective Dart: Style and Formatting (Style)
- Maintaining consistent code aesthetic is the bedrock of collaboration.
+ ### 2. Effective Dart: Style
+ Consistent style enables collaboration.
- * **Linters and Formatting**: It is strongly recommended to use `dart format` to auto-format code, and to enable officially recommended `core` or `recommended` lints inside `analysis_options.yaml`.
+ * **Formatting**: Use `dart format` and enable `core` or `recommended` lints in `analysis_options.yaml`.
* **Naming Conventions**:
- * **Classes, Enums, Typedefs, Type parameters**: Use `UpperCamelCase` (Pascal Case).
- * **Libraries, Packages, Directories, Source files**: Use `lowercase_with_underscores` (Snake Case).
- * **Variables, Parameters, Functions, Methods**: Use `lowerCamelCase`.
- * **Constants**: Please utilize `lowerCamelCase` (e.g.: `const defaultTimeout = 1000;`), and refrain from using fully capitalized letters spliced with underscores (SCREAMING_CAPS).
+ * **Classes, Enums, Typedefs, Type parameters**: `UpperCamelCase`
+ * **Libraries, Packages, Directories, Files**: `lowercase_with_underscores`
+ * **Variables, Parameters, Functions, Methods**: `lowerCamelCase`
+ * **Constants**: `lowerCamelCase` (e.g., `const defaultTimeout = 1000;`) — not SCREAMING_CAPS.
- ### 3. Effective Dart: Programming and Usage (Usage)
+ ### 3. Effective Dart: Usage
#### 3.1 Variables and Types
- * **Type Inference**: Let the compiler deduce types; omit type annotations whenever practically possible. For local variables, abundantly employ `var` or `final`.
- * **Collection Usage (Collections)**:
- * Initialize collections using Literals: `var list = [];`, `var map = {};`. Avoid utilizing the `List()` or `Map()` constructor invocations.
- * Leverage **Spread operators (`...`)** and **collection control flow (`if`, `for`)** to construct dynamic Lists/Maps; this is sizably more concise than repeatedly calling `.add()`.
- * **Lazy Initialization**: Utilize `late` exclusively when calculation delay is fundamentally required, or when an object isn't null but the initialization flow occurs immediately following construction. Meticulously prevent accessing `late` variables prior to assignment to avert runtime trauma.
+ * **Type Inference**: Use `var`/`final` for local variables; omit type annotations where the compiler infers correctly.
+ * **Collections**: Initialize with literals (`var list = [];`). Use spread operators and collection `if`/`for` instead of `.add()` calls.
+ * **`late`**: Use only when initialization must be deferred. Never access before assignment.
- #### 3.2 Functions and Asynchrony (Functions & Async)
- * **Arrow Functions (`=>`)**: When a function contains solely a singular return expression, proficiently utilize arrow functions to condense the code.
- * **Parameter Design**:
- * Confronting multiple potentially optional parameters, prioritize the use of **Named parameters** and affix `required` per necessity, clarifying the caller's intent immensely.
- * **Futures and Asynchrony**:
- * Prioritize establishing flows using `async` / `await` over manually chaining `.then()` and `.catchError()`. This increases legibility and greatly assists the deployment of traditional `try/catch` enclosures.
+ #### 3.2 Functions and Async
+ * **Arrow Functions**: Use `=>` for single-expression functions.
+ * **Named Parameters**: Prefer named parameters for multiple optional arguments; apply `required` as needed.
+ * **Async**: Prefer `async`/`await` over `.then()`/`.catchError()` chains.
#### 3.3 Null Safety
- * **Minimize nullable types**: Ascertain designs where variables categorically cannot be null. Utilize `T?` merely when a value genuinely might lack existence.
- * **Avoid abusing the `!` (Bang operator)**: Attempt aggressively to manage nulls via Type Promotion mechanisms like `if (value != null)` or Pattern matching, drastically minimizing potential crash liabilities instigated by forced unwrapping.
+ * **Minimize nullables**: Design variables as non-nullable where possible.
+ * **Avoid `!`**: Use type promotion (`if (value != null)`) or pattern matching instead of forced unwrapping.
- ### 4. Effective Dart: API Design (Design)
- * **Keep Interfaces pristine**: Only expose members requiring exterior invocation. Dart defaults to public; if a variable or function mandates privacy, prefix its namespace with an underscore `_`.
- * **Harness Getter and Setters to supersede rudimentary operational functions**:
- * Use `get` if the function's activity resembles retrieving a property, free of ostensible side effects or exorbitant calculation outlays.
- * Do not blindly provide a setter for every property; prioritize assigning properties as `final` during constructor initialization (Immutable Data design concept).
- * **Constructor Design**:
- * Exploit Dart's Redirecting constructors or Named constructors (e.g., `User.fromJson`) aggressively to upgrade code semantics.
- * Whenever imaginable, provide `const` constructors, assisting the compiler massively in executing memory and performance optimization routines.
+ ### 4. Effective Dart: API Design
+ * **Minimal exposure**: Only expose members that require external access. Prefix private members with `_`.
+ * **Getters/Setters**: Use `get` for property-like reads with no side effects or expensive computation. Don't add setters for every property — prefer `final` constructor initialization.
+ * **Constructors**: Use named constructors (e.g., `User.fromJson`) and redirecting constructors for semantics. Provide `const` constructors wherever possible.
## Constraints
- * Heavily apply `Records` when confronted with operations demanding composite returns to eradicate the scourge of one-off Data classes.
- * Never explicitly type variables where the Dart compiler can intuitively execute Type Inference securely.
+ * Use `Records` for composite returns instead of one-off data classes.
+ * Omit type annotations where the compiler can infer the type safely.