Skip to content

API doc clarification request: if a key is not provided for a widget, what is default key? #13787

Closed

Description

@sethladd

Trying to learn about keys, and I found https://docs.flutter.io/flutter/foundation/Key-class.html

One of my initial questions was: "what is the "default" key?" and "if I don't provide a key, what's the default?"

I also checked https://docs.flutter.io/flutter/widgets/Widget/key.html and didn't find an obvious answer.

Activity

  1. changed the title [-]API doc clarification request: if a key is not provided for a widget, what happens?[/-] [+]API doc clarification request: if a key is not provided for a widget, what is default "key"?[/+] on Dec 28, 2017
  2. Hixie commented on Jan 2, 2018

    @Hixie
    Contributor

    The default key is null, i.e. no key.

  3. Hixie commented on Jan 2, 2018

    @Hixie
    Contributor

    Also we could add the following when adding docs to keys:

    Basically any time you're building a list of widgets from a list of data, and the list might change, you should key the children, so that we keep the subtrees tied to the data. Otherwise, we won't know what's going on and if anything is stateful the state could spill from one to the other (what's really going on is that the data is spilling from one to the other -- we have no way to distinguish "each item changed its data" from "one of the items was removed/added and pushed all the other items around" without keys).

    Generally the best key to use is a ValueKey where T is the type of the data you're generating the widgets from, assuming that each such datum is unique. (In particular, no need to use toString.)

  4. added this to the milestone on Jan 2, 2018
  5. wmleler commented on Jan 2, 2018

    @wmleler

    Several people (including at least one flutter team member) have been bitten recently by the confusion mentioned by Ian. Would be nice to add language like his to the docs sooner rather than later.

  6. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Dec 3, 2018
  7. changed the title [-]API doc clarification request: if a key is not provided for a widget, what is default "key"?[/-] [+]API doc clarification request: if a key is not provided for a widget, what is default key?[/+] on Jan 13, 2020
  8. added
    P2Important issues not at the top of the work list
    on May 29, 2020
  9. pedromassangocode commented on Jul 22, 2020

    @pedromassangocode

    Found in the current docmunetation because it does not state what it the default key value when not provided.

    I looked at the following links:
    https://docs.flutter.io/flutter/foundation/Key-class.html
    https://docs.flutter.io/flutter/widgets/Widget/key.html

  10. removed this from the milestone on Aug 17, 2020
  11. danagbemava-nc commented on Nov 1, 2022

    @danagbemava-nc
    Member

    The current documentation does not state which key is used either.

    I checked the following links:
    https://api.flutter.dev/flutter/widgets/Widget/key.html
    https://api.flutter.dev/flutter/foundation/Key-class.html

  12. added a commit that references this issue on May 28, 2026
    ba09ef4
  13. added a commit that references this issue on Jun 26, 2026
    544a79f
  14. github-actions commented on Jul 14, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/found in release: 3.3Found to occur in 3.3found in release: 3.5Found to occur in 3.5frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions