flutter_logo_test.dart 3.09 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
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 7 8 9
import 'package:flutter_test/flutter_test.dart';

void main() {
  // Here and below, see: https://github.com/dart-lang/sdk/issues/26980
10 11
  const FlutterLogoDecoration start = FlutterLogoDecoration(
    textColor: Color(0xFFD4F144),
12
    style: FlutterLogoStyle.stacked,
13
    margin: EdgeInsets.all(10.0),
14 15
  );

16 17
  const FlutterLogoDecoration end = FlutterLogoDecoration(
    textColor: Color(0xFF81D4FA),
18
    style: FlutterLogoStyle.stacked,
19
    margin: EdgeInsets.all(10.0),
20 21 22
  );

  test('FlutterLogoDecoration lerp from null to null is null', () {
23
    final FlutterLogoDecoration? logo = FlutterLogoDecoration.lerp(null, null, 0.5);
24 25 26 27
    expect(logo, isNull);
  });

  test('FlutterLogoDecoration lerp from non-null to null lerps margin', () {
28
    final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, null, 0.4)!;
29 30 31 32 33 34
    expect(logo.textColor, start.textColor);
    expect(logo.style, start.style);
    expect(logo.margin, start.margin * 0.4);
  });

  test('FlutterLogoDecoration lerp from null to non-null lerps margin', () {
35
    final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(null, end, 0.6)!;
36 37 38 39 40 41
    expect(logo.textColor, end.textColor);
    expect(logo.style, end.style);
    expect(logo.margin, end.margin * 0.6);
  });

  test('FlutterLogoDecoration lerps colors and margins', () {
42
    final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, end, 0.5)!;
43 44 45 46
    expect(logo.textColor, Color.lerp(start.textColor, end.textColor, 0.5));
    expect(logo.margin, EdgeInsets.lerp(start.margin, end.margin, 0.5));
  });

47
  test('FlutterLogoDecoration.lerpFrom and FlutterLogoDecoration.lerpTo', () {
48
    expect(Decoration.lerp(start, const BoxDecoration(), 0.0), start);
49
    expect(Decoration.lerp(start, const BoxDecoration(), 1.0), const BoxDecoration());
50 51
    expect(Decoration.lerp(const BoxDecoration(), end, 0.0), const BoxDecoration());
    expect(Decoration.lerp(const BoxDecoration(), end, 1.0), end);
52 53
  });

54
  test('FlutterLogoDecoration lerp changes styles at 0.5', () {
55
    FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, end, 0.4)!;
56 57
    expect(logo.style, start.style);

58
    logo = FlutterLogoDecoration.lerp(start, end, 0.5)!;
59 60
    expect(logo.style, end.style);
  });
61 62 63 64 65

  test('FlutterLogoDecoration toString', () {
    expect(
      start.toString(),
      equals(
66
        'FlutterLogoDecoration(textColor: Color(0xffd4f144), style: stacked)'
67 68 69 70 71
      ),
    );
    expect(
      FlutterLogoDecoration.lerp(null, end, 0.5).toString(),
      equals(
72
        'FlutterLogoDecoration(textColor: Color(0xff81d4fa), style: stacked, transition -1.0:0.5)',
73 74 75
      ),
    );
  });
76 77 78 79 80 81 82 83 84 85 86 87 88

  testWidgets('Flutter Logo golden test', (WidgetTester tester) async {
    final Key logo = UniqueKey();
    await tester.pumpWidget(Container(
      key: logo,
      decoration: const FlutterLogoDecoration(),
    ));

    await expectLater(
      find.byKey(logo),
      matchesGoldenFile('flutter_logo.png'),
    );
  });
89
}