Last updated:
0 purchases
injecta
Injecta #
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.2.0
copied to clipboard
Then, run:
flutter pub get
copied to clipboard
Usage #
Create a ServiceRegistry
Create your registry using ServiceRegistry. Pass a list of functions that create instances of your services to the services parameter.
final services = ServiceRegistry(
services: [
() => CounterService(),
],
);
copied to clipboard
Access Services in your Widgets
Use the context.get<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: () {
services.get<CounterService>().increment();
setState(() {});
},
child: Text('${services.get<CounterService>().counter}'),
);
}
}
copied to clipboard
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.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.