injecta 0.1.0 copy "injecta: ^0.1.0" to clipboard
injecta: ^0.1.0 copied to clipboard

outdated

Library that provides a simple and efficient service registry

Injecta #

Code license (MIT) GitHub release (latest by date) GitHub issues

Injecta is a lightweight Flutter library that provides a simple and efficient service registry for managing dependencies in your Flutter applications. It can be used instead of InheritedWidget or Provider to access objects e.g. from your UI.

Installation #

To use Injecta in your Flutter project, add the following dependency to your pubspec.yaml file:

dependencies:
  injecta: ^0.1.0

Then, run:

flutter pub get

Usage #

  1. Create a ServiceRegistry
    Wrap your MaterialApp or any other widget with a ServiceRegistry. Pass a list of functions that create instances of your services to the services parameter.
ServiceRegistry(
    services: [
        () => CounterService(),
    ],
    child: const HomeScreen(),
),
  1. Access Services in your Widgets
    Use the context.read<T>() method to access services within your widgets. The services will be lazily initialized and cached.
class _HomeScreenState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        context.read<CounterService>().increment();
        setState(() {});
      },
      child: Text('${context.read<CounterService>().counter}'),
    );
  }
}

Contributing #

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License #

Injecta is distributed under the MIT License. See the LICENSE.md file for more information.

6
likes
0
points
13
downloads

Publisher

verified publisherkalucky0.dev

Weekly Downloads

Library that provides a simple and efficient service registry

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on injecta