Open stalinkay opened 11 months ago
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
Getting the following during building phase
[SEVERE] injectable_generator:injectable_config_builder on lib/feature/user/data/repository/in_app_purchase_repository.dart (cached): This builder requires Dart inputs without syntax errors.
This started happening after I have upgraded flutter to 3.16.1/2
Flutter Version: Flutter 3.16.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 9e1c857886 (4 days ago) • 2023-11-30 11:51:18 -0600 Engine • revision cf7a9d0800 Tools • Dart 3.2.2 • DevTools 2.28.3
@stalinkay found any workarounds for this?
@stalinkay found any workarounds for this?
@mosabalrsaheed
I have found very interesting quirks and inconsistencies in injectable
and its docs.
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:
AnalyticsService branchServicce =
getIt(instanceName: 'BranchAnalyticsService');
AnalyticsService oneSignalService =
getIt(instanceName: 'OneSignalAnalyticsService');
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 injectable_generator
has a relative dependency on injectable
in @lrampazzo 's branch. Relative dependencies are not supported when referencing remote git repositories and so I had to update this dependency.
To use the fix for #408 before it has been merged, update your pubspec.yaml
:
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 get_it
tries to create a new instance of A, it cannot find B, leading to the issue happened.
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: