I am wondering when I know the initial value to a variable in a State class in Flutter, whether I should initialize it with the variable definition or inside initState method. What is better and why?
First method:
class _SampleState extends State<Sample> {
String _foo = 'FOO';
@override
void initState() {
// Do some other stuff
super.initState();
}
...
}
Second method:
class _SampleState extends State<Sample> {
String _foo;
@override
void initState() {
_foo = 'FOO';
// Do some other stuff
super.initState();
}
...
}