Answer the question
In order to leave comments, you need to log in
Flutter. Error Can't access 'this' in a field initializer to read 'a'. var c = a + 1; ^?
Hello connoisseurs. Please help me figure out why it is not possible to declare a variable c using another variable. Here is my code.
class why extends StatefulWidget {
@override
_whyState createState() => _whyState();
}
class _whyState extends State {
int a = 1;
var c = a + 1;
@override
Widget build(BuildContext context) {
return Container();
}
}
Answer the question
In order to leave comments, you need to log in
of course it won’t work, it’s not js or python (it seems to work there), your variables are at the same level, either take out “a” as global, or initialize “c” in the function
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question