Skip to content

Mouse Tracking throwing exceptions for widgets inside a ListView that are listening for hover events  #30744

Closed

Description

@KevinTheGray

I have some widgets inside a ListView that are listening for hover events. When they are hovered they change color. After they rebuild to change color, exceptions are thrown and the hover events no longer fire.

Here's a link to a Flutter Desktop repository that is having the reported issue: https://github.com/KevinTheGray/mouse-hover-exceptions

If you follow the instructions for Flutter Desktop Embedding and run example/macos_fde/ExampleEmbedder.xcodeproj, you can see the exception.

Here's a simple main.dart that reproduces the issue. It builds a row with a ListView and a Column that implement similar behavior. The column behaves as expected, but the ListView will exhibit the behavior described above.

import 'package:flutter/foundation.dart'
    show debugDefaultTargetPlatformOverride;
import 'package:flutter/material.dart';

void main() {
  debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
  runApp(new TestApp());
}

class TestApp extends StatelessWidget {
  final ValueNotifier<int> _hoveredListViewIndex = ValueNotifier(-1);
  final ValueNotifier<int> _hoveredColumnIndex = ValueNotifier(-1);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: AnimatedBuilder(
        animation:
            Listenable.merge([_hoveredListViewIndex, _hoveredColumnIndex]),
        builder: (_, __) {
          return Container(
            constraints: BoxConstraints.expand(),
            color: Colors.black,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Expanded(
                  child: Container(
                    color: Colors.white,
                    child: ListView(
                      children: List.generate(16, (index) {
                        return Listener(
                          onPointerEnter: (_) {
                            _hoveredListViewIndex.value = index;
                          },
                          onPointerExit: (_) {},
                          child: Container(
                            height: 20.0,
                            color: index == _hoveredListViewIndex.value
                                ? Colors.red
                                : Colors.green,
                          ),
                        );
                      }),
                    ),
                  ),
                ),
                Container(
                  width: 20.0,
                ),
                Expanded(
                  child: Container(
                    color: Colors.grey,
                    child: Column(
                      children: List.generate(16, (index) {
                        return Listener(
                          onPointerEnter: (_) {
                            _hoveredColumnIndex.value = index;
                          },
                          onPointerExit: (_) {},
                          child: Container(
                            height: 20.0,
                            color: index == _hoveredColumnIndex.value
                                ? Colors.red
                                : Colors.green,
                          ),
                        );
                      }),
                    ),
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );
  }
}

The exception thrown is this:

══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during a scheduler callback:
flutter: Unable to find annotation [MouseTrackerAnnotation30885124 onEnter onExit] in tracked annotations.
flutter: Check that attachAnnotation has been called for all annotated layers.
flutter: 'package:flutter/src/gestures/mouse_tracking.dart': Failed assertion: line 168 pos 9:
flutter: 'trackedAnnotation != null'
flutter: 
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter:   https://github.com/flutter/flutter/issues/new?template=BUG.md
flutter: 
flutter: When the exception was thrown, this was the stack:
flutter: #2      MouseTracker._findAnnotation (package:flutter/src/gestures/mouse_tracking.dart:168:9)
flutter: #3      MouseTracker.collectMousePositions (package:flutter/src/gestures/mouse_tracking.dart:233:48)
flutter: #4      MouseTracker._scheduleMousePositionCheck.<anonymous closure> (package:flutter/src/gestures/mouse_tracking.dart:131:68)
flutter: #5      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
flutter: #6      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:960:9)
flutter: #7      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:864:5)
flutter: #11     _invoke (dart:ui/hooks.dart:219:10)
flutter: #12     _drawFrame (dart:ui/hooks.dart:178:3)
flutter: (elided 5 frames from class _AssertionError and package dart:async)

Flutter Doctor

[✓] Flutter (Channel dev, v1.4.11, on Mac OS X 10.13.6 17G5019, locale en-US)
    • Flutter version 1.4.11 at /Users/KG/Developer/Flutter/flutter
    • Framework revision d15b3b1c8b (4 days ago), 2019-04-04 15:14:46 -0700
    • Engine revision 219bf59387
    • Dart version 2.2.1 (build 2.2.1-dev.3.0 None)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/KG/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/KG/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-1248-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 33.3.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[✓] IntelliJ IDEA Community Edition (version 2018.2.5)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 29.1.3
    • Dart plugin version 182.4892.25

FDE Checkout

google/flutter-desktop-embedding@dbd7482

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Apr 8, 2019
  2. stuartmorgan-g commented on Apr 8, 2019

    @stuartmorgan-g
    Contributor
  3. KevinTheGray commented on Apr 9, 2019

    @KevinTheGray
    Author

    This is also reproducible on mobile. For example, I attached a mouse to my Android device, an Essential Phone, and the same behavior is seen with the above main.dart file.

  4. self-assigned this
    on Apr 9, 2019
  5. added a commit that references this issue on Apr 11, 2019
    8bea3fb
  6. giladna commented on Jan 6, 2020

    @giladna

    @gspencergoog

    I have similar issue

    Assertion failed: org-dartlang-app:///packages/flutter/src/gestures/mouse_tracking.dart:467:14
    trackedAnnotations.contains(annotation)
    is not true

    Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
    In either case, please report this assertion by filing a bug on GitHub:
    https://github.com/flutter/flutter/issues/new?template=BUG.md

    When the exception was thrown, this was the stack:
    package:dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 196:49 throw
    package:dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 26:3 assertFailed
    package:flutter/src/gestures/mouse_tracking.dart 467:52 _dispatchDeviceCallbacks
    package:flutter/src/gestures/mouse_tracking.dart 297:9
    package:flutter/src/gestures/mouse_tracking.dart 416:26 [_updateDevices]
    ...
    Event: PointerHoverEvent#f30ce(position: Offset(205.7, 453.1), delta: Offset(10.7, -3.0), timeStamp: 0:00:29.136330, pointer: 0, kind: mouse, device: -1, down: false, pressure: 0.0, pressureMin: 0.0)
    position: Offset(205.7, 453.1)

  7. giladna commented on Jan 6, 2020

    @giladna

    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel dev, v1.13.6, on Mac OS X 10.14.5 18F203, locale en-IL)

    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    [✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 3.5)
    [✓] Connected device (2 available)

    • No issues found!

  8. giladna commented on Jan 6, 2020

    @giladna

    @KevinTheGray do you still face this issue?

  9. github-actions commented on Aug 24, 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.

  10. locked as resolved and limited conversation to collaborators on Aug 24, 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 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