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

import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
10
  testWidgets('provides a value to the layer tree', (WidgetTester tester) async {
11 12 13
    await tester.pumpWidget(
      const AnnotatedRegion<int>(
        value: 1,
14
        child: SizedBox(width: 100.0, height: 100.0),
15 16 17
      ),
    );
    final List<Layer> layers = tester.layers;
18
    final AnnotatedRegionLayer<int> layer = layers.whereType<AnnotatedRegionLayer<int>>().first;
19 20
    expect(layer.value, 1);
  });
21

22
  testWidgets('provides a value to the layer tree in a particular region', (WidgetTester tester) async {
23 24 25 26 27
    await tester.pumpWidget(
      Transform.translate(
        offset: const Offset(25.0, 25.0),
        child: const AnnotatedRegion<int>(
          value: 1,
28
          child: SizedBox(width: 100.0, height: 100.0),
29 30 31
        ),
      ),
    );
32
    int? result = RendererBinding.instance.renderView.debugLayer!.find<int>(Offset(
33 34
      10.0 * tester.view.devicePixelRatio,
      10.0 * tester.view.devicePixelRatio,
35
    ));
36
    expect(result, null);
37
    result = RendererBinding.instance.renderView.debugLayer!.find<int>(Offset(
38 39
      50.0 * tester.view.devicePixelRatio,
      50.0 * tester.view.devicePixelRatio,
40
    ));
41 42
    expect(result, 1);
  });
43
}