set up
- create a new project
- add the dependencies visible under
additional information
- add the files below
- foos.dart
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'foos.g.dart';
@Riverpod(keepAlive: true)
class Foos extends _$Foos {
@override
List<String> build() => <String>[];
Future<void> initialize() => Future.sync(
() => state = [for (var i = 0; i < 100; ++i) 'foo'],
);
}
- bars.dart
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'foos.dart';
part 'bars.g.dart';
@Riverpod(keepAlive: true, dependencies: [Foos])
class Bars extends _$Bars {
@override
List<String> build() => <String>[];
Future<void> initialize() =>
Future.sync(() => [for (final _ in ref.read(foosProvider)) 'bar']);
}
description
in Bars
' riverpod annotation dependencies
@Riverpod(keepAlive: true, dependencies: [Foos])
Foos shows the error below
If a provider depends on providers which specify "dependencies", they should themselves specify "dependencies" and include all the scoped providers. dart(provider_dependencies)
question
can someone help me understand the meaning of this error
and how do I solve it?
additional information
- pubspec.yaml
environment:
sdk: '>=2.19.4 <3.0.0'
dependencies:
flutter:
sdk: flutter
flutter_riverpod: ^2.3.0
riverpod_annotation: ^2.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1
build_runner: ^2.3.3
custom_lint: ^0.3.2
riverpod_lint: ^1.1.5
riverpod_generator: ^2.0.0
flutter:
uses-material-design: true
- analysis_options.yaml
include: package:flutter_lints/flutter.yaml
analyzer:
exclude:
- "**/*.g.dart"
plugins:
- custom_lint
You can find the lint's explanation and fixes here.
TL;DR: your
Bars
does not depend onFoos
. You can see that there's noref.watch(foosProvider)
in itsbuild
method. Thus, the lint is triggered asdependencies
shouldn't includeFoos
.Instead, if your
initialize
method was meant to be used onbuild
, you should put its contents in there, specify the dependency throughref.watch
and add it todependencies
in the annotation, like so: