Invalid Constant Value using variable as parameter

In dart when you pass something as a parameter in a const constructor, the compiler makes sure that the value set as default is not changed during the execution of the code.

Hence, the Invalid constant value warning.

To resolve this issue you should remove the const keyword from the in front of the Text.


Don't use the const keyword if you are not using fixed values.


You are declaring your Text widget as a const, which requires all of its children to be const as well. If you want to fix this, you should not use a const Text widget in this case as you want to pass a non-const variable.

The reason for this is that Flutter uses the const keyword as an idicator for a widget to never rebuild as it will get evaluated at compile time and only once. Hence, every part of it has to be constant as well.

double textSize = 10.04;
// ...
child: Text('Calculate Client Fees', style: TextStyle(fontSize: textSize))

Read more about it in this article.

Tags:

Dart

Flutter