Skip to main content

avoid-function-type-in-records

added in: 1.5.0
Dart 3.0+
Pro+

Warns when a record type declaration contains a function type.

Records are usually treated as a way to group data, not behavior. Consider passing an instance of a class instead.

Example

❌ Bad:

// LINT: Avoid function types inside records. Try creating a class with methods instead.
(String, void Function()) regular() => ('str', () {});

// LINT: Avoid function types inside records. Try creating a class with methods instead.
({void Function() f}) named() => (f: () {},);

// LINT: Avoid function types inside records. Try creating a class with methods instead.
typedef NullableRecord = ({String str, int Function() f});

✅ Good:

class WithBehavior {
void fn() {...}
}

WithBehavior regular() => WithBehavior(...);

typedef NullableRecord = ({String str, int executionResult}); // Correct, no functions

Additional Resources