ams-dart-pro
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
Dart Pro
Overview
Dart's design — sound null safety, approachable async, and a productive standard library — makes it a strong language beyond Flutter (servers, CLIs, scripting). Professional Dart means using null safety as intended, writing async code structurally, modeling with immutable classes and sealed hierarchies, and organizing packages cleanly.
The through-line: null-safe by construction, async without callbacks, and code that reads plainly.
When to use
- Writing or reviewing Dart code for idiom (Flutter apps, servers, CLIs).
- Designing with null safety, sealed classes, and pattern matching.
- Structuring Dart/Flutter packages and managing dependencies.
- Using isolates, streams, and futures correctly.
- Setting up testing, linting, and CI for Dart.
Core concepts
- Sound null safety. Non-nullable by default (
Stringcan't be null);?marks genuine absence;!asserts non-null (use sparingly — each is a potential crash);latefor definitely-assigned-later fields (initialization discipline, not a null-safety escape hatch). Flow analysis + smart promotion mean well-structured code rarely needs casts. - Async done structurally.
async/awaitfor futures;Streamfor sequences of events withawait for,map/wheretransforms, and broadcast vs single-subscription semantics;Isolatefor true parallelism (CPU work off the main isolate — no shared memory, message passing only). - Sealed classes + patterns (Dart 3).
sealed class Resultwith subtypes, exhaustiveswitch— the compiler enforces handling every case. Destructuring patterns in variable declarations andif-casekeep parsing code clean. - Immutable models.
finalfields,constconstructors where possible,copyWithfor variations. Immutable state is the foundation of predictable Flutter UIs and testable logic. - Packages and pub.
pubspec.yamldeclares deps with version constraints;dart pub getresolves; lock file committed for apps. Organize by feature inlib/; keepsrc/private with a barrel export file when publishing packages. - Lint like you mean it.
dart analyze+flutter_lints(or strictervery_good_analysisrules) in CI. Lints catch real bugs (unawaited futures, unnecessary null assertions) — not just style.
Practical workflow
- Scaffold:
dart create(orflutter create), null-safe SDK constraint, lints package,analysis_options.yamlwired up, tests intest/. - Model the domain. Sealed classes for states/results, immutable classes with
copyWith, enums with fields/methods for rich fixed sets. Validate in factories. - Write async structurally.
awaitchains over.thenpyramids; streams for event flows with proper subscription lifecycle (cancel!); isolates for CPU-bound work, not I/O. - Handle errors explicitly.
try/catchat boundaries; custom exception types with context;Future.erroronly deliberately; never swallow errors silently — log with context. - Test the logic.
package:test(orflutter_test): unit-test pure logic and models, widget-test UI interactions, integration-test critical journeys. Mock at boundaries (HTTP, platform channels), not at your own domain. - Mind the runtime. Avoid jank: no heavy synchronous work on the UI isolate; profile with
DevTools before optimizing;
constwidgets where static to reduce rebuild cost.
Idiomatic snippets:
// Sealed result + exhaustive switch
sealed class LoadResult<T> {}
final class Loaded<T> extends LoadResult<T> { final T data; Loaded(this.data); }
final class LoadFailed<T> extends LoadResult<T> { final String message; LoadFailed(this.message); }
String describe<T>(LoadResult<T> r) => switch (r) {
Loaded(:var data) => 'Loaded: $data',
LoadFailed(:var message) => 'Failed: $message',
};
// Immutable model with copyWith
class Order {
final String id; final int totalCents; final bool paid;
const Order({required this.id, required this.totalCents, this.paid = false});
Order copyWith({bool? paid}) => Order(id: id, totalCents: totalCents, paid: paid ?? this.paid);
}
Common pitfalls
!as a habit. Null-assertion operators scattered to silence the analyzer reintroduce the crashes null safety was built to prevent. Restructure so promotion works, or handle the null.lateabuse.latefields that throwLateInitializationErrorin production because initialization order wasn't guaranteed. Prefer nullable + explicit init, or constructor init.- Unawaited futures. Fire-and-forget futures whose errors vanish silently (unhandled async
errors). Await or explicitly handle; the
unawaited_futureslint exists for this. - Blocking the UI isolate. Synchronous file I/O, JSON parsing of huge payloads, or image
processing on main — jank.
compute()/isolates for CPU work; async I/O is already non-blocking. - Stream subscription leaks. Listening without canceling (especially in widgets) — memory leaks and setState-after-dispose crashes. Manage lifecycle explicitly.
- Mutable shared state. Non-final fields mutated across async gaps — race-shaped bugs even in single-threaded Dart (await points interleave). Immutable models + explicit state management.
- Ignoring lints.
dart analyzewarnings treated as noise. Many Dart lints encode real correctness lessons — keep the analyzer clean in CI.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).