hit_test_test.dart 1.74 KB
Newer Older
1 2 3 4 5
// Copyright 2019 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/gestures.dart';
6
import 'package:vector_math/vector_math_64.dart';
7 8 9 10 11 12 13 14

import '../flutter_test_alternative.dart';

void main() {
  test('wrpped HitTestResult gets HitTestEntry added to wrapping HitTestResult', () async {
    final HitTestEntry entry1 = HitTestEntry(_DummyHitTestTarget());
    final HitTestEntry entry2 = HitTestEntry(_DummyHitTestTarget());
    final HitTestEntry entry3 = HitTestEntry(_DummyHitTestTarget());
15
    final Matrix4 transform = Matrix4.translationValues(40.0, 150.0, 0.0);
16

17 18
    final HitTestResult wrapped = MyHitTestResult()
      ..publicPushTransform(transform);
19 20
    wrapped.add(entry1);
    expect(wrapped.path, equals(<HitTestEntry>[entry1]));
21
    expect(entry1.transform, transform);
22 23 24 25 26 27 28 29

    final HitTestResult wrapping = HitTestResult.wrap(wrapped);
    expect(wrapping.path, equals(<HitTestEntry>[entry1]));
    expect(wrapping.path, same(wrapped.path));

    wrapping.add(entry2);
    expect(wrapping.path, equals(<HitTestEntry>[entry1, entry2]));
    expect(wrapped.path, equals(<HitTestEntry>[entry1, entry2]));
30
    expect(entry2.transform, transform);
31 32 33 34

    wrapped.add(entry3);
    expect(wrapping.path, equals(<HitTestEntry>[entry1, entry2, entry3]));
    expect(wrapped.path, equals(<HitTestEntry>[entry1, entry2, entry3]));
35
    expect(entry3.transform, transform);
36 37 38 39 40 41 42 43 44
  });
}

class _DummyHitTestTarget implements HitTestTarget {
  @override
  void handleEvent(PointerEvent event, HitTestEntry entry) {
    // Nothing to do.
  }
}
45 46 47 48

class MyHitTestResult extends HitTestResult {
  void publicPushTransform(Matrix4 transform) => pushTransform(transform);
}