
issue: https://github.com/flutter/flutter/issues/127855 This is a forward fix to help https://github.com/flutter/engine/pull/54981 land. It makes the following changes: 1) Removes hardcoded `Color.toString()` assumptions in asserts 1) Switches some lerp tests to use numbers that are more friendly to uint8_t and floating point numbers 1) implements custom matchers for color 1) removes word wrapping for some asserts since it makes them fragile to changes in `Color.toString()` invocations ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
101 lines
3.5 KiB
Dart
101 lines
3.5 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// This file is run as part of a reduced test set in CI on Mac and Windows
|
|
// machines.
|
|
@Tags(<String>['reduced-test-set'])
|
|
library;
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
// Here and below, see: https://github.com/dart-lang/sdk/issues/26980
|
|
const FlutterLogoDecoration start = FlutterLogoDecoration(
|
|
textColor: Color(0xFFD4F144),
|
|
style: FlutterLogoStyle.stacked,
|
|
margin: EdgeInsets.all(10.0),
|
|
);
|
|
|
|
const FlutterLogoDecoration end = FlutterLogoDecoration(
|
|
textColor: Color(0xFF81D4FA),
|
|
style: FlutterLogoStyle.stacked,
|
|
margin: EdgeInsets.all(10.0),
|
|
);
|
|
|
|
test('FlutterLogoDecoration lerp from null to null is null', () {
|
|
final FlutterLogoDecoration? logo = FlutterLogoDecoration.lerp(null, null, 0.5);
|
|
expect(logo, isNull);
|
|
});
|
|
|
|
test('FlutterLogoDecoration.lerp identical a,b', () {
|
|
expect(FlutterLogoDecoration.lerp(null, null, 0), null);
|
|
const FlutterLogoDecoration logo = FlutterLogoDecoration();
|
|
expect(identical(FlutterLogoDecoration.lerp(logo, logo, 0.5), logo), true);
|
|
});
|
|
|
|
test('FlutterLogoDecoration lerp from non-null to null lerps margin', () {
|
|
final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, null, 0.4)!;
|
|
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.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.textColor, Color.lerp(start.textColor, end.textColor, 0.5));
|
|
expect(logo.margin, EdgeInsets.lerp(start.margin, end.margin, 0.5));
|
|
});
|
|
|
|
test('FlutterLogoDecoration.lerpFrom and FlutterLogoDecoration.lerpTo', () {
|
|
expect(Decoration.lerp(start, const BoxDecoration(), 0.0), start);
|
|
expect(Decoration.lerp(start, const BoxDecoration(), 1.0), const BoxDecoration());
|
|
expect(Decoration.lerp(const BoxDecoration(), end, 0.0), const BoxDecoration());
|
|
expect(Decoration.lerp(const BoxDecoration(), end, 1.0), end);
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
test('FlutterLogoDecoration toString', () {
|
|
expect(
|
|
start.toString(),
|
|
equals(
|
|
'FlutterLogoDecoration(textColor: ${const Color(0xffd4f144)}, style: stacked)',
|
|
),
|
|
);
|
|
expect(
|
|
FlutterLogoDecoration.lerp(null, end, 0.5).toString(),
|
|
equals(
|
|
'FlutterLogoDecoration(textColor: ${const Color(0xff81d4fa)}, style: stacked, transition -1.0:0.5)',
|
|
),
|
|
);
|
|
});
|
|
|
|
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'),
|
|
);
|
|
});
|
|
}
|