Dependency Scope

Dependency Scope is a Flutter package designed to facilitate the use of Dependency Injection (DI) in Flutter projects. This package provides a straightforward way to manage dependencies, improving code modularity and testability.

Features

  • Simplifies dependency injection setup in Flutter applications.
  • Enhances code maintainability and readability.
  • Supports easy and efficient management of app-wide dependencies.

Installation

  • Add the following to your pubspec.yaml file:
dependencies:
  dependency_scope: ^1.1.0

Getting started

  • Setup: Initialize the DependencyScope in your main app file.
  • Register Dependencies: Register your dependencies in the DependencyScope.
  • Inject Dependencies: Use the provided methods to inject dependencies where needed.

Usage

Include short and useful examples for package users. Add longer examples to /example folder.

final class AppDependency extends DependencyScope {
  late final String title;

  @override
  Future<void> initialization() async {
    title = await create(() => 'Flutter DI');
  }
}

And

class App extends StatelessWidget {
  final AppDependency appDependency;

  const App({super.key, required this.appDependency});

  @override
  Widget build(BuildContext context) {
    return DependencyProvider<AppDependency>(
      dependency: appDependency,
      child: const MaterialApp(
        home: MyHomePage(),
      ),
    );
  }
}

After this you can use DI with context extension

final appDependency = context.get<AppDependency>();