injectable
injectable copied to clipboard
The annotation 'preResolve' can only be used on methods.
After upgrading to the latest version 2.4.1, I'm getting the following warning in one of the examples used in the documentation:
The annotation 'preResolve' can only be used on methods
@module
abstract class RegisterModule {
@preResolve
Future<SharedPreferences> get prefs => SharedPreferences.getInstance();
}
same
in analysis_options.yaml
analyzer:
exclude:
- "**/locale_keys.g.dart"
# - "**/*.g.dart"
# - "**/*.freezed.dart"
errors:
invalid_annotation_target: ignore # hotfix for freezed @JsonKey and injectable @preResolve
in analysis_options.yaml
analyzer: exclude: - "**/locale_keys.g.dart" # - "**/*.g.dart" # - "**/*.freezed.dart" errors: invalid_annotation_target: ignore # hotfix for freezed @JsonKey and injectable @preResolve
Ignoring the warnings is not a solution.
Switching from getter to a method like this will solve the warning
@module
abstract class RegisterModule {
@preResolve
Future<SharedPreferences> prefs() async => await SharedPreferences.getInstance();
}
If preResolve shuold no longer be used with getter, the documentation should also change the example to avoid confusion.
fixed