variable_pattern_keyword_in_declaration_context
Variable patterns in declaration context can't specify 'var' or 'final' keyword.
Description
#The analyzer produces this diagnostic when a variable pattern is used within a declaration context.
Example
#The following code produces this diagnostic because the variable patterns in the record pattern are in a declaration context:
dart
void f((int, int) r) {
var (var x, y) = r;
print(x + y);
}
Common fixes
#Remove the var
or final
keyword(s) within the variable pattern:
dart
void f((int, int) r) {
var (x, y) = r;
print(x + y);
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.