animated_padding_test.dart 3.56 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Ian Hickson's avatar
Ian Hickson 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

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

void main() {
  testWidgets('AnimatedPadding.debugFillProperties', (WidgetTester tester) async {
13
    final AnimatedPadding padding = AnimatedPadding(
Ian Hickson's avatar
Ian Hickson committed
14 15 16 17 18 19 20 21 22
      padding: const EdgeInsets.all(7.0),
      curve: Curves.ease,
      duration: const Duration(milliseconds: 200),
    );

    expect(padding, hasOneLineDescription);
  });

  testWidgets('AnimatedPadding padding visual-to-directional animation', (WidgetTester tester) async {
23
    final Key target = UniqueKey();
Ian Hickson's avatar
Ian Hickson committed
24 25

    await tester.pumpWidget(
26
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
27
        textDirection: TextDirection.rtl,
28
        child: AnimatedPadding(
Ian Hickson's avatar
Ian Hickson committed
29 30
          duration: const Duration(milliseconds: 200),
          padding: const EdgeInsets.only(right: 50.0),
31
          child: SizedBox.expand(key: target),
Ian Hickson's avatar
Ian Hickson committed
32 33 34 35 36 37 38 39
        ),
      ),
    );

    expect(tester.getSize(find.byKey(target)), const Size(750.0, 600.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(750.0, 0.0));

    await tester.pumpWidget(
40
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
41
        textDirection: TextDirection.rtl,
42
        child: AnimatedPadding(
Ian Hickson's avatar
Ian Hickson committed
43 44
          duration: const Duration(milliseconds: 200),
          padding: const EdgeInsetsDirectional.only(start: 100.0),
45
          child: SizedBox.expand(key: target),
Ian Hickson's avatar
Ian Hickson committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        ),
      ),
    );

    expect(tester.getSize(find.byKey(target)), const Size(750.0, 600.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(750.0, 0.0));

    await tester.pump(const Duration(milliseconds: 100));

    expect(tester.getSize(find.byKey(target)), const Size(725.0, 600.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(725.0, 0.0));

    await tester.pump(const Duration(milliseconds: 500));

    expect(tester.getSize(find.byKey(target)), const Size(700.0, 600.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(700.0, 0.0));
  });
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

  testWidgets('AnimatedPadding animated padding clamped to positive values', (WidgetTester tester) async {
    final Key target = UniqueKey();

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.rtl,
        child: AnimatedPadding(
          curve: Curves.easeInOutBack, // will cause negative padding during overshoot
          duration: const Duration(milliseconds: 200),
          padding: const EdgeInsets.only(right: 50.0),
          child: SizedBox.expand(key: target),
        ),
      ),
    );

    expect(tester.getSize(find.byKey(target)), const Size(750.0, 600.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(750.0, 0.0));

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.rtl,
        child: AnimatedPadding(
          curve: Curves.easeInOutBack,
          duration: const Duration(milliseconds: 200),
          padding: const EdgeInsets.only(right: 0.0),
          child: SizedBox.expand(key: target),
        ),
      ),
    );

    expect(tester.getSize(find.byKey(target)), const Size(750.0, 600.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(750.0, 0.0));

    await tester.pump(const Duration(milliseconds: 128));
    // Curve would have made the padding negative a this point if it is not clamped.
    expect(tester.getSize(find.byKey(target)), const Size(800.0, 600.0));
    expect(tester.getTopRight(find.byKey(target)), const Offset(800.0, 0.0));
  });

Ian Hickson's avatar
Ian Hickson committed
103
}