flutter_logo_test.dart 3.28 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 9
// 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/painting.dart';

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

18 19 20 21
  const FlutterLogoDecoration end = FlutterLogoDecoration(
    lightColor: Color(0xFFFFFFFF),
    darkColor: Color(0xFF000000),
    textColor: Color(0xFF81D4FA),
22
    style: FlutterLogoStyle.stacked,
23
    margin: EdgeInsets.all(10.0),
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  );

  test('FlutterLogoDecoration lerp from null to null is null', () {
    final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(null, null, 0.5);
    expect(logo, isNull);
  });

  test('FlutterLogoDecoration lerp from non-null to null lerps margin', () {
    final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, null, 0.4);
    expect(logo.lightColor, start.lightColor);
    expect(logo.darkColor, start.darkColor);
    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', () {
    final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(null, end, 0.6);
    expect(logo.lightColor, end.lightColor);
    expect(logo.darkColor, end.darkColor);
    expect(logo.textColor, end.textColor);
    expect(logo.style, end.style);
    expect(logo.margin, end.margin * 0.6);
  });

  test('FlutterLogoDecoration lerps colors and margins', () {
    final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, end, 0.5);
    expect(logo.lightColor, Color.lerp(start.lightColor, end.lightColor, 0.5));
    expect(logo.darkColor, Color.lerp(start.darkColor, end.darkColor, 0.5));
    expect(logo.textColor, Color.lerp(start.textColor, end.textColor, 0.5));
    expect(logo.margin, EdgeInsets.lerp(start.margin, end.margin, 0.5));
  });

57
  test('FlutterLogoDecorationl.lerpFrom and FlutterLogoDecorationl.lerpTo', () {
58
    expect(Decoration.lerp(start, const BoxDecoration(), 0.0), start);
59
    expect(Decoration.lerp(start, const BoxDecoration(), 1.0), const BoxDecoration());
60 61
    expect(Decoration.lerp(const BoxDecoration(), end, 0.0), const BoxDecoration());
    expect(Decoration.lerp(const BoxDecoration(), end, 1.0), end);
62 63
  });

64 65 66 67 68 69 70
  test('FlutterLogoDecoration lerp changes styles at 0.5', () {
    FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, end, 0.4);
    expect(logo.style, start.style);

    logo = FlutterLogoDecoration.lerp(start, end, 0.5);
    expect(logo.style, end.style);
  });
71 72 73 74 75

  test('FlutterLogoDecoration toString', () {
    expect(
      start.toString(),
      equals(
76
        'FlutterLogoDecoration(Color(0xff000000)/Color(0xffffffff) on Color(0xffd4f144), style: stacked)'
77 78 79 80 81
      ),
    );
    expect(
      FlutterLogoDecoration.lerp(null, end, 0.5).toString(),
      equals(
82
        'FlutterLogoDecoration(Color(0xffffffff)/Color(0xff000000) on Color(0xff81d4fa), style: stacked, transition -1.0:0.5)',
83 84 85
      ),
    );
  });
86
}