Unverified Commit cbf1e135 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate non-test files in flutter/test (#67098)

parent ddb81770
...@@ -58,6 +58,10 @@ class SynchronousErrorTestImageProvider extends ImageProvider<int> { ...@@ -58,6 +58,10 @@ class SynchronousErrorTestImageProvider extends ImageProvider<int> {
} }
class AsyncTestImageProvider extends ImageProvider<int> { class AsyncTestImageProvider extends ImageProvider<int> {
AsyncTestImageProvider(this.image);
final ui.Image image;
@override @override
Future<int> obtainKey(ImageConfiguration configuration) { Future<int> obtainKey(ImageConfiguration configuration) {
return Future<int>.value(2); return Future<int>.value(2);
...@@ -66,7 +70,7 @@ class AsyncTestImageProvider extends ImageProvider<int> { ...@@ -66,7 +70,7 @@ class AsyncTestImageProvider extends ImageProvider<int> {
@override @override
ImageStreamCompleter load(int key, DecoderCallback decode) { ImageStreamCompleter load(int key, DecoderCallback decode) {
return OneFrameImageStreamCompleter( return OneFrameImageStreamCompleter(
Future<ImageInfo>.value(TestImageInfo(key)) Future<ImageInfo>.value(TestImageInfo(key, image: image))
); );
} }
} }
...@@ -147,9 +151,10 @@ void main() { ...@@ -147,9 +151,10 @@ void main() {
expect(onChangedCalled, equals(false)); expect(onChangedCalled, equals(false));
}); });
test('BoxDecorationImageListenerAsync', () { test('BoxDecorationImageListenerAsync', () async {
final ui.Image image = await createTestImage(width: 10, height: 10);
FakeAsync().run((FakeAsync async) { FakeAsync().run((FakeAsync async) {
final ImageProvider imageProvider = AsyncTestImageProvider(); final ImageProvider imageProvider = AsyncTestImageProvider(image);
final DecorationImage backgroundImage = DecorationImage(image: imageProvider); final DecorationImage backgroundImage = DecorationImage(image: imageProvider);
final BoxDecoration boxDecoration = BoxDecoration(image: backgroundImage); final BoxDecoration boxDecoration = BoxDecoration(image: backgroundImage);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui show Codec, FrameInfo, instantiateImageCodec; import 'dart:ui' as ui show Codec, FrameInfo, instantiateImageCodec;
...@@ -28,9 +26,9 @@ class FakeCodec implements ui.Codec { ...@@ -28,9 +26,9 @@ class FakeCodec implements ui.Codec {
static Future<FakeCodec> fromData(Uint8List data) async { static Future<FakeCodec> fromData(Uint8List data) async {
final ui.Codec codec = await ui.instantiateImageCodec(data); final ui.Codec codec = await ui.instantiateImageCodec(data);
final int frameCount = codec.frameCount; final int frameCount = codec.frameCount;
final List<ui.FrameInfo> frameInfos = List<ui.FrameInfo>(frameCount); final List<ui.FrameInfo> frameInfos = <ui.FrameInfo>[];
for (int i = 0; i < frameCount; i += 1) for (int i = 0; i < frameCount; i += 1)
frameInfos[i] = await codec.getNextFrame(); frameInfos.add(await codec.getNextFrame());
return FakeCodec._(frameCount, codec.repetitionCount, frameInfos); return FakeCodec._(frameCount, codec.repetitionCount, frameInfos);
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' as ui show Codec; import 'dart:ui' as ui show Codec;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'dart:ui' as ui; import 'dart:ui' as ui;
...@@ -19,7 +17,7 @@ class TestImageProvider extends ImageProvider<TestImageProvider> { ...@@ -19,7 +17,7 @@ class TestImageProvider extends ImageProvider<TestImageProvider> {
final ui.Image testImage; final ui.Image testImage;
final Completer<ImageInfo> _completer = Completer<ImageInfo>.sync(); final Completer<ImageInfo> _completer = Completer<ImageInfo>.sync();
ImageConfiguration configuration; ImageConfiguration? configuration;
int loadCallCount = 0; int loadCallCount = 0;
@override @override
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'dart:ui' as ui show Image; import 'dart:ui' as ui show Image;
...@@ -11,7 +9,7 @@ import 'package:flutter/foundation.dart'; ...@@ -11,7 +9,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
class TestImageInfo implements ImageInfo { class TestImageInfo implements ImageInfo {
const TestImageInfo(this.value, { this.image, this.scale = 1.0, this.debugLabel }); const TestImageInfo(this.value, { required this.image, this.scale = 1.0, this.debugLabel });
@override @override
final ui.Image image; final ui.Image image;
...@@ -20,7 +18,7 @@ class TestImageInfo implements ImageInfo { ...@@ -20,7 +18,7 @@ class TestImageInfo implements ImageInfo {
final double scale; final double scale;
@override @override
final String debugLabel; final String? debugLabel;
final int value; final int value;
...@@ -29,7 +27,7 @@ class TestImageInfo implements ImageInfo { ...@@ -29,7 +27,7 @@ class TestImageInfo implements ImageInfo {
} }
class TestImageProvider extends ImageProvider<int> { class TestImageProvider extends ImageProvider<int> {
const TestImageProvider(this.key, this.imageValue, { @required this.image }) const TestImageProvider(this.key, this.imageValue, { required this.image })
: assert(image != null); : assert(image != null);
final int key; final int key;
...@@ -53,7 +51,7 @@ class TestImageProvider extends ImageProvider<int> { ...@@ -53,7 +51,7 @@ class TestImageProvider extends ImageProvider<int> {
} }
class FailingTestImageProvider extends TestImageProvider { class FailingTestImageProvider extends TestImageProvider {
const FailingTestImageProvider(int key, int imageValue, { ui.Image image }) : super(key, imageValue, image: image); const FailingTestImageProvider(int key, int imageValue, { required ui.Image image }) : super(key, imageValue, image: image);
@override @override
ImageStreamCompleter load(int key, DecoderCallback decode) { ImageStreamCompleter load(int key, DecoderCallback decode) {
...@@ -63,7 +61,7 @@ class FailingTestImageProvider extends TestImageProvider { ...@@ -63,7 +61,7 @@ class FailingTestImageProvider extends TestImageProvider {
Future<ImageInfo> extractOneFrame(ImageStream stream) { Future<ImageInfo> extractOneFrame(ImageStream stream) {
final Completer<ImageInfo> completer = Completer<ImageInfo>(); final Completer<ImageInfo> completer = Completer<ImageInfo>();
ImageStreamListener listener; late ImageStreamListener listener;
listener = ImageStreamListener((ImageInfo image, bool synchronousCall) { listener = ImageStreamListener((ImageInfo image, bool synchronousCall) {
completer.complete(image); completer.complete(image);
stream.removeListener(listener); stream.removeListener(listener);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui; import 'dart:ui' as ui;
...@@ -17,7 +15,7 @@ class PaintingBindingSpy extends BindingBase with SchedulerBinding, ServicesBind ...@@ -17,7 +15,7 @@ class PaintingBindingSpy extends BindingBase with SchedulerBinding, ServicesBind
int get instantiateImageCodecCalledCount => counter; int get instantiateImageCodecCalledCount => counter;
@override @override
Future<ui.Codec> instantiateImageCodec(Uint8List list, {int cacheWidth, int cacheHeight, bool allowUpscaling = false}) { Future<ui.Codec> instantiateImageCodec(Uint8List list, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) {
counter++; counter++;
return ui.instantiateImageCodec(list); return ui.instantiateImageCodec(list);
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
...@@ -20,7 +18,7 @@ class _TestHitTester extends RenderBox { ...@@ -20,7 +18,7 @@ class _TestHitTester extends RenderBox {
final BoxHitTest hitTestOverride; final BoxHitTest hitTestOverride;
@override @override
bool hitTest(BoxHitTestResult result, {ui.Offset position}) { bool hitTest(BoxHitTestResult result, {required ui.Offset position}) {
return hitTestOverride(result, position); return hitTestOverride(result, position);
} }
} }
...@@ -39,7 +37,7 @@ class TestMouseTrackerFlutterBinding extends BindingBase ...@@ -39,7 +37,7 @@ class TestMouseTrackerFlutterBinding extends BindingBase
renderView.child = _TestHitTester(hitTest); renderView.child = _TestHitTester(hitTest);
} }
SchedulerPhase _overridePhase; SchedulerPhase? _overridePhase;
@override @override
SchedulerPhase get schedulerPhase => _overridePhase ?? super.schedulerPhase; SchedulerPhase get schedulerPhase => _overridePhase ?? super.schedulerPhase;
...@@ -48,7 +46,7 @@ class TestMouseTrackerFlutterBinding extends BindingBase ...@@ -48,7 +46,7 @@ class TestMouseTrackerFlutterBinding extends BindingBase
// In real apps this is done by the renderer binding, but in tests we have to // In real apps this is done by the renderer binding, but in tests we have to
// bypass the phase assertion of [MouseTracker.schedulePostFrameCheck]. // bypass the phase assertion of [MouseTracker.schedulePostFrameCheck].
void scheduleMouseTrackerPostFrameCheck() { void scheduleMouseTrackerPostFrameCheck() {
final SchedulerPhase lastPhase = _overridePhase; final SchedulerPhase? lastPhase = _overridePhase;
_overridePhase = SchedulerPhase.persistentCallbacks; _overridePhase = SchedulerPhase.persistentCallbacks;
addPostFrameCallback((_) { addPostFrameCallback((_) {
mouseTracker.updateAllDevices(renderView.hitTestMouseTrackers); mouseTracker.updateAllDevices(renderView.hitTestMouseTrackers);
...@@ -77,13 +75,13 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation ...@@ -77,13 +75,13 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation
const TestAnnotationTarget({this.onEnter, this.onHover, this.onExit, this.cursor = MouseCursor.defer}); const TestAnnotationTarget({this.onEnter, this.onHover, this.onExit, this.cursor = MouseCursor.defer});
@override @override
final PointerEnterEventListener onEnter; final PointerEnterEventListener? onEnter;
@override @override
final PointerHoverEventListener onHover; final PointerHoverEventListener? onHover;
@override @override
final PointerExitEventListener onExit; final PointerExitEventListener? onExit;
@override @override
final MouseCursor cursor; final MouseCursor cursor;
...@@ -92,14 +90,14 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation ...@@ -92,14 +90,14 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation
void handleEvent(PointerEvent event, HitTestEntry entry) { void handleEvent(PointerEvent event, HitTestEntry entry) {
if (event is PointerHoverEvent) if (event is PointerHoverEvent)
if (onHover != null) if (onHover != null)
onHover(event); onHover!(event);
} }
} }
// A hit test entry that can be assigned with a [TestAnnotationTarget] and an // A hit test entry that can be assigned with a [TestAnnotationTarget] and an
// optional transform matrix. // optional transform matrix.
class TestAnnotationEntry extends HitTestEntry { class TestAnnotationEntry extends HitTestEntry {
TestAnnotationEntry(TestAnnotationTarget target, [Matrix4 transform]) TestAnnotationEntry(TestAnnotationTarget target, [Matrix4? transform])
: transform = transform ?? Matrix4.identity(), super(target); : transform = transform ?? Matrix4.identity(), super(target);
@override @override
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/src/rendering/layer.dart'; import 'package:flutter/src/rendering/layer.dart';
...@@ -13,7 +11,7 @@ import 'package:flutter/src/rendering/layer.dart'; ...@@ -13,7 +11,7 @@ import 'package:flutter/src/rendering/layer.dart';
/// Used by [TestRecordingCanvas] to trace canvas calls. /// Used by [TestRecordingCanvas] to trace canvas calls.
class RecordedInvocation { class RecordedInvocation {
/// Create a record for an invocation list. /// Create a record for an invocation list.
const RecordedInvocation(this.invocation, { this.stack }); const RecordedInvocation(this.invocation, { required this.stack });
/// The method that was called and its arguments. /// The method that was called and its arguments.
/// ///
...@@ -74,7 +72,7 @@ class TestRecordingCanvas implements Canvas { ...@@ -74,7 +72,7 @@ class TestRecordingCanvas implements Canvas {
} }
@override @override
void saveLayer(Rect bounds, Paint paint) { void saveLayer(Rect? bounds, Paint paint) {
_saveCount += 1; _saveCount += 1;
invocations.add(RecordedInvocation(_MethodCall(#saveLayer, <dynamic>[bounds, paint]), stack: StackTrace.current)); invocations.add(RecordedInvocation(_MethodCall(#saveLayer, <dynamic>[bounds, paint]), stack: StackTrace.current));
} }
...@@ -106,27 +104,27 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex ...@@ -106,27 +104,27 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex
} }
@override @override
ClipRectLayer pushClipRect( ClipRectLayer? pushClipRect(
bool needsCompositing, bool needsCompositing,
Offset offset, Offset offset,
Rect clipRect, Rect clipRect,
PaintingContextCallback painter, { PaintingContextCallback painter, {
Clip clipBehavior = Clip.hardEdge, Clip clipBehavior = Clip.hardEdge,
ClipRectLayer oldLayer, ClipRectLayer? oldLayer,
}) { }) {
clipRectAndPaint(clipRect.shift(offset), clipBehavior, clipRect.shift(offset), () => painter(this, offset)); clipRectAndPaint(clipRect.shift(offset), clipBehavior, clipRect.shift(offset), () => painter(this, offset));
return null; return null;
} }
@override @override
ClipRRectLayer pushClipRRect( ClipRRectLayer? pushClipRRect(
bool needsCompositing, bool needsCompositing,
Offset offset, Offset offset,
Rect bounds, Rect bounds,
RRect clipRRect, RRect clipRRect,
PaintingContextCallback painter, { PaintingContextCallback painter, {
Clip clipBehavior = Clip.antiAlias, Clip clipBehavior = Clip.antiAlias,
ClipRRectLayer oldLayer, ClipRRectLayer? oldLayer,
}) { }) {
assert(clipBehavior != null); assert(clipBehavior != null);
clipRRectAndPaint(clipRRect.shift(offset), clipBehavior, bounds.shift(offset), () => painter(this, offset)); clipRRectAndPaint(clipRRect.shift(offset), clipBehavior, bounds.shift(offset), () => painter(this, offset));
...@@ -134,26 +132,26 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex ...@@ -134,26 +132,26 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex
} }
@override @override
ClipPathLayer pushClipPath( ClipPathLayer? pushClipPath(
bool needsCompositing, bool needsCompositing,
Offset offset, Offset offset,
Rect bounds, Rect bounds,
Path clipPath, Path clipPath,
PaintingContextCallback painter, { PaintingContextCallback painter, {
Clip clipBehavior = Clip.antiAlias, Clip clipBehavior = Clip.antiAlias,
ClipPathLayer oldLayer, ClipPathLayer? oldLayer,
}) { }) {
clipPathAndPaint(clipPath.shift(offset), clipBehavior, bounds.shift(offset), () => painter(this, offset)); clipPathAndPaint(clipPath.shift(offset), clipBehavior, bounds.shift(offset), () => painter(this, offset));
return null; return null;
} }
@override @override
TransformLayer pushTransform( TransformLayer? pushTransform(
bool needsCompositing, bool needsCompositing,
Offset offset, Offset offset,
Matrix4 transform, Matrix4 transform,
PaintingContextCallback painter, { PaintingContextCallback painter, {
TransformLayer oldLayer, TransformLayer? oldLayer,
}) { }) {
canvas.save(); canvas.save();
canvas.transform(transform.storage); canvas.transform(transform.storage);
...@@ -163,17 +161,25 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex ...@@ -163,17 +161,25 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex
} }
@override @override
OpacityLayer pushOpacity(Offset offset, int alpha, PaintingContextCallback painter, OpacityLayer pushOpacity(
{ OpacityLayer oldLayer }) { Offset offset,
canvas.saveLayer(null, null); // TODO(ianh): Expose the alpha somewhere. int alpha,
PaintingContextCallback painter, {
OpacityLayer? oldLayer,
}) {
canvas.saveLayer(null, Paint()); // TODO(ianh): Expose the alpha somewhere.
painter(this, offset); painter(this, offset);
canvas.restore(); canvas.restore();
return null; return OpacityLayer();
} }
@override @override
void pushLayer(Layer childLayer, PaintingContextCallback painter, Offset offset, void pushLayer(
{ Rect childPaintBounds }) { Layer childLayer,
PaintingContextCallback painter,
Offset offset, {
Rect? childPaintBounds,
}) {
painter(this, offset); painter(this, offset);
} }
...@@ -204,7 +210,7 @@ class _MethodCall implements Invocation { ...@@ -204,7 +210,7 @@ class _MethodCall implements Invocation {
List<Type> get typeArguments => _typeArguments; List<Type> get typeArguments => _typeArguments;
} }
String _valueName(Object value) { String _valueName(Object? value) {
if (value is double) if (value is double)
return value.toStringAsFixed(1); return value.toStringAsFixed(1);
return value.toString(); return value.toString();
...@@ -228,7 +234,7 @@ String _describeInvocation(Invocation call) { ...@@ -228,7 +234,7 @@ String _describeInvocation(Invocation call) {
buffer.write('('); buffer.write('(');
buffer.writeAll(call.positionalArguments.map<String>(_valueName), ', '); buffer.writeAll(call.positionalArguments.map<String>(_valueName), ', ');
String separator = call.positionalArguments.isEmpty ? '' : ', '; String separator = call.positionalArguments.isEmpty ? '' : ', ';
call.namedArguments.forEach((Symbol name, Object value) { call.namedArguments.forEach((Symbol name, Object? value) {
buffer.write(separator); buffer.write(separator);
buffer.write(_symbolName(name)); buffer.write(_symbolName(name));
buffer.write(': '); buffer.write(': ');
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -29,7 +27,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser ...@@ -29,7 +27,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser
TestRenderingFlutterBinding({ this.onErrors }) { TestRenderingFlutterBinding({ this.onErrors }) {
FlutterError.onError = (FlutterErrorDetails details) { FlutterError.onError = (FlutterErrorDetails details) {
FlutterError.dumpErrorToConsole(details); FlutterError.dumpErrorToConsole(details);
Zone.current.parent.handleUncaughtError(details.exception, details.stack); Zone.current.parent!.handleUncaughtError(details.exception as Object, details.stack!);
}; };
} }
...@@ -40,14 +38,14 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser ...@@ -40,14 +38,14 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser
/// This function is expected to inspect these errors and decide whether they /// This function is expected to inspect these errors and decide whether they
/// are expected or not. Use [takeFlutterErrorDetails] to take one error at a /// are expected or not. Use [takeFlutterErrorDetails] to take one error at a
/// time, or [takeAllFlutterErrorDetails] to iterate over all errors. /// time, or [takeAllFlutterErrorDetails] to iterate over all errors.
VoidCallback onErrors; VoidCallback? onErrors;
/// Returns the error least recently caught by [FlutterError] and removes it /// Returns the error least recently caught by [FlutterError] and removes it
/// from the list of captured errors. /// from the list of captured errors.
/// ///
/// Returns null if no errors were captures, or if the list was exhausted by /// Returns null if no errors were captures, or if the list was exhausted by
/// calling this method repeatedly. /// calling this method repeatedly.
FlutterErrorDetails takeFlutterErrorDetails() { FlutterErrorDetails? takeFlutterErrorDetails() {
if (_errors.isEmpty) { if (_errors.isEmpty) {
return null; return null;
} }
...@@ -87,7 +85,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser ...@@ -87,7 +85,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser
@override @override
void drawFrame() { void drawFrame() {
assert(phase != EnginePhase.build, 'rendering_tester does not support testing the build phase; use flutter_test instead'); assert(phase != EnginePhase.build, 'rendering_tester does not support testing the build phase; use flutter_test instead');
final FlutterExceptionHandler oldErrorHandler = FlutterError.onError; final FlutterExceptionHandler? oldErrorHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) { FlutterError.onError = (FlutterErrorDetails details) {
_errors.add(details); _errors.add(details);
}; };
...@@ -113,7 +111,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser ...@@ -113,7 +111,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser
FlutterError.onError = oldErrorHandler; FlutterError.onError = oldErrorHandler;
if (_errors.isNotEmpty) { if (_errors.isNotEmpty) {
if (onErrors != null) { if (onErrors != null) {
onErrors(); onErrors!();
if (_errors.isNotEmpty) { if (_errors.isNotEmpty) {
_errors.forEach(FlutterError.dumpErrorToConsole); _errors.forEach(FlutterError.dumpErrorToConsole);
fail('There are more errors than the test inspected using TestRenderingFlutterBinding.takeFlutterErrorDetails.'); fail('There are more errors than the test inspected using TestRenderingFlutterBinding.takeFlutterErrorDetails.');
...@@ -127,11 +125,9 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser ...@@ -127,11 +125,9 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser
} }
} }
TestRenderingFlutterBinding _renderer; late final TestRenderingFlutterBinding _renderer = TestRenderingFlutterBinding();
TestRenderingFlutterBinding get renderer { TestRenderingFlutterBinding get renderer => _renderer;
_renderer ??= TestRenderingFlutterBinding();
return _renderer;
}
/// Place the box in the render tree, at the given size and with the given /// Place the box in the render tree, at the given size and with the given
/// alignment on the screen. /// alignment on the screen.
...@@ -149,10 +145,10 @@ TestRenderingFlutterBinding get renderer { ...@@ -149,10 +145,10 @@ TestRenderingFlutterBinding get renderer {
/// If `onErrors` is not null, it is set as [TestRenderingFlutterBinding.onError]. /// If `onErrors` is not null, it is set as [TestRenderingFlutterBinding.onError].
void layout( void layout(
RenderBox box, { RenderBox box, {
BoxConstraints constraints, BoxConstraints? constraints,
Alignment alignment = Alignment.center, Alignment alignment = Alignment.center,
EnginePhase phase = EnginePhase.layout, EnginePhase phase = EnginePhase.layout,
VoidCallback onErrors, VoidCallback? onErrors,
}) { }) {
assert(box != null); // If you want to just repump the last box, call pumpFrame(). assert(box != null); // If you want to just repump the last box, call pumpFrame().
assert(box.parent == null); // We stick the box in another, so you can't reuse it easily, sorry. assert(box.parent == null); // We stick the box in another, so you can't reuse it easily, sorry.
...@@ -175,7 +171,7 @@ void layout( ...@@ -175,7 +171,7 @@ void layout(
/// Pumps a single frame. /// Pumps a single frame.
/// ///
/// If `onErrors` is not null, it is set as [TestRenderingFlutterBinding.onError]. /// If `onErrors` is not null, it is set as [TestRenderingFlutterBinding.onError].
void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback onErrors }) { void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback? onErrors }) {
assert(renderer != null); assert(renderer != null);
assert(renderer.renderView != null); assert(renderer.renderView != null);
assert(renderer.renderView.child != null); // call layout() first! assert(renderer.renderView.child != null); // call layout() first!
...@@ -189,7 +185,7 @@ void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback onErrors } ...@@ -189,7 +185,7 @@ void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback onErrors }
} }
class TestCallbackPainter extends CustomPainter { class TestCallbackPainter extends CustomPainter {
const TestCallbackPainter({ this.onPaint }); const TestCallbackPainter({ required this.onPaint });
final VoidCallback onPaint; final VoidCallback onPaint;
...@@ -251,25 +247,25 @@ class FakeTickerProvider implements TickerProvider { ...@@ -251,25 +247,25 @@ class FakeTickerProvider implements TickerProvider {
class FakeTicker implements Ticker { class FakeTicker implements Ticker {
@override @override
bool muted; bool muted = false;
@override @override
void absorbTicker(Ticker originalTicker) { } void absorbTicker(Ticker originalTicker) { }
@override @override
String get debugLabel => null; String? get debugLabel => null;
@override @override
bool get isActive => null; bool get isActive => throw UnimplementedError();
@override @override
bool get isTicking => null; bool get isTicking => throw UnimplementedError();
@override @override
bool get scheduled => null; bool get scheduled => throw UnimplementedError();
@override @override
bool get shouldScheduleTick => null; bool get shouldScheduleTick => throw UnimplementedError();
@override @override
void dispose() { } void dispose() { }
...@@ -279,7 +275,7 @@ class FakeTicker implements Ticker { ...@@ -279,7 +275,7 @@ class FakeTicker implements Ticker {
@override @override
TickerFuture start() { TickerFuture start() {
return null; throw UnimplementedError();
} }
@override @override
...@@ -301,7 +297,14 @@ class TestClipPaintingContext extends PaintingContext { ...@@ -301,7 +297,14 @@ class TestClipPaintingContext extends PaintingContext {
TestClipPaintingContext() : super(ContainerLayer(), Rect.zero); TestClipPaintingContext() : super(ContainerLayer(), Rect.zero);
@override @override
ClipRectLayer pushClipRect(bool needsCompositing, Offset offset, Rect clipRect, PaintingContextCallback painter, {Clip clipBehavior = Clip.hardEdge, ClipRectLayer oldLayer}) { ClipRectLayer? pushClipRect(
bool needsCompositing,
Offset offset,
Rect clipRect,
PaintingContextCallback painter, {
Clip clipBehavior = Clip.hardEdge,
ClipRectLayer? oldLayer,
}) {
this.clipBehavior = clipBehavior; this.clipBehavior = clipBehavior;
return null; return null;
} }
...@@ -310,7 +313,7 @@ class TestClipPaintingContext extends PaintingContext { ...@@ -310,7 +313,7 @@ class TestClipPaintingContext extends PaintingContext {
} }
void expectOverflowedErrors() { void expectOverflowedErrors() {
final FlutterErrorDetails errorDetails = renderer.takeFlutterErrorDetails(); final FlutterErrorDetails errorDetails = renderer.takeFlutterErrorDetails()!;
final bool overflowed = errorDetails.toString().contains('overflowed'); final bool overflowed = errorDetails.toString().contains('overflowed');
if (!overflowed) { if (!overflowed) {
FlutterError.reportError(errorDetails); FlutterError.reportError(errorDetails);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -53,15 +51,15 @@ class MockRestorationManager extends TestRestorationManager { ...@@ -53,15 +51,15 @@ class MockRestorationManager extends TestRestorationManager {
int rootBucketAccessed = 0; int rootBucketAccessed = 0;
@override @override
Future<RestorationBucket> get rootBucket { Future<RestorationBucket?> get rootBucket {
rootBucketAccessed++; rootBucketAccessed++;
return _rootBucket; return _rootBucket;
} }
Future<RestorationBucket> _rootBucket; late Future<RestorationBucket?> _rootBucket;
set rootBucket(Future<RestorationBucket> value) { set rootBucket(Future<RestorationBucket?> value) {
_rootBucket = value; _rootBucket = value;
_isRestoring = true; _isRestoring = true;
ServicesBinding.instance.addPostFrameCallback((Duration _) { ServicesBinding.instance!.addPostFrameCallback((Duration _) {
_isRestoring = false; _isRestoring = false;
}); });
notifyListeners(); notifyListeners();
...@@ -69,7 +67,7 @@ class MockRestorationManager extends TestRestorationManager { ...@@ -69,7 +67,7 @@ class MockRestorationManager extends TestRestorationManager {
@override @override
bool get isReplacing => _isRestoring; bool get isReplacing => _isRestoring;
bool _isRestoring; bool _isRestoring = false;
@override @override
Future<void> sendToEngine(Uint8List encodedData) { Future<void> sendToEngine(Uint8List encodedData) {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -13,7 +11,7 @@ RenderEditable findRenderEditable(WidgetTester tester) { ...@@ -13,7 +11,7 @@ RenderEditable findRenderEditable(WidgetTester tester) {
final RenderObject root = tester.renderObject(find.byType(EditableText)); final RenderObject root = tester.renderObject(find.byType(EditableText));
expect(root, isNotNull); expect(root, isNotNull);
RenderEditable renderEditable; late RenderEditable renderEditable;
void recursiveFinder(RenderObject child) { void recursiveFinder(RenderObject child) {
if (child is RenderEditable) { if (child is RenderEditable) {
renderEditable = child; renderEditable = child;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
......
...@@ -2,49 +2,47 @@ ...@@ -2,49 +2,47 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
typedef OnObservation = void Function(Route<dynamic> route, Route<dynamic> previousRoute); typedef OnObservation = void Function(Route<dynamic>? route, Route<dynamic>? previousRoute);
/// A trivial observer for testing the navigator. /// A trivial observer for testing the navigator.
class TestObserver extends NavigatorObserver { class TestObserver extends NavigatorObserver {
OnObservation onPushed; OnObservation? onPushed;
OnObservation onPopped; OnObservation? onPopped;
OnObservation onRemoved; OnObservation? onRemoved;
OnObservation onReplaced; OnObservation? onReplaced;
OnObservation onStartUserGesture; OnObservation? onStartUserGesture;
@override @override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) { void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (onPushed != null) { if (onPushed != null) {
onPushed(route, previousRoute); onPushed!(route, previousRoute);
} }
} }
@override @override
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) { void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (onPopped != null) { if (onPopped != null) {
onPopped(route, previousRoute); onPopped!(route, previousRoute);
} }
} }
@override @override
void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) { void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (onRemoved != null) if (onRemoved != null)
onRemoved(route, previousRoute); onRemoved!(route, previousRoute);
} }
@override @override
void didReplace({ Route<dynamic> oldRoute, Route<dynamic> newRoute }) { void didReplace({ Route<dynamic>? oldRoute, Route<dynamic>? newRoute }) {
if (onReplaced != null) if (onReplaced != null)
onReplaced(newRoute, oldRoute); onReplaced!(newRoute, oldRoute);
} }
@override @override
void didStartUserGesture(Route<dynamic> route, Route<dynamic> previousRoute) { void didStartUserGesture(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (onStartUserGesture != null) if (onStartUserGesture != null)
onStartUserGesture(route, previousRoute); onStartUserGesture!(route, previousRoute);
} }
} }
...@@ -2,24 +2,22 @@ ...@@ -2,24 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
export '../services/restoration.dart'; export '../services/restoration.dart';
class BucketSpy extends StatefulWidget { class BucketSpy extends StatefulWidget {
const BucketSpy({Key key, this.child}) : super(key: key); const BucketSpy({Key? key, this.child}) : super(key: key);
final Widget child; final Widget? child;
@override @override
State<BucketSpy> createState() => BucketSpyState(); State<BucketSpy> createState() => BucketSpyState();
} }
class BucketSpyState extends State<BucketSpy> { class BucketSpyState extends State<BucketSpy> {
RestorationBucket bucket; RestorationBucket? bucket;
@override @override
void didChangeDependencies() { void didChangeDependencies() {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
const List<String> kStates = <String>[ const List<String> kStates = <String>[
'Alabama', 'Alabama',
'Alaska', 'Alaska',
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
typedef Logger = void Function(String caller); typedef Logger = void Function(String caller);
...@@ -20,19 +18,19 @@ class TestBorder extends ShapeBorder { ...@@ -20,19 +18,19 @@ class TestBorder extends ShapeBorder {
ShapeBorder scale(double t) => TestBorder(onLog); ShapeBorder scale(double t) => TestBorder(onLog);
@override @override
Path getInnerPath(Rect rect, { TextDirection textDirection }) { Path getInnerPath(Rect rect, { TextDirection? textDirection }) {
onLog('getInnerPath $rect $textDirection'); onLog('getInnerPath $rect $textDirection');
return Path(); return Path();
} }
@override @override
Path getOuterPath(Rect rect, { TextDirection textDirection }) { Path getOuterPath(Rect rect, { TextDirection? textDirection }) {
onLog('getOuterPath $rect $textDirection'); onLog('getOuterPath $rect $textDirection');
return Path(); return Path();
} }
@override @override
void paint(Canvas canvas, Rect rect, { TextDirection textDirection }) { void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) {
onLog('paint $rect $textDirection'); onLog('paint $rect $textDirection');
} }
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -21,7 +19,7 @@ const BoxDecoration kBoxDecorationC = BoxDecoration( ...@@ -21,7 +19,7 @@ const BoxDecoration kBoxDecorationC = BoxDecoration(
); );
class TestBuildCounter extends StatelessWidget { class TestBuildCounter extends StatelessWidget {
const TestBuildCounter({ Key key }) : super(key: key); const TestBuildCounter({ Key? key }) : super(key: key);
static int buildCount = 0; static int buildCount = 0;
...@@ -34,7 +32,7 @@ class TestBuildCounter extends StatelessWidget { ...@@ -34,7 +32,7 @@ class TestBuildCounter extends StatelessWidget {
class FlipWidget extends StatefulWidget { class FlipWidget extends StatefulWidget {
const FlipWidget({ Key key, this.left, this.right }) : super(key: key); const FlipWidget({ Key? key, required this.left, required this.right }) : super(key: key);
final Widget left; final Widget left;
final Widget right; final Widget right;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -14,7 +12,7 @@ RenderEditable findRenderEditable(WidgetTester tester) { ...@@ -14,7 +12,7 @@ RenderEditable findRenderEditable(WidgetTester tester) {
final RenderObject root = tester.renderObject(find.byType(EditableText)); final RenderObject root = tester.renderObject(find.byType(EditableText));
expect(root, isNotNull); expect(root, isNotNull);
RenderEditable renderEditable; late RenderEditable renderEditable;
void recursiveFinder(RenderObject child) { void recursiveFinder(RenderObject child) {
if (child is RenderEditable) { if (child is RenderEditable) {
renderEditable = child; renderEditable = child;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
...@@ -12,48 +10,46 @@ import 'package:flutter/material.dart'; ...@@ -12,48 +10,46 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
typedef InspectorServiceExtensionCallback = FutureOr<Map<String, Object>> Function(Map<String, String> parameters);
class TestWidgetInspectorService extends Object with WidgetInspectorService { class TestWidgetInspectorService extends Object with WidgetInspectorService {
final Map<String, InspectorServiceExtensionCallback> extensions = <String, InspectorServiceExtensionCallback>{}; final Map<String, ServiceExtensionCallback> extensions = <String, ServiceExtensionCallback>{};
final Map<String, List<Map<Object, Object>>> eventsDispatched = <String, List<Map<Object, Object>>>{}; final Map<String, List<Map<Object, Object?>>> eventsDispatched = <String, List<Map<Object, Object?>>>{};
@override @override
void registerServiceExtension({ void registerServiceExtension({
@required String name, required String name,
@required FutureOr<Map<String, Object>> callback(Map<String, String> parameters), required ServiceExtensionCallback callback,
}) { }) {
assert(!extensions.containsKey(name)); assert(!extensions.containsKey(name));
extensions[name] = callback; extensions[name] = callback;
} }
@override @override
void postEvent(String eventKind, Map<Object, Object> eventData) { void postEvent(String eventKind, Map<Object, Object?> eventData) {
getEventsDispatched(eventKind).add(eventData); getEventsDispatched(eventKind).add(eventData);
} }
List<Map<Object, Object>> getEventsDispatched(String eventKind) { List<Map<Object, Object?>> getEventsDispatched(String eventKind) {
return eventsDispatched.putIfAbsent(eventKind, () => <Map<Object, Object>>[]); return eventsDispatched.putIfAbsent(eventKind, () => <Map<Object, Object>>[]);
} }
Iterable<Map<Object, Object>> getServiceExtensionStateChangedEvents(String extensionName) { Iterable<Map<Object, Object?>> getServiceExtensionStateChangedEvents(String extensionName) {
return getEventsDispatched('Flutter.ServiceExtensionStateChanged') return getEventsDispatched('Flutter.ServiceExtensionStateChanged')
.where((Map<Object, Object> event) => event['extension'] == extensionName); .where((Map<Object, Object?> event) => event['extension'] == extensionName);
} }
Future<Object> testExtension(String name, Map<String, String> arguments) async { Future<Object?> testExtension(String name, Map<String, String> arguments) async {
expect(extensions, contains(name)); expect(extensions, contains(name));
// Encode and decode to JSON to match behavior using a real service // Encode and decode to JSON to match behavior using a real service
// extension where only JSON is allowed. // extension where only JSON is allowed.
return json.decode(json.encode(await extensions[name](arguments)))['result']; return json.decode(json.encode(await extensions[name]!(arguments)))['result'];
} }
Future<String> testBoolExtension(String name, Map<String, String> arguments) async { Future<String> testBoolExtension(String name, Map<String, String> arguments) async {
expect(extensions, contains(name)); expect(extensions, contains(name));
// Encode and decode to JSON to match behavior using a real service // Encode and decode to JSON to match behavior using a real service
// extension where only JSON is allowed. // extension where only JSON is allowed.
return json.decode(json.encode(await extensions[name](arguments)))['enabled'] as String; return json.decode(json.encode(await extensions[name]!(arguments)))['enabled'] as String;
} }
int rebuildCount = 0; int rebuildCount = 0;
...@@ -61,10 +57,10 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { ...@@ -61,10 +57,10 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
@override @override
Future<void> forceRebuild() async { Future<void> forceRebuild() async {
rebuildCount++; rebuildCount++;
final WidgetsBinding binding = WidgetsBinding.instance; final WidgetsBinding binding = WidgetsBinding.instance!;
if (binding.renderViewElement != null) { if (binding.renderViewElement != null) {
binding.buildOwner.reassemble(binding.renderViewElement); binding.buildOwner!.reassemble(binding.renderViewElement!);
} }
} }
} }
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