coordinates_test.dart 1.33 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
import 'package:flutter/widgets.dart';
6
import 'package:flutter_test/flutter_test.dart';
7 8

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

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

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

42
    final RenderBox boxB = tester.renderObject(find.byKey(keyB));
43
    expect(boxB.localToGlobal(Offset.zero), equals(const Offset(100.0, 200.0)));
44
    expect(boxB.globalToLocal(const Offset(110.0, 205.0)), equals(const Offset(10.0, 5.0)));
45 46
  });
}