injectable icon indicating copy to clipboard operation
injectable copied to clipboard

The annotation 'preResolve' can only be used on methods.

Open jamontes79 opened this issue 2 years ago • 5 comments

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();
}

jamontes79 avatar Apr 02 '24 10:04 jamontes79

same

user97116 avatar Apr 04 '24 03:04 user97116

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

phamconganh avatar May 10 '24 02:05 phamconganh

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.

jamontes79 avatar May 10 '24 06:05 jamontes79

Switching from getter to a method like this will solve the warning

@module
abstract class RegisterModule {
  @preResolve
   Future<SharedPreferences> prefs() async => await SharedPreferences.getInstance();
}

mllrr96 avatar May 13 '24 20:05 mllrr96

If preResolve shuold no longer be used with getter, the documentation should also change the example to avoid confusion.

sabifa avatar May 17 '24 05:05 sabifa

fixed

Milad-Akarie avatar Jul 21 '24 14:07 Milad-Akarie