Take this code for example:
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
//returns widget
}
}
What I know
MyApp
is constructor for the class which has field key
. Initializer list consists of super(key: key)
.
So does it mean that I am assigning the key
of MyApp
to the key
of its super constructor?
Is the super constructor StatelessWidget
?
Why do we need to assign key
to the super
?
What happens if I don't do this initializing?
I am new to flutter and am trying to understand how things work, and why. Please help!