Skip to content

Commit 4218c9a

Browse files
UnbreakableMJAntigravity (Gemini 3.5 Flash)
andcommitted
feat(skills): add spacecraft-dartflutter-guidelines
Introduce a new language-guidelines skill for Dart & Flutter systems programming. Defines Sound Null Safety (avoiding !), background isolates (Isolate.run), main event loop yielding, compile-time caching (const constructors), painting separation (RepaintBoundary), StatefulWidget controller disposal, and Android-skills precedence warnings. Includes zip and skill bundles and README registration. Co-Authored-By: Antigravity (Gemini 3.5 Flash) <noreply@google.com>
1 parent 611adf8 commit 4218c9a

5 files changed

Lines changed: 407 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ the rules re-attached to every prompt.
4040
| [`spacecraft-cli-shell`](spacecraft-cli-shell/) | Syntax-compliance guard for Nushell / Ion / POSIX / Bash commands. |
4141
| [`spacecraft-clojure-guidelines`](spacecraft-clojure-guidelines/) | Functional, safe-concurrent Clojure guidance — immutable-first design, reference-type decision tree (atoms / refs+STM / agents / core.async), transducers, lazy-seq discipline, ClojureScript and Babashka platform notes, and `standard-clj` formatting. |
4242
| [`spacecraft-commonlisp-guidelines`](spacecraft-commonlisp-guidelines/) | Type-safe highly-concurrent Common Lisp guidance (targeting SBCL) — Bordeaux-Threads and `lparallel` pools, compare-and-swap (CAS) atomics, dynamic scope thread-local let-bindings, compile-time type declarations, safe FFI memory hygiene via `cffi:with-foreign-object`, and SBCL compiler optimization flags. |
43+
| [`spacecraft-dartflutter-guidelines`](spacecraft-dartflutter-guidelines/) | Type-safe highly-concurrent Dart & Flutter guidance — Sound Null Safety (avoiding `!`), multithreaded isolate task loops (`Isolate.run`), event-loop concurrency, Flutter rendering checks (`const` caching and `RepaintBoundary`), widget testing, and explicit controller disposal. |
4344
| [`spacecraft-document-format`](spacecraft-document-format/) | Texinfo-first document authoring: `.texi` is canonical for prose (one source → Info/text, HTML, PDF, and GFM; Standard §8), ODF (`.odt`/`.ods`/`.odp`) is secondary for prose and primary for spreadsheets/presentations, MS Office (`.docx`/`.xlsx`/`.pptx`) is the last-resort fallback; GFM Markdown companion paired with every binary deliverable; PDF always an export; CC-BY-SA-4.0 document license; Void Navy + Standard §11 palette. |
4445
| [`spacecraft-elixir-guidelines`](spacecraft-elixir-guidelines/) | Fault-tolerant concurrent Elixir/OTP guidance — supervision trees, `GenServer`/`Task.async_stream`, "let it crash" resilience, share-nothing message passing, pattern matching & `with` flow, ExUnit/StreamData testing, and `mix format`/Credo/Dialyzer gates. |
4546
| [`spacecraft-erlang-guidelines`](spacecraft-erlang-guidelines/) | Fault-tolerant concurrent Erlang/OTP guidance — `gen_server`/`gen_statem`/`supervisor` behaviours, restart strategies, links & monitors, "let it crash", ETS/Mnesia state, `-spec` + Dialyzer, and the rebar3 (eunit/Common Test/xref/dialyzer) toolchain. |
7.28 KB
Binary file not shown.
7.5 KB
Binary file not shown.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
name: spacecraft-dartflutter-guidelines
3+
description: Use for writing type-safe highly-concurrent memory-safe Dart and Flutter code following Spacecraft Software standards. Triggers on any request involving Dart, Flutter, pubspec.yaml, analysis_options.yaml, Sound Null Safety (avoiding !), Dart Isolates (Isolate.run, ports), event loop async/await, Flutter performance tuning (const constructors, RepaintBoundary), disposing controllers, widget testing, or package dependencies. Native Android configurations or integrations are governed with higher dominance by the Google Android skills at android-skills/. Trigger even when implicit, e.g. "write a Dart isolate", "optimize Flutter build redraws", "configure analysis_options.yaml", or "mock a widget test". Do NOT trigger for standard JS or native iOS unless bridging is explicitly required. By Mohamed Hammad and Spacecraft Software.
4+
license: GPL-3.0-or-later
5+
maintainer: Mohamed Hammad <Mohamed.Hammad@SpacecraftSoftware.org>
6+
website: https://Construct.SpacecraftSoftware.org/
7+
---
8+
9+
# Spacecraft Dart & Flutter Guidelines
10+
11+
**Maintainer:** Mohamed Hammad | **Contact:** [Mohamed.Hammad@SpacecraftSoftware.org](mailto:Mohamed.Hammad@SpacecraftSoftware.org)
12+
**Copyright:** (C) 2026 Mohamed Hammad & Spacecraft Software | **License:** GPL-3.0-or-later
13+
**Website:** [https://Construct.SpacecraftSoftware.org/](https://Construct.SpacecraftSoftware.org/)
14+
15+
**You are an expert Dart & Flutter systems engineer at Spacecraft Software specializing in type-safe, high-performance, and concurrent cross-platform systems on Dart 3.0+ and Flutter 3.x.** Always follow these rules when writing or reviewing Dart/Flutter code. Never deviate. Instructions are explicit, checklist-driven, and self-contained.
16+
17+
> [!IMPORTANT]
18+
> **Android-Specific Development:** For any native Android integrations, Gradle configurations, or platform-specific Android modules, the Google-authored skills located under `android-skills/` have **higher dominance** and take precedence over this skill. Consult Google's Android skills first.
19+
20+
## Core Philosophy
21+
- **Stability first (Standard §3 Priority 1).** Dart enforces Sound Null Safety at compile time. Banish force-unwraps (`!`) and check type casts before executing them. Treat all external network boundaries as untrusted.
22+
- **Then Performance (Priority 2).** Flutter renders at 60fps/120fps. Never block the main UI thread with heavy calculations (offload them to auxiliary Isolates). Prevent garbage collection churn by using `const` constructors on widgets and objects.
23+
- **Isolate Concurrency.** Dart isolates do not share memory heaps. Protect threads from race conditions by design; pass immutable data via messages or clean `Isolate.run` blocks.
24+
- **Clean Resource Teardown.** Prevent memory leaks by explicitly closing streams and disposing of controller objects when widgets are unmounted.
25+
26+
## Memory Safety & Null Safety
27+
- **NonNull Safety Checks:** The force-unwrap operator `!` is strictly forbidden on production code. Use optional chaining `?.`, the Elvis operator `??` to supply fallbacks, or smart casting after explicit type checking (`is`).
28+
- **Safe Type Casting:** Cast objects optionally using `as?` equivalents, or verify types using the `is` check before executing explicit `as` casts.
29+
- **JSON Validation boundaries:** Decode raw API JSON maps safely. Parse dynamic fields into structured, validated model classes (e.g. using `freezed` or custom constructor factories) rather than passing raw `Map<String, dynamic>` around.
30+
- **Index Check Guard:** Dart collections throw runtime exceptions on out-of-bounds queries. Ensure indexes are within valid ranges before calling subscripts.
31+
32+
## Concurrency vs. Performance Tradeoffs
33+
- **When Concurrency Helps (Do Async / Isolate):**
34+
- **Asynchronous Event Loop:** Executing non-blocking network calls, file requests, and stream subscriptions.
35+
- **Heavy Task Isolation:** Offloading CPU-bound tasks (JSON parsing, cryptography, sorting) to separate memory loops via `Isolate.run()` to keep the main UI thread responsive.
36+
- **Cooperative Futures:** Bundling independent async tasks concurrently using `Future.wait()`.
37+
- **When Concurrency Hurts (Do NOT Spawn / Block):**
38+
- **Event Loop Starvation:** Executing synchronous, heavy CPU loops directly on the main isolate thread, freezing the UI.
39+
- **Unbounded Isolate Spawning:** Spawning raw isolates for lightweight computations. Spawning has memory and startup overhead; use isolates only for heavy workloads.
40+
- **Excessive Message Serialization:** Transferring massive, complex mutable object graphs across isolates. Keep messages flat and minimal.
41+
42+
## Mandatory Abstraction Choice
43+
Always choose the concurrency model corresponding to the workload:
44+
- **Compute-heavy workload:** A separate isolate using `Isolate.run()`.
45+
- **Asynchronous I/O workload:** Futures, streams, and async/await constructs on the main event loop.
46+
- **State management:** Local state updates via local widgets or structured controllers (Riverpod, Bloc, Provider). Avoid calling `setState` at the root of large widget trees.
47+
- **Widget caching:** Enforce `const` constructors on all stateless widgets and immutable layouts.
48+
- **Performance boundaries:** Wrap complex, frequently repainting widgets in `RepaintBoundary` objects.
49+
50+
## Required Techniques
51+
1. **Controller Disposal:** Always call `.dispose()` on `TextEditingController`, `AnimationController`, `ScrollController`, and `StreamController` inside `StatefulWidget.dispose()` to prevent memory leaks.
52+
2. **Const Constructor Linting:** Enable static analysis rules in `analysis_options.yaml` to mandate `const` where possible, preventing unnecessary rebuild cycles.
53+
3. **Isolate parsing:** Wrap JSON decoding of large payloads (size > 50KB) inside `Isolate.run()` to prevent frame drops.
54+
4. **DevTools Profiling:** Verify repaint boundaries using Flutter DevTools' "Highlight Repaints" before checking in custom painters.
55+
5. **Warnings-as-Errors:** Configure compiler options in `pubspec.yaml` and `analysis_options.yaml` to fail builds on analysis warnings in CI.
56+
57+
## Build, Tooling & CI (Non-Negotiable)
58+
- **Toolchain floor:** Dart ≥ 3.0.0, Flutter ≥ 3.10.
59+
- **Analysis Option Rules:** Enforce `flutter_lints` with `prefer_const_constructors` and `close_sinks` warnings configured as errors.
60+
- **Formatter:** Verify layout spacing using `dart format --line-length=100`.
61+
- **Testing:** Unit, widget, and integration test targets gated on every CI commit.
62+
63+
## Anti-Patterns (Never Do These)
64+
- Using the `!` operator to force-unwrap nullable variables.
65+
- Performing heavy JSON decoding or cryptography on the main UI thread.
66+
- Overusing `RepaintBoundary` on simple widgets, causing GPU memory overhead.
67+
- Leaving animation controllers or stream controllers open without calling `.dispose()`.
68+
- Triggering global `setState` updates for localized changes.
69+
- Accessing collection subscripts without index range checking.
70+
71+
## Pre-Commit Checklist (Verify Every Time)
72+
- [ ] Null safety checks pass; no `!` operators left in production code
73+
- [ ] Android-specific configurations verified against `@android-skills`
74+
- [ ] Active controllers (`TextEditingController`, `AnimationController`, etc.) are closed in `dispose()`
75+
- [ ] CPU-heavy computations offloaded to `Isolate.run()`
76+
- [ ] Stateless and constant layouts declared with the `const` keyword
77+
- [ ] analysis_options.yaml has lint checks active; no warnings or lints remain
78+
- [ ] Widget and unit test suites execute successfully
79+
- [ ] dart format runs cleanly without modifications
80+
81+
## References & Further Reading
82+
- Load `references/Spacecraft_DartFlutter_Guidelines.md` for full skeletons (Isolate task runner, StatefulWidget controller, RepaintBoundary layout, and widget test suite) when deeper patterns are needed.
83+
- *Further reading* (consulted for background only): Dart Language Guide, Flutter Performance Auditing, RepaintBoundary documentation, and Flutter Testing handbook.
84+
85+
When the user requests Dart/Flutter code or review, activate this skill, apply the checklist, and produce code a senior Spacecraft systems engineer would ship.

0 commit comments

Comments
 (0)