Most of the time you don't need to use a widget key in Flutter. A new widget will only be used to update an existing element if its key is the same as the key of the current widget associated with that element.
When You Need Keys
Keys become important in specific situations.
Key Use Cases
You need keys to:
- clone a widget state across multiple pages or tabs
- change a widget order inside a list
- preserve scroll position
- identify widgets and their state
- identify for test
How Keys Work
Key allows Flutter to link an element from the ElementTree and a widget. If you change swap two widgets with keys in the widget tree, Flutter will also swap these in the element tree.