Skip to main content

avoid_unused_parameters

Warns about unused function, method, constructor or factory parameters.

Example:

BAD:

typedef MaxFun = int Function(int a, int b);
final MaxFun bad = (int a, int b) => 1; // LINT
final MaxFun testFun = (int a, int b) { // LINT
return 4;
};
final optional = (int a, [int b = 0]) { // LINT
return a;
};
void fun(String x) {} // LINT
void fun2(String x, String y) { // LINT
print(y);
}

class TestClass {
static void staticMethod(int a) {} // LINT
void method(String s) {} // LINT

TestClass([int a]); // LINT
factory TestClass.named(int a) { // LINT
return TestClass();
}
}

GOOD:

typedef MaxFun = int Function(int a, int b);
final MaxFun good = (int a, int b) => a + b;
final MaxFun testFun = (int a, int b) {
return a + b;
};
void fun(String _) {} // Replacing with underscores silences the warning
void fun2(String _, String y) {
print(y);
}

class TestClass {
static void staticMethod(int _) {} // OK
void method(String _) {} // OK

TestClass([int _]); // OK
factory TestClass.named(int _) { // OK
return TestClass();
}
}

Allowed:

typedef Named = String Function({required String text});
final Named named = ({required text}) {
return '';
};