transformed_scale_test.dart 1.74 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
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
9
  testWidgets('gets local coordinates', (WidgetTester tester) async {
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    final List<ScaleStartDetails> startDetails = <ScaleStartDetails>[];
    final List<ScaleUpdateDetails> updateDetails = <ScaleUpdateDetails>[];

    final Key redContainer = UniqueKey();
    await tester.pumpWidget(
      Center(
        child: GestureDetector(
          onScaleStart: (ScaleStartDetails details) {
            startDetails.add(details);
          },
          onScaleUpdate: (ScaleUpdateDetails details) {
            updateDetails.add(details);
          },
          child: Container(
            key: redContainer,
            width: 100,
            height: 100,
            color: Colors.red,
          ),
        ),
      ),
    );

    await tester.startGesture(tester.getCenter(find.byKey(redContainer)) - const Offset(20, 20));
    final TestGesture pointer2 = await tester.startGesture(tester.getCenter(find.byKey(redContainer)) + const Offset(30, 30));
    await pointer2.moveTo(tester.getCenter(find.byKey(redContainer)) + const Offset(20, 20));

    expect(updateDetails.single.localFocalPoint, const Offset(50, 50));
    expect(updateDetails.single.focalPoint, const Offset(400, 300));

    expect(startDetails, hasLength(2));
    expect(startDetails.first.localFocalPoint, const Offset(30, 30));
    expect(startDetails.first.focalPoint, const Offset(380, 280));
    expect(startDetails.last.localFocalPoint, const Offset(50, 50));
    expect(startDetails.last.focalPoint, const Offset(400, 300));
  });
}