-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
injectable environments are broken #419
Comments
Injectable, LazySingleton, and Singleton annotations are also not working at all. The lowercase variants work, but only when no environment is specified. |
Facing the same issue, I have a big multi-package project with multiple environments Flutter Version: |
@stalinkay found any workarounds for this? |
I have found very interesting quirks and inconsistencies in I have stopped trying to use environments even though I'm somehow still passing prod to injectable. I also figured out that in the case of subclasses that are bound to an abstract class. It's better to use getIt(instanceName: ''). This is not documented AFAIK but it showed up in my generated injectable.config.dart Example of AnalyticsService subclasses:
It's not possible to annotate abstract classes unless they are base/abstract classes. One last thing: I've also picked up cases where changing the annotation from to @Injectable works but @lazySingleton would through an error when generating the injectable.config.dart. Can't remember the exact issue there but it's something along that line. I'll attempt to use environments again once my code base is stable. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions |
I have this same issue. Seems there is a PR (#408, ping @Milad-Akarie ) with a fix that has not yet been merged. |
EDIT The fix has now been merged and this comment is therefore outdated. I have now confirmed that the fix in #408 works for me and set up a fork that can be used as a workaround until the PR is merged. The fork was necessary as To use the fix for #408 before it has been merged, update your dependencies:
# injectable: ^2.3.2
injectable:
git:
url: https://github.com/FelixZY/injectable.git
path: injectable
ref: fix-singleton-environment-filter
dev_dependencies:
# injectable_generator: ^2.4.1
injectable_generator:
git:
url: https://github.com/FelixZY/injectable.git
path: injectable_generator
ref: fix-singleton-environment-filter |
Hi @FelixZY, I checked out your repo, but the issue persists. I believe the root cause might be an incorrect order of injectable registration. According to the official documentation, injectable are reordered based on their dependencies. In other words, if A depends on B, B should be registered first. However, in the current version, B seems to be registered after A. Consequently, when |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions |
Greetings, @Milad-Akarie!
I just discovered injectable. Love it, but I can't use environments. If I remove environments, everything works fine. I have tried to get it to work for the past 3 days but no luck. I believe the package breaks when newer Flutter and/or Dart. Or am I doing something wrong?
Creating a new Flutter project with the latest injectable and get_it versions results in the following error:
Steps to reproduce:
flutter create injectable_environments
flutter pub add injectable get_it
flutter pub add build_runner injectable_generator --dev
dart run build_runner watch
to create injectable.config.dart fileflutter run
lib/main.dart
lib/test.dart
lib/concretetest.dart
lib/injectable.dart
Flutter environment:
The text was updated successfully, but these errors were encountered: