Skip to content

Focus sometimes lost when focus move in the GridView #34153

@boyan01

Description

@boyan01

I am an AndroidTV developer, so it is excited to see that flutter support Focus shifts in different widget.

But it seems to the FocusManager have some problems in the GridView. When using the controller or keyboard to move the focus, the focus sometimes got lost.

Here is a gif example:
focus_loss

GIf is running on macOS, Android also has the same problem when using the remote control

Steps to Reproduce

gif example source code is here : https://github.com/boyan01/flutter_focus_loss

It's easy to reproduce, just press the navigation key to move the focus up and down.

Logs

This is the key log when the focus has been lost,It seems that FocusManager's primary focus does not have an ancestor. maybe this is the cause

flutter: ERR: the focus has been loss
flutter: primary focus:FocusNode#9d55a(context: Focus, FOCUSED)
flutter: primary focus ancestor: :()
flutter: FocusManager#07390
flutter:  │ currentFocus: FocusNode#9d55a
flutter:  │
flutter:  └─rootScope: FocusScopeNode#96475
flutter:    │ debugLabel: "Root Focus Scope"
flutter:    │ focusedChild: FocusScopeNode#78b3f
flutter:    │
flutter:    └─Child 1: FocusScopeNode#78b3f
flutter:      │ context: FocusScope
flutter:      │ debugLabel: "Navigator Scope"
flutter:      │ focusedChild: FocusScopeNode#f41e2
flutter:      │
flutter:      └─Child 1: FocusScopeNode#f41e2
flutter:        │ context: FocusScope
flutter:        │ debugLabel: "_ModalScopeState<dynamic> Focus Scope"
flutter:        │ focusedChild: FocusScopeNode#9625d
flutter:        │
flutter:        └─Child 1: FocusScopeNode#9625d
flutter:          │ context: FocusScope
flutter:          │ focusedChild: FocusNode#107c4
flutter:          │
flutter:          ├─Child 1: FocusNode#107c4
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 2: FocusNode#cab25
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 3: FocusNode#7e80d
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 4: FocusNode#a2324
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 5: FocusNode#16794
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 6: FocusNode#96fcd
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 7: FocusNode#8aa87
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 8: FocusNode#f3cd7
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 9: FocusNode#c40c0
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 10: FocusNode#3d090
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 11: FocusNode#9d015
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 12: FocusNode#0ccba
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 13: FocusNode#17a06
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 14: FocusNode#c7fb3
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 15: FocusNode#bc2be
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 16: FocusNode#81c77
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 17: FocusNode#1bd7d
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 18: FocusNode#ba30a
flutter:          │   context: Focus
flutter:          │
flutter:          ├─Child 19: FocusNode#4b07c
flutter:          │   context: Focus
flutter:          │
flutter:          └─Child 20: FocusNode#77eaa
flutter:              context: Focus
flutter: 

Flutter version


  [✓] Flutter (Channel master, v1.7.4-pre.30, on Mac OS X 10.14.5 18F132, locale
    zh-Hans-CN)
    • Flutter version 1.7.4-pre.30 at /Users/ff/flutter
    • Framework revision 1157e67491 (12 hours ago), 2019-06-09 15:05:55 -0400
    • Engine revision e886d7b082
    • Dart version 2.3.2 (build 2.3.2-dev.0.1 7f146e431e)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/ff/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/ff/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • CocoaPods version 1.5.3

[!] iOS tools - develop for iOS devices
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with
      Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    • ios-deploy 1.9.4

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 35.3.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1343-b01)

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 3.5 Preview.app/Contents
    • Flutter plugin version 36.0.7
    • Dart plugin version 191.7221
    • Java version OpenJDK Runtime Environment (build
      1.8.0_202-release-1483-b02)

[!] IntelliJ IDEA Community Edition (version 2019.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[✓] VS Code (version 1.34.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.1.0

[✓] Connected device (1 available)
    • macOS • macOS • darwin-x64 • Mac OS X 10.14.5 18F132

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: desktopRunning on desktopframeworkflutter/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