gesture_disambiguation_test.dart 1.57 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 8 9 10 11 12

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

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

    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);
  });
}