null_closures

Group: style

Maturity: stable

Linter v0.1.56

Since info is static, may be stale
recommendedflutterpedantic

View all Lint Rules

Using the Linter

DO NOT pass null as an argument where a closure is expected.

Often a closure that is passed to a method will only be called conditionally, so that tests and "happy path" production calls do not reveal that null will result in an exception being thrown.

This rule only catches null literals being passed where closures are expected in the following locations:

Constructors

Static functions

Instance methods

BAD:

[1, 3, 5].firstWhere((e) => e.isOdd, orElse: null);

GOOD:

[1, 3, 5].firstWhere((e) => e.isOdd, orElse: () => null);