{
    "url": "https://delaparra-services.nl/skills/flutter-di",
    "locale": "en",
    "title": "Flutter Di | DeLaParra Services",
    "description": "Use when registering or resolving a dependency with flutter_injections - adding a registration to the core injections, assembling a feature FlutterModule, choosing between singleton/lazySingleton/factory, or calling FlutterInjections.get. Triggers on a runtime \"dependency not registered\" error.",
    "alternates": {
        "en": "https://delaparra-services.nl/skills/flutter-di",
        "nl": "https://delaparra-services.nl/nl/skills/flutter-di"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/skills/flutter-di.csv",
        "md": "https://delaparra-services.nl/skills/flutter-di.md",
        "json": "https://delaparra-services.nl/skills/flutter-di.json",
        "zip": "https://delaparra-services.nl/skills/flutter-di.zip",
        "pdf": "https://delaparra-services.nl/skills/flutter-di.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/skills/flutter-di.csv",
            "encodingFormat": "text/csv",
            "name": "flutter-di.csv"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-di.json",
            "encodingFormat": "application/json",
            "name": "flutter-di.json"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-di.md",
            "encodingFormat": "text/markdown",
            "name": "flutter-di.md"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-di.pdf",
            "encodingFormat": "application/pdf",
            "name": "flutter-di.pdf"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-di.zip",
            "encodingFormat": "application/zip",
            "name": "flutter-di.zip"
        },
        {
            "url": "https://delaparra-services.nl/skills/flutter-di/download",
            "encodingFormat": "application/zip",
            "name": "flutter-di-files.zip"
        }
    ],
    "markdown": "# Flutter Di\n\n \n\nUse when registering or resolving a dependency with flutter\\_injections - adding a registration to the core injections, assembling a feature FlutterModule, choosing between singleton/lazySingleton/factory, or calling FlutterInjections.get. Triggers on a runtime \"dependency not registered\" error.\n\n \n\n**Licence** MIT\n\n \n\n**Source** gabuldev/flutter-skills\n\n [Download zip](<https://delaparra-services.nl/skills/flutter-di/download>)   \n\nYou are configuring dependency injection for a Flutter feature using ` flutter_injections `.\n\n \n\n## DI Architecture Overview\n\n \n\n```\nFlutterInjectionsWidget (root, in AppWidget)\n  └── CoreInjections.core()        ← global singletons (Dio, repos, session)\n       ├── auth()\n       ├── services()\n       ├── eventBus()\n       └── ...\n\nFlutterModule (per-module, lazy)\n  └── HomeModule.injections        ← scoped to module lifetime\n       ├── HomeController\n       └── HomeConsumer\n```\n\n \n\n## Registration Lifetimes\n\n    Type Usage Pattern     ` singleton ` One instance for app lifetime Dio, Session, Broker   ` lazySingleton ` Created on first use, then kept Controllers, Repositories   ` factory ` New instance every ` get<T>() ` call Usecases, one-time actions    \n\n## Step 1: Register in CoreInjections\n\n \n\nFile: ` core/lib/injections.dart `\n\n \n\nAdd a new static method for the domain group:\n\n \n\n```\nclass CoreInjections {\n  static List<Inject<Object>> core() => [\n    ...auth(),\n    ...services(),\n    ...eventBus(),\n    ...<module_name>(),  // ← ADD THIS\n  ];\n\n  // ← ADD THIS METHOD\n  static List<Inject<Object>> <module_name>() => [\n    Inject<<ModuleName>Datasource>(\n      (i) => <ModuleName>Datasource(i.find<Dio>()),\n    ),\n    Inject<<ModuleName>Repository>(\n      (i) => <ModuleName>RepositoryImpl(i.find<<ModuleName>Datasource>()),\n    ),\n  ];\n}\n```\n\n \n\n## Step 2: Register controller in the Module\n\n \n\nFile: ` modules/<module_name>/<module_name>_module.dart `\n\n \n\nExtend **` FlutterModule `** and override its two getters, ` injections ` and ` child `. ` FlutterModule ` is a ` StatelessWidget ` that wraps its ` child ` in a ` FlutterInjectionsWidget ` for you — don't build that wrapper by hand.\n\n \n\n```\nclass <ModuleName>Module extends FlutterModule {\n  const <ModuleName>Module({super.key});\n\n  @override\n  List<Inject<Object>> get injections => [\n        Inject<<ModuleName>Controller>.lazySingleton(\n          (i) => <ModuleName>Controller(\n            Get<ModuleName>Usecase(i.find<<ModuleName>Repository>()),\n          ),\n        ),\n      ];\n\n  @override\n  Widget get child => BlocProvider(\n        create: (_) => FlutterInjections.get<<ModuleName>Controller>(),\n        child: const <ModuleName>Screen(),\n      );\n}\n```\n\n \n\nBoth getters are ` @override ` — they are abstract on ` FlutterModule `, so omitting either is a compile error rather than a silent no-op.\n\n \n\n## Step 3: Resolve dependencies\n\n \n\n**In widgets/screens (via BlocProvider):**\n\n \n\n```\ncontext.read<<ModuleName>Controller>()\n```\n\n \n\n**Programmatic resolution (outside widget tree):**\n\n \n\n```\nfinal controller = FlutterInjections.get<<ModuleName>Controller>();\n```\n\n \n\n**Inside an Inject factory (chain resolution):**\n\n \n\n```\nInject<OrderController>.lazySingleton(\n  (i) => OrderController(\n    getOrders: i.find<GetOrdersUsecase>(),\n    broker:    i.find<Broker>(),\n  ),\n),\n```\n\n \n\n## Patterns to Follow\n\n \n\n### Usecase as factory (stateless, safe to create per-use)\n\n \n\n```\nInject<Get<ModuleName>Usecase>(\n  (i) => Get<ModuleName>Usecase(i.find<<ModuleName>Repository>()),\n),\n```\n\n \n\n### Controller as lazySingleton (stateful, one per scope)\n\n \n\n```\nInject<<ModuleName>Controller>.lazySingleton(\n  (i) => <ModuleName>Controller(i.find<Get<ModuleName>Usecase>()),\n),\n```\n\n \n\n### Repository as singleton (shared data layer)\n\n \n\n```\nInject<<ModuleName>Repository>(\n  (i) => <ModuleName>RepositoryImpl(i.find<<ModuleName>Datasource>()),\n),\n```\n\n \n\n## Event Bus DI\n\n \n\nWhen a module needs to publish/subscribe events via Broker:\n\n \n\n```\nInject<PaymentConsumer>(\n  (i) => PaymentConsumer(broker: i.find<Broker>()),\n),\n```\n\n \n\n## Common Mistakes to Avoid\n\n \n\n1. **Do NOT** register controllers in ` CoreInjections ` — they belong in the module scope \n1. **Do NOT** register usecases as singletons — they are stateless and should be factories \n1. **Always** use ` i.find<T>() ` inside Inject factory, never ` FlutterInjections.get<T>() ` (which bypasses scope) \n1. **Order matters** — list dependencies before dependents in the injections list\n\n \n\n## Instructions\n\n \n\n1. Read ` core/lib/injections.dart ` to understand existing registrations \n1. Find the right scope: global (CoreInjections) vs module-scoped (Module.injections) \n1. Apply the correct lifetime: singleton/lazySingleton/factory \n1. Register datasource → repository in Core; usecase + controller in Module \n1. Check for circular dependencies before registering\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- [Flutter Dependency Injection](<https://delaparra-services.nl/knowledge-hub/flutter-dependency-injection>)\n\n \n\n## Related services\n\n \n\n- [App development](<https://delaparra-services.nl/services#service-02>)\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-di)\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-di#webpage",
                "url": "https://delaparra-services.nl/skills/flutter-di",
                "name": "Flutter Di | DeLaParra Services",
                "description": "Use when registering or resolving a dependency with flutter_injections - adding a registration to the core injections, assembling a feature FlutterModule, choosing between singleton/lazySingleton/factory, or calling FlutterInjections.get. Triggers on a runtime \"dependency not registered\" error.",
                "isPartOf": {
                    "@id": "https://delaparra-services.nl/#website"
                },
                "about": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "inLanguage": "en",
                "breadcrumb": {
                    "@id": "https://delaparra-services.nl/skills/flutter-di#breadcrumb"
                }
            },
            {
                "@type": "BreadcrumbList",
                "@id": "https://delaparra-services.nl/skills/flutter-di#breadcrumb",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "name": "Home",
                        "item": "https://delaparra-services.nl/"
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "name": "Flutter Di"
                    }
                ]
            },
            {
                "@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-di#skill",
                "url": "https://delaparra-services.nl/skills/flutter-di",
                "name": "Flutter Di",
                "description": "Use when registering or resolving a dependency with flutter_injections - adding a registration to the core injections, assembling a feature FlutterModule, choosing between singleton/lazySingleton/factory, or calling FlutterInjections.get. Triggers on a runtime \"dependency not registered\" error.",
                "inLanguage": "en",
                "license": "https://spdx.org/licenses/MIT.html",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/skills/flutter-di#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/skills/flutter-di#dataset",
                "name": "Flutter Di",
                "description": "Use when registering or resolving a dependency with flutter_injections - adding a registration to the core injections, assembling a feature FlutterModule, choosing between singleton/lazySingleton/factory, or calling FlutterInjections.get. Triggers on a runtime \"dependency not registered\" error.",
                "url": "https://delaparra-services.nl/skills/flutter-di",
                "identifier": "https://delaparra-services.nl/skills/flutter-di#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/skills/flutter-di#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-di.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-di.csv",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-di.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-di.json",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-di.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-di.md",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-di.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-di.pdf",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-di.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-di.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "flutter-di-files.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/skills/flutter-di/download",
                        "inLanguage": "en",
                        "dateModified": "2026-11-30T13:17:19+00:00",
                        "license": "https://spdx.org/licenses/MIT.html"
                    }
                ]
            }
        ]
    }
}