Add a debug feature to the gestures library to dump hit test results (#11346)
This commit is contained in:
@@ -11,6 +11,7 @@ export 'src/gestures/arena.dart';
|
||||
export 'src/gestures/binding.dart';
|
||||
export 'src/gestures/constants.dart';
|
||||
export 'src/gestures/converter.dart';
|
||||
export 'src/gestures/debug.dart';
|
||||
export 'src/gestures/drag.dart';
|
||||
export 'src/gestures/drag_details.dart';
|
||||
export 'src/gestures/events.dart';
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'arena.dart';
|
||||
import 'converter.dart';
|
||||
import 'debug.dart';
|
||||
import 'events.dart';
|
||||
import 'hit_test.dart';
|
||||
import 'pointer_router.dart';
|
||||
@@ -75,6 +76,11 @@ abstract class GestureBinding extends BindingBase with HitTestable, HitTestDispa
|
||||
result = new HitTestResult();
|
||||
hitTest(result, event.position);
|
||||
_hitTests[event.pointer] = result;
|
||||
assert(() {
|
||||
if (debugPrintHitTestResults)
|
||||
debugPrint('$event: $result');
|
||||
return true;
|
||||
});
|
||||
} else if (event is PointerUpEvent || event is PointerCancelEvent) {
|
||||
result = _hitTests.remove(event.pointer);
|
||||
} else if (event.down) {
|
||||
|
||||
32
packages/flutter/lib/src/gestures/debug.dart
Normal file
32
packages/flutter/lib/src/gestures/debug.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
// Any changes to this file should be reflected in the debugAssertAllGesturesVarsUnset()
|
||||
// function below.
|
||||
|
||||
/// Whether to print the results of each hit test to the console.
|
||||
///
|
||||
/// When this is set, in debug mode, any time a hit test is triggered by the
|
||||
/// [GestureBinding] the results are dumped to the console.
|
||||
///
|
||||
/// This has no effect in release builds.
|
||||
bool debugPrintHitTestResults = false;
|
||||
|
||||
/// Returns true if none of the gestures library debug variables have been changed.
|
||||
///
|
||||
/// This function is used by the test framework to ensure that debug variables
|
||||
/// haven't been inadvertently changed.
|
||||
///
|
||||
/// See [https://docs.flutter.io/flutter/gestures/gestures-library.html] for
|
||||
/// a complete list.
|
||||
bool debugAssertAllGesturesVarsUnset(String reason) {
|
||||
assert(() {
|
||||
if (debugPrintHitTestResults)
|
||||
throw new FlutterError(reason);
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -474,6 +474,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
'The value of a foundation debug variable was changed by the test.',
|
||||
debugPrintOverride: debugPrintOverride,
|
||||
));
|
||||
assert(debugAssertAllGesturesVarsUnset(
|
||||
'The value of a gestures debug variable was changed by the test.',
|
||||
));
|
||||
assert(debugAssertAllRenderVarsUnset(
|
||||
'The value of a rendering debug variable was changed by the test.',
|
||||
debugCheckIntrinsicSizesOverride: checkIntrinsicSizes,
|
||||
|
||||
Reference in New Issue
Block a user