key method

Widget key(
  1. Key key
)

Assigns a Key to this widget.

Keys are used to preserve state when widgets move around in the tree. This method provides a fluent way to assign a key to a widget.

Example:

Container().key(GlobalKey()),
Text('Hello').key(UniqueKey()),

Implementation

Widget key(Key key) {
  return _WidgetWrapper._wrapOrCopyWith(
    child: this,
    key: () => key,
  );
}