coordinates_test.dart 1.39 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.

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

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

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

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

43
    final RenderBox boxB = tester.renderObject(find.byKey(keyB));
44 45
    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)));
46 47
  });
}