Search code examples
flutterdartvisual-studio-codevscode-debugger

what is the use of keys and const


in every time I write a code in vscode editor. every time I get an error the use key in widgets and also giving me an alert that prefer to use const constructor but what is the real use of it


Solution

  • Those widgets which not need to rebuild every time the build() is called, are defined with const keyword. This improves performance of the app, and is best practice to use const keyword with widgets which need no update. Talking about keys, keys are identifiers for widgets and help Flutter to distinguish between different widgets so that their respective state remain with them, instead of getting assigned to another similar widget.