{
    "url": "https://delaparra-services.nl/skills/flutter-dart-style",
    "locale": "en",
    "title": "analysis_options.yaml | DeLaParra Services",
    "description": "Use when writing or reviewing any Dart or Flutter code for craft - naming, null safety, pattern matching, records, error handling idioms, dartdoc comments, logging, assertion style in tests, widget-level code quality (const, keys, dispose, BuildContext across an await), and analysis_options lint setup. Triggers on \"clean this up\", \"is this idiomatic?\", a code review of Dart, or a new file that sets a precedent others will copy.",
    "alternates": {
        "en": "https://delaparra-services.nl/skills/flutter-dart-style",
        "nl": "https://delaparra-services.nl/nl/skills/flutter-dart-style"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/skills/flutter-dart-style.csv",
        "md": "https://delaparra-services.nl/skills/flutter-dart-style.md",
        "json": "https://delaparra-services.nl/skills/flutter-dart-style.json",
        "zip": "https://delaparra-services.nl/skills/flutter-dart-style.zip",
        "pdf": "https://delaparra-services.nl/skills/flutter-dart-style.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/skills/flutter-dart-style.csv",
            "encodingFormat": "text/csv",
            "name": "flutter-dart-style.csv"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-dart-style.json",
            "encodingFormat": "application/json",
            "name": "flutter-dart-style.json"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-dart-style.md",
            "encodingFormat": "text/markdown",
            "name": "flutter-dart-style.md"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-dart-style.pdf",
            "encodingFormat": "application/pdf",
            "name": "flutter-dart-style.pdf"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-dart-style.zip",
            "encodingFormat": "application/zip",
            "name": "flutter-dart-style.zip"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-dart-style/download",
            "encodingFormat": "application/zip",
            "name": "flutter-dart-style-files.zip"
        }
    ],
    "markdown": "# analysis\\_options.yaml\n\n \n\nUse when writing or reviewing any Dart or Flutter code for craft - naming, null safety, pattern matching, records, error handling idioms, dartdoc comments, logging, assertion style in tests, widget-level code quality (const, keys, dispose, BuildContext across an await), and analysis\\_options lint setup. Triggers on \"clean this up\", \"is this idiomatic?\", a code review of Dart, or a new file that sets a precedent others will copy.\n\n \n\n**Licence** MIT\n\n \n\n**Source** gabuldev/flutter-skills\n\n [Download zip](<https://delaparra-services.nl/skills/flutter-dart-style/download>)   \n\nYou are writing or reviewing Dart for craft — the layer below architecture. Where a project convention exists, it wins; this is what to do when there isn't one, and what the analyzer will not tell you.\n\n \n\nRelated in this repo: **flutter-clean-arch** for layering, **flutter-testing** for what to test, **flutter-concurrency** for isolates and streams, **flutter-accessibility** for semantics, **flutter-theming** for colour and type.\n\n \n\nSome topics below have a **canonical skill from the Dart team** (dart-lang/skills) that goes deeper than this file should. Where one exists it is named inline — install it and defer to it. What stays here is the opinion: which convention this codebase picked, and the traps the analyzer won't flag.\n\n \n\n## The first rule: let the tools own what the tools own\n\n \n\nNever spend a review comment on something ` dart format ` or ` dart analyze ` will fix. Formatting, unused imports, missing ` const ` where the lint catches it — all machine work.\n\n \n\n```\ndart format .        # not `flutter format`, removed in Flutter 3.38\ndart fix --apply     # applies analyzer-suggested fixes\ndart analyze\n```\n\n \n\n> Setting up and driving the analyzer is ` dart-run-static-analysis `'s job.\n\n \n\nReview *semantics*: a name that misleads, an error swallowed, a shape that won't survive the next change.\n\n \n\n## Naming\n\n    Thing Case Note     Classes, enums, typedefs, extensions ` UpperCamelCase `    Members, variables, parameters, constants ` lowerCamelCase ` constants too — not ` SCREAMING_CAPS `   Files, directories, import prefixes ` lowercase_with_underscores `    Private leading ` _ `     \n\nBeyond case:\n\n \n\n- **Put the most descriptive noun last.** ` pageCount `, not ` numPages `. ` inputUserName `, not ` userNameInput `. The last word is what a reader scanning a column of names actually sees. \n- **Don't abbreviate** unless the abbreviation is more common than the word (` id `, ` http `, ` db ` are fine; ` usr `, ` btn `, ` cfg ` are not). Abbreviation drift inside one file — ` user ` in one method and ` usr ` in the next — is worth a review comment even though it changes no behaviour. \n- **Non-boolean property → noun phrase** (` elements `, ` remainingBudget `). **Function that does something → verb phrase** (` sortItems() `, ` sendInvite() `). **Boolean → non-imperative predicate** that reads as an assertion: ` isEmpty `, ` hasElements `, ` canClose ` — never ` close ` or ` getIsEmpty `. \n- **Don't prefix getters with ` get `.** In Dart the access syntax already says it: ` user.name `, not ` user.getName() `. \n- **` toX() ` returns a new object; ` asX() ` returns a view or wrapper** over the same data. Picking the wrong one tells the caller the wrong thing about cost and about whether mutations alias. \n- **Don't repeat the parameter's type in the name.** ` addPerson(Person p) `, not ` addPersonWithPerson `. The signature is right there.\n\n \n\n## Null safety\n\n \n\nSoundly null-safe code is the default; the interesting part is what to do at the boundary.\n\n \n\n- **` ! ` is a claim you are making to the compiler.** Every one is a potential runtime crash. Use it only where the invariant is genuinely local and obvious, and prefer restructuring so the compiler can see it:\n\n \n\n```\n// avoid — the ! is load-bearing and far from the check\nif (user != null) { ... }\ndoSomething(user!.name);\n\n// prefer — promote once, into a non-nullable local\nfinal u = user;\nif (u != null) doSomething(u.name);\n```\n\n \n\nA field can't be promoted (another isolate or subclass could change it), which is why the local is necessary. \n- Reach for the null-aware operators — ` ?. `, ` ?? `, ` ??= `, ` ...? ` — before an explicit ` if (x == null) `. \n- **Don't initialise to ` null ` explicitly.** ` int? count; ` is already null. \n- Prefer ` late final ` over a nullable field you know gets set once in ` initState `. It fails loudly at the wrong access instead of spreading ` ? ` through callers. \n- At an API boundary you don't control (JSON, platform channels), validate once on the way in and hand the rest of the codebase non-nullable types. Don't let ` Map<String, dynamic> ` nullability leak past the model layer.\n\n \n\n## Pattern matching over a sealed status\n\n \n\n> The general feature is ` dart-use-pattern-matching `'s subject. What follows is only how it pairs with the sealed status classes this codebase uses.\n\n \n\n- **Prefer ` switch ` expressions** over statements when producing a value. They are exhaustive over a sealed hierarchy, so adding a variant becomes a compile error instead of a silently missed branch — which is the whole reason to seal a status class in the first place (see **flutter-state**).\n\n \n\n```\nfinal label = switch (status) {\n  LoadingStatus()      => 'Loading…',\n  SuccessStatus(:final items) => '${items.length} found',\n  ErrorStatus(:final message) => message,\n};\n```\n\n \n\n` :final items ` destructures in the pattern — no cast, no second lookup. \n- **Records for a genuinely anonymous pair**, when a named class would be ceremony and the tuple never leaves the file:\n\n \n\n```\n(int width, int height) measure() => (800, 600);\nfinal (w, h) = measure();\n```\n\n \n\nOnce a record crosses a layer boundary or gains a third field, make it a class. Records have no name, so they can't carry meaning or invariants. \n- Avoid ` default: ` in a switch over a sealed type. It defeats exhaustiveness and turns the next added variant into a runtime bug.\n\n \n\n## Error handling\n\n \n\n- **` catch ` without an ` on ` clause catches everything**, including programming errors you wanted to crash on. Catch the type you can act on. \n- **Never swallow.** An empty ` catch {} `, or one that only returns ` null `, destroys the stack trace at the exact moment you needed it. \n- **` rethrow `, not ` throw e `** — ` throw e ` restarts the stack trace at the catch site and you lose the origin. \n- Preserve the stack trace when you cross a layer: ` catch (e, s) ` and pass ` s ` along. A domain exception with no trace is a bug report you can't act on. \n- Throw objects implementing ` Exception ` (recoverable, expected) or ` Error ` (a bug — don't catch these). Never throw a raw ` String `.\n\n \n\n## Members and constructors\n\n \n\n- **Prefer ` final ` fields.** Immutability removes a whole class of question from every read. \n- **Don't wrap a field in a trivial getter/setter.** Dart lets you turn a field into a getter later without changing call sites — that's the point of uniform access. Add the getter when it does something. \n- **Use ` => ` for members that are a single expression**, and a block body when it isn't. Don't chain ` => ` across three lines to avoid braces. \n- **Initialising formals**: ` Foo(this.bar) ` over an assignment in the body. \n- **` const ` constructors wherever the class allows it** — this is what lets callers build the widget once and skip rebuilds. \n- If you override ` == `, **override ` hashCode `**, and don't define ` == ` on a mutable class — a mutated key silently disappears from any ` Set ` or ` Map ` holding it. For value objects, ` Equatable ` or a record is usually less risk than hand-writing both.\n\n \n\n## Type annotations\n\n \n\nAnnotate where it's a contract or where inference can't see it; stay quiet where the compiler already knows:\n\n \n\n- **Do annotate**: return types, parameter types, fields and top-level variables without an obvious initialiser. \n- **Don't annotate**: locals with an initialiser, and lambda parameters whose type comes from context.\n\n \n\n```\n// the types add nothing here\nListView.builder(\n  itemBuilder: (context, index) => ItemCard(items[index]),\n);\n\n// but here the annotation is the only thing documenting the shape\nfinal Map<String, List<int>> byCategory = {};\n```\n\n \n\nAn empty collection literal with no annotation infers ` dynamic ` and quietly disables type checking for everything downstream.\n\n \n\n## Widget-level quality\n\n \n\n- **A private widget class beats a ` Widget _buildHeader() ` helper.** It isn't style: a helper method has no element of its own, so it rebuilds whenever the parent does and can never be ` const `. A ` class _Header extends StatelessWidget ` gets its own element and can be skipped entirely. \n- **Break up a long ` build() `** the same way — into widget classes, not more helpers. \n- **No expensive work in ` build() `.** It runs on every frame that touches this subtree. Network calls, sorting a large list, parsing — all belong above it. Heavy pure computation goes to ` compute() ` / ` Isolate.run() `; see **flutter-concurrency**. \n- **Dispose what you create**: controllers, ` StreamSubscription `s, ` Ticker `s, ` FocusNode `s. If a field has a ` dispose() `, your ` State ` needs one. \n- **` BuildContext ` across an ` await ` is a bug waiting to happen.** Guard it:\n\n \n\n```\nawait repository.save(item);\nif (!context.mounted) return;\nNavigator.of(context).pop();\n```\n\n \n\n` use_build_context_synchronously ` catches the common shape, not all of them. \n- **Stable ` Key `s on dynamic lists.** Without one, Flutter matches children by position, so an insert or reorder keeps the wrong state attached to the wrong item — the classic \"the checkbox moved to another row\" bug. \n- **` ListView.builder `, never a ` ListView(children: [...]) `** for a list whose length you don't control. The non-builder form materialises every child.\n\n \n\n## Documentation\n\n \n\n> Formatting rules — summary sentence, third-person verbs, ` [brackets] `, where the comment sits relative to annotations — are ` dart-write-documentation `'s subject, and it is the authority. Two judgement calls it can't make for you:\n\n \n\n- **Document what a caller can't see**, not what the signature already shows. Nullability, what it throws and when, side effects, cost. A doc comment that re-lists the parameters has added nothing.\n\n \n\n```\n/// Fetches the profile for [userId].\n///\n/// Returns `null` when no such user exists. Throws [NetworkException] if the\n/// request fails for connectivity reasons — callers that can retry should\n/// catch it; other failures are programming errors and propagate.\nFuture<User?> fetchUser(String userId) async { ... }\n``` \n- **Comment why, not what.** ` // increment i ` is noise. ` // the API is 1-based ` is the reason the next person doesn't \"fix\" it back into a bug.\n\n \n\n## Logging\n\n \n\n` print() ` is for scratch debugging and the ` avoid_print ` lint exists for a reason. Use ` dart:developer `, which DevTools understands:\n\n \n\n```\nimport 'dart:developer' as developer;\n\ntry {\n  await repository.sync();\n} catch (e, s) {\n  developer.log(\n    'Sync failed',\n    name: 'myapp.sync',   // shows as a filterable channel in DevTools\n    level: 1000,          // 1000 = SEVERE, per package:logging levels\n    error: e,\n    stackTrace: s,\n  );\n}\n```\n\n \n\nNever log a credential, token, or personally identifying field. In an app that handles user data, assume every log line reaches a crash reporter.\n\n \n\n## Assertion style in tests\n\n \n\nUse ` package:checks ` for unit and service assertions — better failure messages and type-safe chaining than bare ` expect `. ` dart-migrate-to-checks-package ` covers the migration and the full matcher mapping; the two things worth fixing as convention here:\n\n \n\n```\ncheck(user)\n  ..has((u) => u.name,  'name').equals('Ana')\n  ..has((u) => u.email, 'email').contains('@');\n```\n\n \n\n- **Prefer ` .has((u) => u.field, 'field') ` over comparing whole objects.** It makes the failure name *which* field differed instead of dumping two objects side by side and leaving you to diff them. \n- **Widget tests keep ` expect `** with ` findsOneWidget ` / ` findsNothing ` — those are ` flutter_test ` matchers with no ` checks ` equivalent. Both styles in one file is fine; they solve different problems.\n\n \n\nSee **flutter-testing** for structure, mocking and what deserves a test at all.\n\n \n\n## Lint setup\n\n \n\n` dart-run-static-analysis ` owns running the analyzer and ` dart fix `. The convention worth stating: **promote a lint to ` error ` when violating it ships a bug; leave it a warning when it is taste** — and always exclude generated files, because noise you can't fix trains people to ignore the analyzer.\n\n \n\n```\n# analysis_options.yaml\ninclude: package:flutter_lints/flutter.yaml\n\nanalyzer:\n  errors:\n    use_build_context_synchronously: error   # real crashes, not style\n    unawaited_futures: error\n  exclude:\n    - \"**/*.g.dart\"\n    - \"**/*.freezed.dart\"\n```\n\n \n\nAdd rules deliberately. A rule nobody agreed to becomes a rule everybody suppresses.\n\n \n\n## Review checklist\n\n \n\n1. Would ` dart format ` / ` dart analyze ` have caught it? Then don't raise it. \n1. Does any name mislead, or drift from the name used three lines up? \n1. Is there a ` ! ` whose invariant isn't visible within a few lines? \n1. Is any error swallowed, or rethrown as ` throw e ` losing the trace? \n1. Is a ` switch ` over a sealed type using ` default: `? \n1. Does a ` State ` create something with a ` dispose() ` and not dispose it? \n1. Is ` context ` used after an ` await ` without a ` mounted ` guard? \n1. Is a ` Widget _buildX() ` helper doing what a private widget class should? \n1. Does a new public API have a doc comment saying what a caller can't see? \n1. Is anything logged that shouldn't leave the device?\n\n \n\n## Files\n\n \n\n- ` LICENSE ` \n- ` SKILL.md ` \n- ` SOURCE.md `\n\n \n\n## Related terms\n\n \n\n- [Dart](<https://delaparra-services.nl/knowledge-hub/dart>) \n- [Dart Coding Conventions](<https://delaparra-services.nl/knowledge-hub/dart-coding-conventions>)\n\n \n\n## Related services\n\n \n\n- [App development](<https://delaparra-services.nl/services#service-02>) \n- [AI code review](<https://delaparra-services.nl/services#service-05>)\n\n \n\n[Installing an agent skill in Claude Code, Codex, Cursor and Copilot](<https://delaparra-services.nl/manuals/een-skill-installeren-in-je-ai-assistent>)\n\n[HTML version](https://delaparra-services.nl/skills/flutter-dart-style)\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "Organization",
                "@id": "https://delaparra-services.nl/#practice",
                "logo": "https://delaparra-services.nl/logo.png",
                "name": "DeLaParra Services",
                "legalName": "DeLaParra Services",
                "url": "https://delaparra-services.nl/",
                "description": "Bespoke software, web applications and mobile apps, developed in Laravel by a single developer in Groningen. Fixed price agreed in advance, full source code provided upon delivery.",
                "email": "info@delaparra-services.nl",
                "address": {
                    "@type": "PostalAddress",
                    "addressLocality": "Groningen",
                    "addressRegion": "Groningen",
                    "addressCountry": "NL"
                },
                "areaServed": "Groningen, the Netherlands",
                "knowsLanguage": [
                    "en",
                    "nl"
                ],
                "knowsAbout": [
                    "Web design and development",
                    "App development",
                    "Custom software and web applications",
                    "OpenSpec",
                    "AI code review",
                    "Your own coding agent"
                ],
                "founder": {
                    "@id": "https://delaparra-services.nl/#person"
                }
            },
            {
                "@type": "WebPage",
                "@id": "https://delaparra-services.nl/skills/flutter-dart-style#webpage",
                "url": "https://delaparra-services.nl/skills/flutter-dart-style",
                "name": "analysis_options.yaml | DeLaParra Services",
                "description": "Use when writing or reviewing any Dart or Flutter code for craft - naming, null safety, pattern matching, records, error handling idioms, dartdoc comments, logging, assertion style in tests, widget-level code quality (const, keys, dispose, BuildContext across an await), and analysis_options lint setup. Triggers on \"clean this up\", \"is this idiomatic?\", a code review of Dart, or a new file that sets a precedent others will copy.",
                "isPartOf": {
                    "@id": "https://delaparra-services.nl/#website"
                },
                "about": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "inLanguage": "en",
                "breadcrumb": {
                    "@id": "https://delaparra-services.nl/skills/flutter-dart-style#breadcrumb"
                }
            },
            {
                "@type": "BreadcrumbList",
                "@id": "https://delaparra-services.nl/skills/flutter-dart-style#breadcrumb",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "name": "Home",
                        "item": "https://delaparra-services.nl/"
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "name": "analysis_options.yaml"
                    }
                ]
            },
            {
                "@type": "Person",
                "@id": "https://delaparra-services.nl/#person",
                "name": "Reinier de la Parra",
                "url": "https://delaparra-services.nl/about"
            },
            {
                "@type": "SoftwareSourceCode",
                "@id": "https://delaparra-services.nl/skills/flutter-dart-style#skill",
                "url": "https://delaparra-services.nl/skills/flutter-dart-style",
                "name": "analysis_options.yaml",
                "description": "Use when writing or reviewing any Dart or Flutter code for craft - naming, null safety, pattern matching, records, error handling idioms, dartdoc comments, logging, assertion style in tests, widget-level code quality (const, keys, dispose, BuildContext across an await), and analysis_options lint setup. Triggers on \"clean this up\", \"is this idiomatic?\", a code review of Dart, or a new file that sets a precedent others will copy.",
                "inLanguage": "en",
                "license": "https://spdx.org/licenses/MIT.html",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/skills/flutter-dart-style#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/skills/flutter-dart-style#dataset",
                "name": "analysis_options.yaml",
                "description": "Use when writing or reviewing any Dart or Flutter code for craft - naming, null safety, pattern matching, records, error handling idioms, dartdoc comments, logging, assertion style in tests, widget-level code quality (const, keys, dispose, BuildContext across an await), and analysis_options lint setup. Triggers on \"clean this up\", \"is this idiomatic?\", a code review of Dart, or a new file that sets a precedent others will copy.",
                "url": "https://delaparra-services.nl/skills/flutter-dart-style",
                "identifier": "https://delaparra-services.nl/skills/flutter-dart-style#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/skills/flutter-dart-style#skill"
                },
                "creditText": "gabuldev/flutter-skills",
                "publisher": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "license": "https://spdx.org/licenses/MIT.html",
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "dateModified": "2026-11-30T13:17:19+00:00",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/knowledge-hub#skills",
                    "name": "Skills for AI coding assistants",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "flutter-dart-style.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-dart-style.csv",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-dart-style.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-dart-style.json",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-dart-style.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-dart-style.md",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-dart-style.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-dart-style.pdf",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-dart-style.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-dart-style.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-dart-style-files.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-dart-style/download",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    }
                ]
            }
        ]
    }
}