'"Use key in widget constructors" warning each time I create a new widget

I've started getting a warning every time I create a new class.

enter image description here

Use key in widget constructors.

Prefer const with constant constructor.

and so on. Where these errors are coming from and how do I get rid of it?



Solution 1:[1]

add this in your code right before the @override line

const FooPage({Key? key}) : super(key: key);

always add const before the widget command like EdgeInsets, spacer, SizedBox, BorderRadius etc

Solution 2:[2]

You can use prefer_const_constructors : false in analysis_options.yaml

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jilan Dirgantara
Solution 2 kksal55