prefer-explicit-type-arguments
Warns when a method that accepts type arguments has no arguments and no type arguments passed.
warning
This rule is not compatible with avoid-inferrable-type-arguments
.
Example
❌ Bad:
class _MyAppState extends State<MyApp> {
late final A a;
late final B b;
void initState() {
super.initState();
a = context.read(); // LINT: Try adding type arguments to improve readability and avoid potential mistakes during a refactoring.
b = context.read(); // LINT: Try adding type arguments to improve readability and avoid potential mistakes during a refactoring.
}
Widget build(BuildContext context) {
return Widget();
}
}
✅ Good:
class _MyAppState extends State<MyApp> {
late final A a;
late final B b;
void initState() {
super.initState();
a = context.read<A>(); // Correct, explicit types
b = context.read<B>();
}
Widget build(BuildContext context) {
return Widget();
}
}