Skip to main content

prefer-explicit-type-arguments

added in: 1.11.0
🛠

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
b = context.read(); // LINT
}


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>();
b = context.read<B>();
}


Widget build(BuildContext context) {
return Widget();
}
}