Skip to content

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

@KevinTheGray

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

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