animated_cross_fade_test.dart 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

void main() {
  testWidgets('AnimatedCrossFade test', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Center(
        child: new AnimatedCrossFade(
14
          firstChild: const SizedBox(
15 16 17
            width: 100.0,
            height: 100.0
          ),
18
          secondChild: const SizedBox(
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
            width: 200.0,
            height: 200.0
          ),
          duration: const Duration(milliseconds: 200),
          crossFadeState: CrossFadeState.showFirst
        )
      )
    );

    expect(find.byType(FadeTransition), findsNWidgets(2));
    RenderBox box = tester.renderObject(find.byType(AnimatedCrossFade));
    expect(box.size.width, equals(100.0));
    expect(box.size.height, equals(100.0));

    await tester.pumpWidget(
      new Center(
        child: new AnimatedCrossFade(
36
          firstChild: const SizedBox(
37 38 39
            width: 100.0,
            height: 100.0
          ),
40
          secondChild: const SizedBox(
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
            width: 200.0,
            height: 200.0
          ),
          duration: const Duration(milliseconds: 200),
          crossFadeState: CrossFadeState.showSecond
        )
      )
    );

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

    expect(find.byType(FadeTransition), findsNWidgets(2));
    box = tester.renderObject(find.byType(AnimatedCrossFade));
    expect(box.size.width, equals(150.0));
    expect(box.size.height, equals(150.0));
  });
57 58 59 60 61

  testWidgets('AnimatedCrossFade test showSecond', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Center(
        child: new AnimatedCrossFade(
62
          firstChild: const SizedBox(
63 64 65
            width: 100.0,
            height: 100.0
          ),
66
          secondChild: const SizedBox(
67 68 69 70 71 72 73 74 75 76 77 78 79 80
            width: 200.0,
            height: 200.0
          ),
          duration: const Duration(milliseconds: 200),
          crossFadeState: CrossFadeState.showSecond
        )
      )
    );

    expect(find.byType(FadeTransition), findsNWidgets(2));
    RenderBox box = tester.renderObject(find.byType(AnimatedCrossFade));
    expect(box.size.width, equals(200.0));
    expect(box.size.height, equals(200.0));
  });
81
}