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

5 6
// @dart = 2.8

Adam Barth's avatar
Adam Barth committed
7
import 'package:flutter_test/flutter_test.dart';
8 9
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
10 11

void main() {
12
  testWidgets('Comparing coordinates', (WidgetTester tester) async {
13 14
    final Key keyA = GlobalKey();
    final Key keyB = GlobalKey();
15

16
    await tester.pumpWidget(
17
      Stack(
18
        textDirection: TextDirection.ltr,
19
        children: <Widget>[
20
          Positioned(
21 22
            top: 100.0,
            left: 100.0,
23
            child: SizedBox(
24 25
              key: keyA,
              width: 10.0,
26 27
              height: 10.0,
            ),
28
          ),
29
          Positioned(
30 31
            left: 100.0,
            top: 200.0,
32
            child: SizedBox(
33 34
              key: keyB,
              width: 20.0,
35 36
              height: 10.0,
            ),
37
          ),
38 39
        ],
      ),
40
    );
41

42
    final RenderBox boxA = tester.renderObject(find.byKey(keyA));
43
    expect(boxA.localToGlobal(const Offset(0.0, 0.0)), equals(const Offset(100.0, 100.0)));
44

45
    final RenderBox boxB = tester.renderObject(find.byKey(keyB));
46 47
    expect(boxB.localToGlobal(const Offset(0.0, 0.0)), equals(const Offset(100.0, 200.0)));
    expect(boxB.globalToLocal(const Offset(110.0, 205.0)), equals(const Offset(10.0, 5.0)));
48 49
  });
}