what does super and Key do in flutter?

Keys are used as an identifier for Widgets, Elements and SemanticsNodes.You don't need to use Keys most of the time, the framework handles it for you and uses them internally to differentiate between widgets. For more on them see: https://flutter.dev/docs/development/ui/widgets-intro#keys

As for the Super keyword:

We see in your example the CardTitle widget extends the super class statelesswidget and in its constructor the ":" starts the "initializer list", a comma separated list of expressions executed before the constructors of the super classes and therefore also before the constructors body.

In the example in your question the key parameter passed to the constructor is forwarded to the named parameter key of the unnamed constructor of the super class.


super is used to call the constructor of the base class. So in your example, the constructor of CardTitle is calling the constructor of StatelessWidget.

Key is a type used in Flutter to identify widgets and allows Flutter to know when a widget that's moved in the tree is the same as a widget that was previously in a different location. There's a good video about keys here: https://www.youtube.com/watch?v=kn0EOS-ZiIc

Tags:

Dart

Flutter