gesture_disambiguation_test.dart 1.66 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';
6
import 'package:flutter_test/flutter_test.dart';
7
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
8 9

void main() {
10
  testWidgetsWithLeakTracking('onTap detection with canceled pointer and a drag listener', (WidgetTester tester) async {
11 12 13
    int detector1TapCount = 0;
    int detector2TapCount = 0;

14 15
    final Widget widget = GestureDetector(
      child: Column(
16
        children: <Widget>[
17
          GestureDetector(
18 19 20 21
            onTap: () { detector1TapCount += 1; },
            behavior: HitTestBehavior.opaque,
            child: const SizedBox(width: 200.0, height: 200.0),
          ),
22
          GestureDetector(
23 24
            onTap: () { detector2TapCount += 1; },
            behavior: HitTestBehavior.opaque,
25 26
            child: const SizedBox(width: 200.0, height: 200.0),
          ),
27
        ],
28
      ),
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    );

    await tester.pumpWidget(widget);

    // The following pointer event sequence was causing the issue described
    // in https://github.com/flutter/flutter/issues/12470 by triggering 2 tap
    // events on the second detector.
    final TestGesture gesture1 = await tester.startGesture(const Offset(400.0, 10.0));
    final TestGesture gesture2 = await tester.startGesture(const Offset(400.0, 210.0));
    await gesture1.up();
    await gesture2.cancel();
    final TestGesture gesture3 = await tester.startGesture(const Offset(400.0, 250.0));
    await gesture3.up();

    expect(detector1TapCount, 1);
    expect(detector2TapCount, 1);
  });
}