What is the impact of final function parameters in Dart?

Viewed 284

I recently found out it was possible to include final in function parameters.

/// Handler for the footer leading checkbox
void _onCheck(final bool value) {
  setState(() {
    _checked = value;
  });
}

However, this feature is not documented anywhere and it's impossible to search any information regarding this topic.

Since the value being passed to the function was already declared elsewhere and could've used var, what are the impacts of using final in function parameters?

1 Answers

It works like declaring any other variable as final - the variable cannot be changed after it has been initialized. A parameter is really just a local variable where the initializing value comes from the caller instead of a local expression.

So here, you would get an error if you write value = false; in the function because value is a final variable. You would get no error if you removed the final.

Other than that, there is no difference.

Related