Skip to content
FunCoding

Search

Search docs, Skills and MCP

effective-dart

Use when writing Dart code, reviewing for style, refactoring naming, adding doc comments, structuring imports, or enforcing type annotations.

文档与办公650skills/effective-dart/SKILL.md

Install

Send this to Claude Code, Codex or Cursor. The agent checks the Skill for safety first and installs it only after you confirm.

读取 https://funcoding.ai/skills/evanca/flutter-ai-rules/effective-dart/install.md ,按里面的步骤帮我安装这个 Skill。

SKILL.md

Effective Dart Skill

This skill defines how to write idiomatic, high-quality Dart and Flutter code following Effective Dart guidelines.


1. Naming Conventions

KindConventionExample
Classes, enums, typedefs, type parameters, extensionsUpperCamelCaseMyWidget, UserState
Packages, directories, source fileslowercase_with_underscoresuser_profile.dart
Import prefixeslowercase_with_underscoresimport '...' as my_prefix;
Variables, parameters, named parameters, functionslowerCamelCaseuserName, fetchData()
  • Capitalize acronyms and abbreviations longer than two letters like words: HttpRequest, not HTTPRequest.
  • Avoid abbreviations unless the abbreviation is more common than the full term.
  • Prefer putting the most descriptive noun last in names.
  • Use terms consistently throughout your code.
  • Follow mnemonic conventions for type parameters: E (element), K/V (key/value), T/S/U (generic types).
  • Consider making code read like a sentence when designing APIs.
  • Prefer a noun phrase for non-boolean properties or variables.
  • Prefer a non-imperative verb phrase for boolean properties or variables; prefer the positive form.
  • Consider omitting the verb for named boolean parameters.
  • Avoid starting a function or method name with get; prefer removing get and using a getter when the API conceptually exposes a property.

2. Types and Functions

  • Use class modifiers (final, sealed, interface, base, mixin) to control whether a class can be extended or implemented.
  • Type annotate variables without initializers.
  • Type annotate fields and top-level variables if the type isn't obvious.
  • Annotate return types on function declarations.
  • Annotate parameter types on function declarations.
  • Write type arguments on generic invocations that aren't inferred.
  • Annotate with dynamic instead of letting inference fail.
  • Use Future<void> as the return type of async members that do not produce values.
  • Use getters for operations that conceptually access properties.
  • Use setters for operations that conceptually change properties.
  • Use a function declaration to bind a function to a name.
  • Use inclusive start and exclusive end parameters to accept a range.
// Prefer: explicit class modifier
final class AppConfig {
  final String apiUrl;
  final int timeout;
  const AppConfig({required this.apiUrl, required this.timeout});
}

// Prefer: sealed for exhaustive pattern matching
sealed class Result<T> {}
class Success<T> extends Result<T> { final T value; Success(this.value); }
class Failure<T> extends Result<T> { final Exception error; Failure(this.error); }

3. Style

dart format .
  • Format code with dart format — don't manually format.
  • Use curly braces for all flow control statements.
  • Prefer final over var when variable values won't change.
  • Use const for compile-time constants.
  • Prefer lines 80 characters or fewer for readability.

4. Imports and Files

  • Don't import libraries inside the src directory of another package.
  • Don't allow import paths to reach into or out of lib.
  • Prefer relative import paths within a package.
  • Don't use /lib/ or ../ in import paths.
  • Consider writing a library-level doc comment for library files.

5. Structure

  • Keep files focused on a single responsibility.
  • Limit file length to maintain readability.
  • Group related functionality together.
  • Prefer making fields and top-level variables final.
  • Consider making constructors const if the class supports it.
  • Prefer making declarations private — only expose what's necessary.

6. Usage Patterns

// Adjacent string concatenation (not +)
final greeting = 'Hello, '
    'world!';

// Collection literals
final list = [1, 2, 3];
final map = {'key': 'value'};

// Initializing formals
class Point {
  final double x, y;
  Point(this.x, this.y);
}

// Empty constructor body
class Empty {
  Empty();  // not Empty() {}
}

// rethrow to preserve stack trace
try {
  doSomething();
} catch (e) {
  log(e);
  rethrow;
}
  • Use whereType<T>() to filter a collection by type.
  • Follow a consistent rule for var and final on local variables.
  • Initialize fields at their declaration when possible.
  • Override hashCode if you override ==; ensure == obeys mathematical equality rules.
  • Prefer specific exception handling: use on SomeException catch (e) instead of broad catch (e) or .catchError handlers.

7. Documentation

/// Returns the sum of [a] and [b].
///
/// Throws [ArgumentError] if either value is negative.
int add(int a, int b) { ... }
  • Format comments like sentences (capitalize, end with period).
  • Use /// doc comments — not /* */ block comments — for types and members.
  • Prefer writing doc comments for public APIs; consider them for private APIs too.
  • Start doc comments with a single-sentence summary, separated into its own paragraph.
  • Avoid redundancy with the surrounding context.
  • Start function/method comments with a third-person verb if the main purpose is a side effect.
  • Start with a noun or non-imperative verb phrase if returning a value is the primary purpose.
  • Start boolean variable/property comments with "Whether" followed by a noun or gerund phrase.
  • Use [identifier] in doc comments to refer to in-scope identifiers.
  • Use prose to explain parameters, return values, and exceptions (e.g., "The [param]", "Returns", "Throws" sections).
  • Put doc comments before metadata annotations.
  • Document why code exists or how it should be used, not just what it does.

8. Testing Patterns

  • Write unit tests for business logic, using group and descriptive test names:
import 'package:test/test.dart';

void main() {
  group('CartService', () {
    late CartService cart;

    setUp(() => cart = CartService());

    test('addItem increases item count', () {
      cart.addItem(Product(id: '1', name: 'Widget', price: 9.99));
      expect(cart.items, hasLength(1));
    });

    test('removeItem decreases total price', () {
      final product = Product(id: '1', name: 'Widget', price: 9.99);
      cart.addItem(product);
      cart.removeItem(product.id);
      expect(cart.totalPrice, equals(0.0));
    });
  });
}
  • Write widget tests using testWidgets and WidgetTester:
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('LoginButton shows loading indicator when tapped',
      (WidgetTester tester) async {
    await tester.pumpWidget(const MaterialApp(home: LoginScreen()));
    await tester.tap(find.byType(ElevatedButton));
    await tester.pump();
    expect(find.byType(CircularProgressIndicator), findsOneWidget);
  });
}

9. Code Review Workflow

When reviewing Dart code for Effective Dart compliance, the agent should check:

  1. Naming — verify all identifiers follow the conventions in Section 1.
  2. Type annotations — confirm public API parameters, return types, and uninitialized variables are annotated.
  3. Class modifiers — verify final, sealed, or interface is used where appropriate.
  4. Documentation — confirm all public members have /// doc comments with a single-sentence summary.
  5. Style — run dart format --output=none --set-exit-if-changed . to verify formatting.
  6. Analysis — run dart analyze and confirm zero issues.

References

Similar Skills

pdf
anthropics/skills180k

pdf

Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.

Docs & office

discernment-nudge
anthropics/skills180k

discernment-nudge

After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.

Docs & office

doc-coauthoring
anthropics/skills180k

doc-coauthoring

Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.

Docs & office

docx
anthropics/skills180k

docx

Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.

Docs & office

pptx
anthropics/skills180k

pptx

Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.

Docs & office

canvas-design
anthropics/skills180k

canvas-design

Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.

Docs & office