I saw two ways to declare variables with StatefulWidget in many sample codes.
- initialize variable with value (firstCase)
- initialize variable without value and assign to value inside of initState (secondCase)
Is there any difference between these? Or which one would be better code in practice?
class Sample extends StatefulWidget {
Sample({Key key}) : super(key: key);
@override
_SampleState createState() => _SampleState();
}
class _SampleState extends State<Sample> {
bool firstCase = false;
bool secondCase;
@override
void initState() {
secondCase = false;
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
child: child,
);
}
}