Unverified Commit 687121d6 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate some tests to null-safety (#67085)

parent 1bea512a
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -75,7 +73,7 @@ Future<void> restoreAndVerify(WidgetTester tester) async {
}
class TestWidget extends StatefulWidget {
const TestWidget({Key key, this.useExternal = false}) : super(key: key);
const TestWidget({Key? key, this.useExternal = false}) : super(key: key);
final bool useExternal;
......@@ -90,7 +88,7 @@ class TestWidgetState extends State<TestWidget> with RestorationMixin {
String get restorationId => 'widget';
@override
void restoreState(RestorationBucket oldBucket, bool initialRestore) {
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(controller, 'controller');
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
......@@ -23,7 +21,7 @@ class MockClipboard {
case 'Clipboard.getData':
return _clipboardData;
case 'Clipboard.setData':
_clipboardData = methodCall.arguments;
_clipboardData = methodCall.arguments! as Object;
break;
}
}
......@@ -80,14 +78,14 @@ void main() {
),
);
// Disabled buttons have no opacity change when pressed.
return button.pressedOpacity < 1.0;
return button.pressedOpacity! < 1.0;
}
group('canSelectAll', () {
Widget createEditableText({
Key key,
String text,
TextSelection selection,
Key? key,
String? text,
TextSelection? selection,
}) {
final TextEditingController controller = TextEditingController(text: text)
..selection = selection ?? const TextSelection.collapsed(offset: -1);
......@@ -106,7 +104,7 @@ void main() {
testWidgets('should return false when there is no text', (WidgetTester tester) async {
final GlobalKey<EditableTextState> key = GlobalKey();
await tester.pumpWidget(createEditableText(key: key));
expect(cupertinoTextSelectionControls.canSelectAll(key.currentState), false);
expect(cupertinoTextSelectionControls.canSelectAll(key.currentState!), false);
});
testWidgets('should return true when there is text and collapsed selection', (WidgetTester tester) async {
......@@ -115,7 +113,7 @@ void main() {
key: key,
text: '123',
));
expect(cupertinoTextSelectionControls.canSelectAll(key.currentState), true);
expect(cupertinoTextSelectionControls.canSelectAll(key.currentState!), true);
});
testWidgets('should return false when there is text and partial uncollapsed selection', (WidgetTester tester) async {
......@@ -125,7 +123,7 @@ void main() {
text: '123',
selection: const TextSelection(baseOffset: 1, extentOffset: 2),
));
expect(cupertinoTextSelectionControls.canSelectAll(key.currentState), false);
expect(cupertinoTextSelectionControls.canSelectAll(key.currentState!), false);
});
testWidgets('should return false when there is text and full selection', (WidgetTester tester) async {
......@@ -135,7 +133,7 @@ void main() {
text: '123',
selection: const TextSelection(baseOffset: 0, extentOffset: 3),
));
expect(cupertinoTextSelectionControls.canSelectAll(key.currentState), false);
expect(cupertinoTextSelectionControls.canSelectAll(key.currentState!), false);
});
});
......
......@@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
int buildCount;
CupertinoThemeData actualTheme;
IconThemeData actualIconTheme;
int buildCount = 0;
CupertinoThemeData? actualTheme;
IconThemeData? actualIconTheme;
final Widget singletonThemeSubtree = Builder(
builder: (BuildContext context) {
......@@ -29,7 +27,7 @@ Future<CupertinoThemeData> testTheme(WidgetTester tester, CupertinoThemeData the
child: singletonThemeSubtree,
),
);
return actualTheme;
return actualTheme!;
}
Future<IconThemeData> testIconTheme(WidgetTester tester, CupertinoThemeData theme) async {
......@@ -39,13 +37,14 @@ Future<IconThemeData> testIconTheme(WidgetTester tester, CupertinoThemeData them
child: singletonThemeSubtree,
),
);
return actualIconTheme;
return actualIconTheme!;
}
void main() {
setUp(() {
buildCount = 0;
actualTheme = null;
actualIconTheme = null;
});
testWidgets('Default theme has defaults', (WidgetTester tester) async {
......@@ -150,7 +149,7 @@ void main() {
final Color darkColor = (await testIconTheme(
tester,
themeData.copyWith(brightness: Brightness.dark),
)).color;
)).color!;
expect(darkColor, isSameColorAs(primaryColor.darkColor));
});
......@@ -207,8 +206,8 @@ void main() {
);
});
Brightness currentBrightness;
void colorMatches(Color componentColor, CupertinoDynamicColor expectedDynamicColor) {
late Brightness currentBrightness;
void colorMatches(Color? componentColor, CupertinoDynamicColor expectedDynamicColor) {
switch (currentBrightness) {
case Brightness.light:
expect(componentColor, isSameColorAs(expectedDynamicColor.color));
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
// Defines a 'package:test' shim.
// TODO(ianh): Remove this file once https://github.com/dart-lang/matcher/issues/98 is fixed
......
......@@ -2,6 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
export 'package:flutter_goldens/flutter_goldens.dart' show main;
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
// Logically this file should be part of `gesture_binding_test.dart` but is here
// due to conflict of `flutter_test` and `package:test`.
// See https://github.com/dart-lang/matcher/issues/98
......@@ -75,10 +73,10 @@ void main() {
),
);
GestureBinding.instance.resamplingEnabled = true;
GestureBinding.instance!.resamplingEnabled = true;
const Duration kSamplingOffset = Duration(microseconds: -5500);
GestureBinding.instance.samplingOffset = kSamplingOffset;
ui.window.onPointerDataPacket(packet);
GestureBinding.instance!.samplingOffset = kSamplingOffset;
ui.window.onPointerDataPacket!(packet);
expect(events.length, 0);
await tester.pump(const Duration(milliseconds: 7));
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui';
import 'package:flutter/gestures.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
/// A 50x50 blue square png.
const List<int> kBlueSquarePng = <int>[
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49,
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math;
import 'package:flutter/painting.dart';
......@@ -110,14 +108,14 @@ void main() {
final AlignmentGeometry mixed3 = const Alignment(25.0, 42.5).add(const AlignmentDirectional(55.0, 80.0));
for (final TextDirection direction in TextDirection.values) {
expect(AlignmentGeometry.lerp(mixed1, mixed2, 0.0).resolve(direction), mixed1.resolve(direction));
expect(AlignmentGeometry.lerp(mixed1, mixed2, 1.0).resolve(direction), mixed2.resolve(direction));
expect(AlignmentGeometry.lerp(mixed1, mixed2, 0.25).resolve(direction), mixed3.resolve(direction));
expect(AlignmentGeometry.lerp(mixed1, mixed2, 0.0)!.resolve(direction), mixed1.resolve(direction));
expect(AlignmentGeometry.lerp(mixed1, mixed2, 1.0)!.resolve(direction), mixed2.resolve(direction));
expect(AlignmentGeometry.lerp(mixed1, mixed2, 0.25)!.resolve(direction), mixed3.resolve(direction));
}
});
test('lerp commutes with resolve', () {
final List<AlignmentGeometry> offsets = <AlignmentGeometry>[
final List<AlignmentGeometry?> offsets = <AlignmentGeometry?>[
Alignment.topLeft,
Alignment.topCenter,
Alignment.topRight,
......@@ -154,19 +152,19 @@ void main() {
for (final TextDirection direction in TextDirection.values) {
final Alignment defaultValue = AlignmentDirectional.center.resolve(direction);
for (final AlignmentGeometry a in offsets) {
for (final AlignmentGeometry? a in offsets) {
final Alignment resolvedA = a?.resolve(direction) ?? defaultValue;
for (final AlignmentGeometry b in offsets) {
for (final AlignmentGeometry? b in offsets) {
final Alignment resolvedB = b?.resolve(direction) ?? defaultValue;
approxExpect(Alignment.lerp(resolvedA, resolvedB, 0.0), resolvedA);
approxExpect(Alignment.lerp(resolvedA, resolvedB, 1.0), resolvedB);
approxExpect(Alignment.lerp(resolvedA, resolvedB, 0.0)!, resolvedA);
approxExpect(Alignment.lerp(resolvedA, resolvedB, 1.0)!, resolvedB);
approxExpect((AlignmentGeometry.lerp(a, b, 0.0) ?? defaultValue).resolve(direction), resolvedA);
approxExpect((AlignmentGeometry.lerp(a, b, 1.0) ?? defaultValue).resolve(direction), resolvedB);
for (final double t in times) {
assert(t > 0.0);
assert(t < 1.0);
final Alignment value = (AlignmentGeometry.lerp(a, b, t) ?? defaultValue).resolve(direction);
approxExpect(value, Alignment.lerp(resolvedA, resolvedB, t));
approxExpect(value, Alignment.lerp(resolvedA, resolvedB, t)!);
final double minDX = math.min(resolvedA.x, resolvedB.x);
final double maxDX = math.max(resolvedA.x, resolvedB.x);
final double minDY = math.min(resolvedA.y, resolvedB.y);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
......@@ -18,7 +16,7 @@ Future<void> main() async {
final ui.Image image = await createTestImage();
testWidgets('didHaveMemoryPressure clears imageCache', (WidgetTester tester) async {
imageCache.putIfAbsent(1, () => OneFrameImageStreamCompleter(
imageCache!.putIfAbsent(1, () => OneFrameImageStreamCompleter(
Future<ImageInfo>.value(ImageInfo(
image: image,
scale: 1.0,
......@@ -26,11 +24,11 @@ Future<void> main() async {
)));
await tester.idle();
expect(imageCache.currentSize, 1);
expect(imageCache!.currentSize, 1);
final ByteData message = const JSONMessageCodec().encodeMessage(
<String, dynamic>{'type': 'memoryPressure'});
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/system', message, (_) { });
expect(imageCache.currentSize, 0);
<String, dynamic>{'type': 'memoryPressure'})!;
await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/system', message, (_) { });
expect(imageCache!.currentSize, 0);
});
test('evict clears live references', () async {
......@@ -71,19 +69,19 @@ class TestBindingBase implements BindingBase {
}
@override
void registerBoolServiceExtension({String name, AsyncValueGetter<bool> getter, AsyncValueSetter<bool> setter}) {}
void registerBoolServiceExtension({required String name, required AsyncValueGetter<bool> getter, required AsyncValueSetter<bool> setter}) {}
@override
void registerNumericServiceExtension({String name, AsyncValueGetter<double> getter, AsyncValueSetter<double> setter}) {}
void registerNumericServiceExtension({required String name, required AsyncValueGetter<double> getter, required AsyncValueSetter<double> setter}) {}
@override
void registerServiceExtension({String name, ServiceExtensionCallback callback}) {}
void registerServiceExtension({required String name, required ServiceExtensionCallback callback}) {}
@override
void registerSignalServiceExtension({String name, AsyncCallback callback}) {}
void registerSignalServiceExtension({required String name, required AsyncCallback callback}) {}
@override
void registerStringServiceExtension({String name, AsyncValueGetter<String> getter, AsyncValueSetter<String> setter}) {}
void registerStringServiceExtension({required String name, required AsyncValueGetter<String> getter, required AsyncValueSetter<String> setter}) {}
@override
void unlocked() {}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -365,10 +363,10 @@ void main() {
bottomLeft: Radius.elliptical(95.0, 105.0), // 50,60 -> 140,150
bottomRight: Radius.elliptical(60.0, 65.0), // 0,0 -> 120,130
);
expect(BorderRadiusGeometry.lerp(a, b, 0.5).resolve(TextDirection.ltr), ltr);
expect(BorderRadiusGeometry.lerp(a, b, 0.5).resolve(TextDirection.rtl), rtl);
expect(BorderRadiusGeometry.lerp(a, b, 0.0).resolve(TextDirection.ltr), a);
expect(BorderRadiusGeometry.lerp(a, b, 1.0).resolve(TextDirection.rtl), b.resolve(TextDirection.rtl));
expect(BorderRadiusGeometry.lerp(a, b, 0.5)!.resolve(TextDirection.ltr), ltr);
expect(BorderRadiusGeometry.lerp(a, b, 0.5)!.resolve(TextDirection.rtl), rtl);
expect(BorderRadiusGeometry.lerp(a, b, 0.0)!.resolve(TextDirection.ltr), a);
expect(BorderRadiusGeometry.lerp(a, b, 1.0)!.resolve(TextDirection.rtl), b.resolve(TextDirection.rtl));
});
test('BorderRadiusGeometry subtract', () {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart' show DiagnosticLevel, FlutterError;
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -77,7 +75,7 @@ void main() {
expect(BoxBorder.lerp(null, directionalWithTop10, 0.25), const BorderDirectional(top: BorderSide(width: 2.5)));
expect(BoxBorder.lerp(directionalWithTop10, visualWithTop100, 0.25), const Border(top: BorderSide(width: 32.5)));
expect(BoxBorder.lerp(visualWithSides10, directionalWithMagentaTop5, 0.25), visualWithSides10At75 + directionalWithMagentaTop5At25);
expect(BoxBorder.lerp(visualWithYellowTop5, directionalWithMagentaTop5, 0.25), Border(top: BorderSide(width: 5.0, color: Color.lerp(const Color(0xFFFFFF00), const Color(0xFFFF00FF), 0.25))));
expect(BoxBorder.lerp(visualWithYellowTop5, directionalWithMagentaTop5, 0.25), Border(top: BorderSide(width: 5.0, color: Color.lerp(const Color(0xFFFFFF00), const Color(0xFFFF00FF), 0.25)!)));
expect(BoxBorder.lerp(visualWithSides10, directionalWithSides10, 0.25), visualWithSides10At50);
expect(BoxBorder.lerp(visualWithYellowTop5, directionalWithSides10, 0.25), visualWithYellowTop5At75 + directionalWithSides10At25);
expect(() => BoxBorder.lerp(SillyBorder(), const Border(), 0.25), throwsFlutterError);
......@@ -89,7 +87,7 @@ void main() {
expect(BoxBorder.lerp(null, directionalWithTop10, 0.75), const BorderDirectional(top: BorderSide(width: 7.5)));
expect(BoxBorder.lerp(directionalWithTop10, visualWithTop100, 0.75), const Border(top: BorderSide(width: 77.5)));
expect(BoxBorder.lerp(visualWithSides10, directionalWithMagentaTop5, 0.75), visualWithSides10At25 + directionalWithMagentaTop5At75);
expect(BoxBorder.lerp(visualWithYellowTop5, directionalWithMagentaTop5, 0.75), Border(top: BorderSide(width: 5.0, color: Color.lerp(const Color(0xFFFFFF00), const Color(0xFFFF00FF), 0.75))));
expect(BoxBorder.lerp(visualWithYellowTop5, directionalWithMagentaTop5, 0.75), Border(top: BorderSide(width: 5.0, color: Color.lerp(const Color(0xFFFFFF00), const Color(0xFFFF00FF), 0.75)!)));
expect(BoxBorder.lerp(visualWithSides10, directionalWithSides10, 0.75), directionalWithSides10At50);
expect(BoxBorder.lerp(visualWithYellowTop5, directionalWithSides10, 0.75), visualWithYellowTop5At25 + directionalWithSides10At75);
expect(() => BoxBorder.lerp(SillyBorder(), const Border(), 0.75), throwsFlutterError);
......@@ -120,7 +118,7 @@ void main() {
});
test('BoxBorder.lerp throws correct FlutterError message', () {
FlutterError error;
late FlutterError error;
try {
BoxBorder.lerp(SillyBorder(), const Border(), 2.0);
} on FlutterError catch (e) {
......@@ -353,13 +351,6 @@ void main() {
);
});
test('BorderDirectional constructor', () {
expect(() => BorderDirectional(top: nonconst(null)), throwsAssertionError);
expect(() => BorderDirectional(start: nonconst(null)), throwsAssertionError);
expect(() => BorderDirectional(end: nonconst(null)), throwsAssertionError);
expect(() => BorderDirectional(bottom: nonconst(null)), throwsAssertionError);
});
test('BorderDirectional.merge', () {
const BorderSide magenta3 = BorderSide(color: Color(0xFFFF00FF), width: 3.0);
const BorderSide magenta6 = BorderSide(color: Color(0xFFFF00FF), width: 6.0);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -17,9 +15,6 @@ void main() {
style: BorderStyle.solid,
),
);
expect(() => BorderSide(color: nonconst(null)), throwsAssertionError);
expect(() => BorderSide(width: nonconst(null)), throwsAssertionError);
expect(() => BorderSide(style: nonconst(null)), throwsAssertionError);
expect(() => BorderSide(width: nonconst(-1.0)), throwsAssertionError);
expect(
const BorderSide(width: -0.0),
......@@ -56,11 +51,8 @@ void main() {
expect( BorderSide.canMerge(none3, BorderSide.none), isTrue);
expect( BorderSide.canMerge(none3, side2), isFalse);
expect( BorderSide.canMerge(none3, yellowNone), isTrue);
expect(() => BorderSide.canMerge(null, null), throwsAssertionError);
expect(() => BorderSide.canMerge(null, side2), throwsAssertionError);
expect( BorderSide.canMerge(side2, BorderSide.none), isTrue);
expect( BorderSide.canMerge(side2, none3), isFalse);
expect(() => BorderSide.canMerge(side2, null), throwsAssertionError);
expect( BorderSide.canMerge(side2, side3), isTrue);
expect( BorderSide.canMerge(side2, yellowNone), isTrue);
expect( BorderSide.canMerge(side3, side2), isTrue);
......@@ -78,11 +70,8 @@ void main() {
expect( BorderSide.merge(none3, BorderSide.none), none3);
expect(() => BorderSide.merge(none3, side2), throwsAssertionError);
expect( BorderSide.merge(none3, yellowNone), none3);
expect(() => BorderSide.merge(null, null), throwsAssertionError);
expect(() => BorderSide.merge(null, side2), throwsAssertionError);
expect( BorderSide.merge(side2, BorderSide.none), side2);
expect(() => BorderSide.merge(side2, none3), throwsAssertionError);
expect(() => BorderSide.merge(side2, null), throwsAssertionError);
expect( BorderSide.merge(side2, side3), side5);
expect( BorderSide.merge(side2, yellowNone), side2);
expect( BorderSide.merge(side3, side2), side5);
......
......@@ -2,21 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Border constructor', () {
expect(() => Border(left: nonconst(null)), throwsAssertionError);
expect(() => Border(top: nonconst(null)), throwsAssertionError);
expect(() => Border(right: nonconst(null)), throwsAssertionError);
expect(() => Border(bottom: nonconst(null)), throwsAssertionError);
});
test('Border.uniform constructor', () {
expect(() => Border.fromBorderSide(null), throwsAssertionError);
const BorderSide side = BorderSide();
const Border border = Border.fromBorderSide(side);
expect(border.left, same(side));
......@@ -26,8 +16,6 @@ void main() {
});
test('Border.symmetric constructor', () {
expect(() => Border.symmetric(vertical: nonconst(null)), throwsAssertionError);
expect(() => Border.symmetric(horizontal: nonconst(null)), throwsAssertionError);
const BorderSide side1 = BorderSide(color: Color(0xFFFFFFFF));
const BorderSide side2 = BorderSide(color: Color(0xFF000000));
const Border border = Border.symmetric(vertical: side1, horizontal: side2);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/painting.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/painting.dart';
import '../flutter_test_alternative.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/painting.dart';
......@@ -26,7 +24,7 @@ void main() {
expect(BorderSide.lerp(side1, side2, 0.0), equals(side1));
expect(BorderSide.lerp(side1, side2, 1.0), equals(side2));
expect(BorderSide.lerp(side1, side2, 0.5), equals(BorderSide(
color: Color.lerp(const Color(0xFF000000), const Color(0xFF00FFFF), 0.5),
color: Color.lerp(const Color(0xFF000000), const Color(0xFF00FFFF), 0.5)!,
width: 1.5,
style: BorderStyle.solid,
)));
......@@ -55,8 +53,8 @@ void main() {
test('Border control test', () {
final Border border1 = Border.all(width: 4.0);
final Border border2 = Border.lerp(null, border1, 0.25);
final Border border3 = Border.lerp(border1, null, 0.25);
final Border border2 = Border.lerp(null, border1, 0.25)!;
final Border border3 = Border.lerp(border1, null, 0.25)!;
expect(border1, hasOneLineDescription);
expect(border1.hashCode, isNot(equals(border2.hashCode)));
......@@ -64,7 +62,7 @@ void main() {
expect(border2.top.width, equals(1.0));
expect(border3.bottom.width, equals(3.0));
final Border border4 = Border.lerp(border2, border3, 0.5);
final Border border4 = Border.lerp(border2, border3, 0.5)!;
expect(border4.left.width, equals(2.0));
});
......@@ -90,8 +88,8 @@ void main() {
test('BoxShadow control test', () {
const BoxShadow shadow1 = BoxShadow(blurRadius: 4.0);
final BoxShadow shadow2 = BoxShadow.lerp(null, shadow1, 0.25);
final BoxShadow shadow3 = BoxShadow.lerp(shadow1, null, 0.25);
final BoxShadow shadow2 = BoxShadow.lerp(null, shadow1, 0.25)!;
final BoxShadow shadow3 = BoxShadow.lerp(shadow1, null, 0.25)!;
expect(shadow1, hasOneLineDescription);
expect(shadow1.hashCode, isNot(equals(shadow2.hashCode)));
......@@ -100,14 +98,14 @@ void main() {
expect(shadow2.blurRadius, equals(1.0));
expect(shadow3.blurRadius, equals(3.0));
final BoxShadow shadow4 = BoxShadow.lerp(shadow2, shadow3, 0.5);
final BoxShadow shadow4 = BoxShadow.lerp(shadow2, shadow3, 0.5)!;
expect(shadow4.blurRadius, equals(2.0));
List<BoxShadow> shadowList = BoxShadow.lerpList(
<BoxShadow>[shadow2, shadow1], <BoxShadow>[shadow3], 0.5);
<BoxShadow>[shadow2, shadow1], <BoxShadow>[shadow3], 0.5)!;
expect(shadowList, equals(<BoxShadow>[shadow4, shadow1.scale(0.5)]));
shadowList = BoxShadow.lerpList(
<BoxShadow>[shadow2], <BoxShadow>[shadow3, shadow1], 0.5);
<BoxShadow>[shadow2], <BoxShadow>[shadow3, shadow1], 0.5)!;
expect(shadowList, equals(<BoxShadow>[shadow4, shadow1.scale(0.5)]));
});
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -25,7 +23,7 @@ void main() {
expect(color.toColor(), const Color(0xb399816b));
final HSVColor result = HSVColor.lerp(color, const HSVColor.fromAHSV(0.3, 128.0, 0.7, 0.2), 0.25);
final HSVColor result = HSVColor.lerp(color, const HSVColor.fromAHSV(0.3, 128.0, 0.7, 0.2), 0.25)!;
expect(result.alpha, moreOrLessEquals(0.6));
expect(result.hue, moreOrLessEquals(53.0));
expect(result.saturation, greaterThan(0.3999));
......@@ -129,7 +127,7 @@ void main() {
const HSVColor endColor = HSVColor.fromAHSV(1.0, 360.0, 1.0, 1.0);
for (double t = -0.5; t < 1.5; t += 0.1) {
output.add(HSVColor.lerp(startColor, endColor, t).toColor());
output.add(HSVColor.lerp(startColor, endColor, t)!.toColor());
}
final List<Color> expectedColors = <Color>[
const Color(0xff00ffff),
......@@ -162,7 +160,7 @@ void main() {
const HSVColor endColor = HSVColor.fromAHSV(1.0, 0.0, 1.0, 1.0);
for (double t = -0.1; t < 1.1; t += 0.1) {
output.add(HSVColor.lerp(startColor, endColor, t).toColor());
output.add(HSVColor.lerp(startColor, endColor, t)!.toColor());
}
final List<Color> expectedColors = <Color>[
const Color(0xffffffff),
......@@ -188,7 +186,7 @@ void main() {
const HSVColor endColor = HSVColor.fromAHSV(1.0, 0.0, 1.0, 1.0);
for (double t = -0.1; t < 1.1; t += 0.1) {
output.add(HSVColor.lerp(startColor, endColor, t).toColor());
output.add(HSVColor.lerp(startColor, endColor, t)!.toColor());
}
final List<Color> expectedColors = <Color>[
const Color(0xff000000),
......@@ -221,7 +219,7 @@ void main() {
expect(color.toColor(), const Color(0xb3b8977a));
final HSLColor result = HSLColor.lerp(color, const HSLColor.fromAHSL(0.3, 128.0, 0.7, 0.2), 0.25);
final HSLColor result = HSLColor.lerp(color, const HSLColor.fromAHSL(0.3, 128.0, 0.7, 0.2), 0.25)!;
expect(result.alpha, moreOrLessEquals(0.6));
expect(result.hue, moreOrLessEquals(53.0));
expect(result.saturation, greaterThan(0.3999));
......@@ -324,7 +322,7 @@ void main() {
const HSLColor endColor = HSLColor.fromAHSL(1.0, 360.0, 0.5, 0.5);
for (double t = -0.5; t < 1.5; t += 0.1) {
output.add(HSLColor.lerp(startColor, endColor, t).toColor());
output.add(HSLColor.lerp(startColor, endColor, t)!.toColor());
}
final List<Color> expectedColors = <Color>[
const Color(0xff40bfbf),
......@@ -357,7 +355,7 @@ void main() {
const HSLColor endColor = HSLColor.fromAHSL(1.0, 0.0, 1.0, 0.5);
for (double t = -0.1; t < 1.1; t += 0.1) {
output.add(HSLColor.lerp(startColor, endColor, t).toColor());
output.add(HSLColor.lerp(startColor, endColor, t)!.toColor());
}
final List<Color> expectedColors = <Color>[
const Color(0xff808080),
......@@ -383,7 +381,7 @@ void main() {
const HSLColor endColor = HSLColor.fromAHSL(1.0, 0.0, 0.5, 1.0);
for (double t = -0.1; t < 1.1; t += 0.1) {
output.add(HSLColor.lerp(startColor, endColor, t).toColor());
output.add(HSLColor.lerp(startColor, endColor, t)!.toColor());
}
final List<Color> expectedColors = <Color>[
const Color(0xff000000),
......@@ -438,7 +436,7 @@ void main() {
expect(valueProperties['blue'], 40);
property = ColorProperty('foo', null);
final Map<String, Object> json = property.toJsonMap(const DiagnosticsSerializationDelegate());
final Map<String, Object?> json = property.toJsonMap(const DiagnosticsSerializationDelegate());
expect(json.containsKey('valueProperties'), isFalse);
});
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
@TestOn('!chrome')
import 'dart:async';
import 'dart:ui' as ui show Image, ColorFilter;
......@@ -17,13 +15,11 @@ import '../painting/mocks_for_image_cache.dart';
import '../rendering/rendering_tester.dart';
class TestCanvas implements Canvas {
TestCanvas([this.invocations]);
final List<Invocation> invocations;
final List<Invocation> invocations = <Invocation>[];
@override
void noSuchMethod(Invocation invocation) {
invocations?.add(invocation);
invocations.add(invocation);
}
}
......@@ -177,7 +173,7 @@ void main() {
// A reference test would be better.
test('BoxDecoration backgroundImage clip', () async {
final ui.Image image = await createTestImage(width: 100, height: 100);
void testDecoration({ BoxShape shape = BoxShape.rectangle, BorderRadius borderRadius, bool expectClip }) {
void testDecoration({ BoxShape shape = BoxShape.rectangle, BorderRadius? borderRadius, required bool expectClip }) {
assert(shape != null);
FakeAsync().run((FakeAsync async) async {
final DelayedImageProvider imageProvider = DelayedImageProvider(image);
......@@ -189,8 +185,7 @@ void main() {
image: backgroundImage,
);
final List<Invocation> invocations = <Invocation>[];
final TestCanvas canvas = TestCanvas(invocations);
final TestCanvas canvas = TestCanvas();
const ImageConfiguration imageConfiguration = ImageConfiguration(
size: Size(100.0, 100.0)
);
......@@ -244,7 +239,7 @@ void main() {
final BoxDecoration boxDecoration = BoxDecoration(image: backgroundImage);
final BoxPainter boxPainter = boxDecoration.createBoxPainter(() { assert(false); });
final TestCanvas canvas = TestCanvas(<Invocation>[]);
final TestCanvas canvas = TestCanvas();
boxPainter.paint(canvas, Offset.zero, const ImageConfiguration(size: Size(100.0, 100.0)));
final Invocation call = canvas.invocations.singleWhere((Invocation call) => call.memberName == #drawImageNine);
......@@ -270,8 +265,8 @@ void main() {
final BoxPainter boxPainter = boxDecoration.createBoxPainter(() {
assert(false);
});
final TestCanvas canvas = TestCanvas(<Invocation>[]);
FlutterError error;
final TestCanvas canvas = TestCanvas();
late FlutterError error;
try {
boxPainter.paint(canvas, Offset.zero, const ImageConfiguration(
size: Size(100.0, 100.0), textDirection: null));
......@@ -297,10 +292,10 @@ void main() {
});
test('DecorationImage - error listener', () async {
String exception;
late String exception;
final DecorationImage backgroundImage = DecorationImage(
image: const SynchronousErrorTestImageProvider('threw'),
onError: (dynamic error, StackTrace stackTrace) {
onError: (dynamic error, StackTrace? stackTrace) {
exception = error as String;
}
);
......@@ -430,7 +425,7 @@ void main() {
test('paintImage BoxFit.none scale test', () async {
for (double scale = 1.0; scale <= 4.0; scale += 1.0) {
final TestCanvas canvas = TestCanvas(<Invocation>[]);
final TestCanvas canvas = TestCanvas();
const Rect outputRect = Rect.fromLTWH(30.0, 30.0, 250.0, 250.0);
final ui.Image image = await createTestImage(width: 100, height: 100);
......@@ -473,7 +468,7 @@ void main() {
test('paintImage BoxFit.scaleDown scale test', () async {
for (double scale = 1.0; scale <= 4.0; scale += 1.0) {
final TestCanvas canvas = TestCanvas(<Invocation>[]);
final TestCanvas canvas = TestCanvas();
// container size > scaled image size
const Rect outputRect = Rect.fromLTWH(30.0, 30.0, 250.0, 250.0);
......@@ -516,7 +511,7 @@ void main() {
});
test('paintImage BoxFit.scaleDown test', () async {
final TestCanvas canvas = TestCanvas(<Invocation>[]);
final TestCanvas canvas = TestCanvas();
// container height (20 px) < scaled image height (50 px)
const Rect outputRect = Rect.fromLTWH(30.0, 30.0, 250.0, 20.0);
......@@ -569,7 +564,7 @@ void main() {
];
for (final BoxFit boxFit in boxFits) {
final TestCanvas canvas = TestCanvas(<Invocation>[]);
final TestCanvas canvas = TestCanvas();
const Rect outputRect = Rect.fromLTWH(30.0, 30.0, 250.0, 250.0);
final ui.Image image = await createTestImage(width: 100, height: 100);
......@@ -595,18 +590,6 @@ void main() {
}
});
test('scale cannot be null in DecorationImage', () async {
final ui.Image image = await createTestImage(width: 100, height: 100);
try {
DecorationImage(scale: null, image: SynchronousTestImageProvider(image));
} on AssertionError catch (error) {
expect(error.toString(), contains('scale != null'));
expect(error.toString(), contains('is not true'));
return;
}
fail('DecorationImage did not throw AssertionError when scale was null');
});
test('DecorationImage scale test', () async {
final ui.Image image = await createTestImage(width: 100, height: 100);
final DecorationImage backgroundImage = DecorationImage(
......@@ -617,7 +600,7 @@ void main() {
final BoxDecoration boxDecoration = BoxDecoration(image: backgroundImage);
final BoxPainter boxPainter = boxDecoration.createBoxPainter(() { assert(false); });
final TestCanvas canvas = TestCanvas(<Invocation>[]);
final TestCanvas canvas = TestCanvas();
boxPainter.paint(canvas, Offset.zero, const ImageConfiguration(size: Size(100.0, 100.0)));
final Invocation call = canvas.invocations.firstWhere((Invocation call) => call.memberName == #drawImageRect);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment