{"id":45161464,"url":"https://github.com/alexhcjp/depend","last_synced_at":"2026-02-20T06:00:27.588Z","repository":{"id":256095387,"uuid":"854313169","full_name":"AlexHCJP/depend","owner":"AlexHCJP","description":"dependencies is a Flutter package for managing dependencies and initializing them before the app starts. It provides easy access to dependencies and logs initialization times for performance tracking.","archived":false,"fork":false,"pushed_at":"2026-02-18T10:47:48.000Z","size":218,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-18T15:19:14.622Z","etag":null,"topics":["dependency","dependency-injection","flutter"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/depend","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexHCJP.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-08T23:46:13.000Z","updated_at":"2026-02-18T10:47:51.000Z","dependencies_parsed_at":"2024-10-01T00:53:06.592Z","dependency_job_id":"b60a7026-0116-4ab7-90d3-03af3d83c00a","html_url":"https://github.com/AlexHCJP/depend","commit_stats":null,"previous_names":["alexhcjp/dependencies","alexhcjp/depend","contributors-company/depend"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/AlexHCJP/depend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexHCJP%2Fdepend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexHCJP%2Fdepend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexHCJP%2Fdepend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexHCJP%2Fdepend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexHCJP","download_url":"https://codeload.github.com/AlexHCJP/depend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexHCJP%2Fdepend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29642901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T05:21:04.652Z","status":"ssl_error","status_checked_at":"2026-02-20T05:21:04.238Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency","dependency-injection","flutter"],"created_at":"2026-02-20T06:00:22.741Z","updated_at":"2026-02-20T06:00:27.560Z","avatar_url":"https://github.com/AlexHCJP.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Logo](screenshots/depend-frame.png)\n![Frame](screenshots/contributors.png)\n\n![Pub Version](https://img.shields.io/pub/v/depend)\n![License](https://img.shields.io/github/license/AlexHCJP/depend)\n![Coverage](https://img.shields.io/codecov/c/github/contributors-company/depend)\n![Stars](https://img.shields.io/github/stars/AlexHCJP/depend)\n\n`depend` is a library for dependency management in Flutter applications. It provides a convenient way to initialize and access services and repositories via `InheritedWidget`.\n\n---\n\n## Features 🚀\n\n- **Dependency Initialization:** Prepare all dependencies before the app launches.\n- **Global Access:** Access dependencies from anywhere in the widget tree.\n- **Parent Dependencies Support:** Easily create nested or connected dependencies.\n- **Ease of Use:** Integrate the library into existing code with minimal changes.\n\n---\n\n## Table of Contents\n\n- [Features 🚀](#features-)\n- [Table of Contents](#table-of-contents)\n- [Installation](#installation)\n- [Usage Examples](#usage-examples)\n  - [Example 1: Simple Initialization](#example-1-simple-initialization)\n    - [Step 1: Define the Dependency](#step-1-define-the-dependency)\n    - [Step 2: Define the DependencyFactory](#step-2-define-the-dependencyfactory)\n    - [Step 3: Use `DependencyScope`](#step-3-use-dependencyscope)\n    - [Step 4: Access the Dependency in a Widget](#step-4-access-the-dependency-in-a-widget)\n  - [Example 2: `DependencyProvider`](#example-2-dependencyprovider)\n  - [Example 3: `DependencyScope`](#example-3-dependencyscope)\n  - [Example 4: Lazy Initialization](#example-4-lazy-initialization)\n    - [Using `LazyGet` for Synchronous Dependencies](#using-lazyget-for-synchronous-dependencies)\n    - [Using `LazyFutureGet` for Asynchronous Dependencies](#using-lazyfutureget-for-asynchronous-dependencies)\n- [Migration Guide](#migration-guide)\n- [Code Coverage](#code-coverage)\n\n---\n\n## Installation\n\nAdd the library to the `pubspec.yaml` of your project:\n\n```yaml\ndependencies:\n  depend: ^latest_version\n```\n\nInstall the dependencies:\n\n```bash\nflutter pub get\n```\n\n---\n\n## Usage Examples\n\n### Example 1: Simple Initialization\n\n#### Step 1: Define the Dependency\n\nCreate a class that extends `DependencyContainer` and initialize your dependencies:\n\n```dart\nclass RootContainer extends DependencyContainer {\n  final ApiService apiService;\n\n  RootContainer({required this.apiService});\n\n\n  void dispose() {\n    apiService.dispose();\n  }\n}\n```\n\n\n#### Step 2: Define the DependencyFactory\n\nCreate a class that extends `DependencyContainer` and initialize your dependencies:\n\n```dart\nclass RootDependencyFactory extends DependencyFactory\u003cRootContainer\u003e {\n  \n  Future\u003cRootContainer\u003e create() async {\n    return RootContainer(\n      apiService: await ApiService.initialize(),\n    );\n  }\n  \n  // or\n\n  RootContainer create() {\n     return RootContainer(\n        apiService: ApiService.initialize(),\n     );\n  }\n}\n```\n\n#### Step 3: Use `DependencyScope`\n\nWrap your app in a `DependencyScope` to provide dependencies:\n\n```dart\nvoid main() {\n  runApp(\n    DependencyScope\u003cRootContainer, RootFactory\u003e(\n       factory: RootFactory(), \n       placeholder: const Center(child: CircularProgressIndicator()), \n       builder: (BuildContext context) =\u003e const MyApp(),\n    ),\n  );\n}\n```\n\n#### Step 4: Access the Dependency in a Widget\n\nYou can now access the dependency using `DependencyProvider` anywhere in the widget tree:\n\n```dart\nclass MyWidget extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    final apiService = DependencyProvider.of\u003cRootContainer\u003e(context).apiService;\n\n    return FutureBuilder(\n      future: apiService.getData(),\n      builder: (context, snapshot) {\n        if (snapshot.connectionState == ConnectionState.waiting) {\n          return const CircularProgressIndicator();\n        } else if (snapshot.hasError) {\n          return Text('Error: ${snapshot.error}');\n        }\n\n        return Text('Data: ${snapshot.data}');\n      },\n    );\n  }\n}\n```\n\n---\n\n### Example 2: `DependencyProvider`\n\n```dart\nfinal RootContainer dep = await RootFactory().create();\n\nDependencyProvider\u003cRootContainer\u003e(\n  dependency: dep,\n  builder: () =\u003e YourWidget();\n  // or\n  child: YourWidget()\n)\n\nclass YourWidget extends StatelessWidget {\n  @override\n  Widget build(BuildContext) {\n    root = DependencyProvider.of\u003cRootContainer\u003e(context);\n    ...\n  }\n}\n```\n\n### Example 3: `DependencyScope`\n\n```dart\nDependencyScope\u003cRootContainer, RootFactory\u003e(\n      factory: RootFactory(),\n      builder: (BuildContext context) =\u003e Text('Inject'),\n      placeholder: Text('Placeholder'),\n      errorBuilder: (Object? error) =\u003e Text('Error'),\n    ),\n```\n\n---\n\n### Example 4: Lazy Initialization\n\nThe library provides `LazyGet` and `LazyFutureGet` classes for lazy initialization of services. Dependencies are created only when they are first accessed, which improves application startup time.\n\n#### Using `LazyGet` for Synchronous Dependencies\n\n```dart\nclass RootContainer extends DependencyContainer {\n  // Service will be created only when accessed for the first time\n  final LazyGet\u003cApiService\u003e apiService;\n  final LazyGet\u003cDatabaseService\u003e database;\n}\n\nclass RootDependencyFactory extends DependencyFactory\u003cRootContainer\u003e {\n  RootContainer create() {\n     return RootContainer(\n        apiService: lazyGet(ApiService.initialize),\n        database: lazyGet(DatabaseService.initialize),\n     );\n  }\n}\n\n// Usage in widgets\nclass MyWidget extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    final container = DependencyProvider.of\u003cRootContainer\u003e(context);\n    \n    // ApiService is created only at this moment\n    final api = container.apiService();\n    \n    return Text('Service initialized: ${api}'); // Instance: ApiService\n  }\n}\n```\n\n#### Using `LazyFutureGet` for Asynchronous Dependencies\n\n```dart\nclass RootContainer extends DependencyContainer {\n  final LazyFutureGet\u003cDatabaseService\u003e database;\n      \n  final LazyFutureGet\u003cAuthService\u003e authService;\n}\n\nclass RootDependencyFactory extends DependencyFactory\u003cRootContainer\u003e {\n  RootContainer create() {\n     return RootContainer(\n        apiService: lazyFutureGet(ApiService.initialize),\n        database: lazyFutureGet(DatabaseService.initialize),\n     );\n  }\n}\n\n// Usage in widgets\nclass MyWidget extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    final container = DependencyProvider.of\u003cRootContainer\u003e(context);\n    \n    return FutureBuilder\u003cDatabaseService\u003e(\n      // Database is initialized only when this widget is built\n      future: container.database(),\n      builder: (context, snapshot) {\n        if (snapshot.connectionState == ConnectionState.waiting) {\n          return CircularProgressIndicator();\n        }\n        \n        return Text('Database ready: ${snapshot.data?.isConnected}');\n      },\n    );\n  }\n}\n```\n\n**Benefits of Lazy Initialization:**\n\n- **Faster App Startup:** Dependencies are created only when needed\n- **Memory Optimization:** Unused services don't consume memory\n- **Flexible Initialization:** You can control when heavy operations are performed\n- **Simple API:** Easy to use with both sync and async dependencies\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexhcjp%2Fdepend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexhcjp%2Fdepend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexhcjp%2Fdepend/lists"}