This code snippet
class SomeWidget extends StatelessWidget {
final String aString;
SomeWidget(this.aString);
compiles without error or warning. However, this code snippet
class SomeWidget extends StatelessWidget {
final String aString;
SomeWidget(String inputString) {
this.aString=inputString;
}
gives an error message that all final variables must be initialized and aString isn't, and how aString can't be used as a setter because it's final. Removing the final
keyword eliminates the error messages.
I'm unclear what's going on here. I saw this and this SO item, but honestly I'm still struggling to understand. I think the problem, for me, stems from how I was taught my two code snippets are functionally identical.