Skip to content

Focus based navigation needs to have the widget Rect. #30084

Description

@gspencergoog

In order to be able to perform focus-based navigation, it is necessary to know the size and location of widgets that might be traversed to.

This is a tracking issue for the breaking change needed to collect this information, in order to fix #1608.

Currently, FocusScopeNode.reparentIfNeeded takes only the FocusNode that it will reparent. In order to provide services needed for keyboard focus traversal, this method will need to provide a BuildContext in order to be able to measure its size and location when determining the next widget to traverse to.
We propose to break the FocusScopeNode API by changing it's signature from:

void reparentIfNeeded(FocusNode node);

to

void reparentIfNeeded(BuildContext context, FocusNode node);

To modify code to compile again after this change, you would need to add a context argument to the call.  Typically, this method is called from a build method in order to keep the focus tree up to date with the widget tree, so instead of calling:

FocusScope.of(context).reparentIfNeeded(focusNode);

You would instead call:

FocusScope.of(context).reparentIfNeeded(context, focusNode);

Activity

  1. self-assigned this
    on Mar 28, 2019
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: API breakBackwards-incompatible API changes
    on Mar 28, 2019
  3. added 2 commits that reference this issue on Apr 22, 2019
    4218c0b
    7775c23
  4. xiaoxiaohaozi commented on Jul 23, 2019

    @xiaoxiaohaozi

    Error: The method 'reparentIfNeeded' isn't defined for the class 'FocusScopeNode'.

    • 'FocusScopeNode' is from 'package:flutter/src/widgets/focus_manager.dart' ('file:///Users/Macro/Documents/Flutter/flutter/packages/flutter/lib/src/widgets/focus_manager.dart').
      Try correcting the name to the name of an existing method, or defining a method named 'reparentIfNeeded'.
      FocusScope.of(context).reparentIfNeeded(context,node);

    how to modify it ? thank you
    tip: [✓] Flutter (Channel stable, v1.7.8+hotfix.3, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)

  5. gspencergoog commented on Jul 23, 2019

    @gspencergoog
    ContributorAuthor

    @xiaoxiaohaozi, you need to use a FocusAttachment instead. See the documentation for FocusNode for an example. The focus system has changed quite a lot since reparentIfNeeded was used. You might also consider switching to use the new Focus or FocusScope widgets to manage the focus node for you.

  6. github-actions commented on Aug 29, 2021

    @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.

  7. locked as resolved and limited conversation to collaborators on Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: desktopRunning on desktopc: API breakBackwards-incompatible API changesframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions