From 4a53fbd08b118b26cb90d928a16a5f0ad0fac6f8 Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Thu, 30 Nov 2023 20:23:02 +0330 Subject: [PATCH] Format --- .../test/rendering/rendering_tools.dart | 107 +++++++++++------- 1 file changed, 67 insertions(+), 40 deletions(-) diff --git a/packages/fleather/test/rendering/rendering_tools.dart b/packages/fleather/test/rendering/rendering_tools.dart index daeff7ef..1586f238 100644 --- a/packages/fleather/test/rendering/rendering_tools.dart +++ b/packages/fleather/test/rendering/rendering_tools.dart @@ -10,12 +10,22 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart' show EnginePhase, TestDefaultBinaryMessengerBinding, fail; +import 'package:flutter_test/flutter_test.dart' + show EnginePhase, TestDefaultBinaryMessengerBinding, fail; export 'package:flutter/foundation.dart' show FlutterError, FlutterErrorDetails; -export 'package:flutter_test/flutter_test.dart' show EnginePhase, TestDefaultBinaryMessengerBinding; - -class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, ServicesBinding, GestureBinding, PaintingBinding, SemanticsBinding, RendererBinding, TestDefaultBinaryMessengerBinding { +export 'package:flutter_test/flutter_test.dart' + show EnginePhase, TestDefaultBinaryMessengerBinding; + +class TestRenderingFlutterBinding extends BindingBase + with + SchedulerBinding, + ServicesBinding, + GestureBinding, + PaintingBinding, + SemanticsBinding, + RendererBinding, + TestDefaultBinaryMessengerBinding { /// Creates a binding for testing rendering library functionality. /// /// If [onErrors] is not null, it is called if [FlutterError] caught any errors @@ -25,10 +35,11 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser /// /// Errors caught between frames will cause the test to fail unless /// [FlutterError.onError] has been overridden. - TestRenderingFlutterBinding({ this.onErrors }) { + TestRenderingFlutterBinding({this.onErrors}) { FlutterError.onError = (FlutterErrorDetails details) { FlutterError.dumpErrorToConsole(details); - Zone.current.parent!.handleUncaughtError(details.exception, details.stack!); + Zone.current.parent! + .handleUncaughtError(details.exception, details.stack!); }; } @@ -37,7 +48,8 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser /// Provides access to the features exposed by this binding. The binding must /// be initialized before using this getter; this is typically done by calling /// [TestRenderingFlutterBinding.ensureInitialized]. - static TestRenderingFlutterBinding get instance => BindingBase.checkInstance(_instance); + static TestRenderingFlutterBinding get instance => + BindingBase.checkInstance(_instance); static TestRenderingFlutterBinding? _instance; @override @@ -87,7 +99,8 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser /// Creates and initializes the binding. This function is /// idempotent; calling it a second time will just return the /// previously-created instance. - static TestRenderingFlutterBinding ensureInitialized({ VoidCallback? onErrors }) { + static TestRenderingFlutterBinding ensureInitialized( + {VoidCallback? onErrors}) { if (_instance != null) { return _instance!; } @@ -162,11 +175,13 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser onErrors!(); if (_errors.isNotEmpty) { _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.'); } } else { _errors.forEach(FlutterError.dumpErrorToConsole); - fail('Caught error while rendering frame. See preceding logs for details.'); + fail( + 'Caught error while rendering frame. See preceding logs for details.'); } } } @@ -174,7 +189,8 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser @override 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; FlutterError.onError = _errors.add; try { @@ -200,7 +216,8 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser if (phase == EnginePhase.flushSemantics) { return; } - assert(phase == EnginePhase.flushSemantics || phase == EnginePhase.sendSemanticsUpdate); + assert(phase == EnginePhase.flushSemantics || + phase == EnginePhase.sendSemanticsUpdate); } finally { FlutterError.onError = oldErrorHandler; if (_errors.isNotEmpty) { @@ -208,11 +225,13 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser onErrors!(); if (_errors.isNotEmpty) { _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.'); } } else { _errors.forEach(FlutterError.dumpErrorToConsole); - fail('Caught error while rendering frame. See preceding logs for details.'); + fail( + 'Caught error while rendering frame. See preceding logs for details.'); } } } @@ -234,13 +253,15 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser /// /// If `onErrors` is not null, it is set as [TestRenderingFlutterBinding.onError]. void layout( - RenderBox box, { // If you want to just repump the last box, call pumpFrame(). + RenderBox box, { + // If you want to just repump the last box, call pumpFrame(). BoxConstraints? constraints, Alignment alignment = Alignment.center, EnginePhase phase = EnginePhase.layout, VoidCallback? onErrors, }) { - 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. TestRenderingFlutterBinding.instance.renderView.child = null; if (constraints != null) { @@ -260,8 +281,10 @@ void layout( /// Pumps a single frame. /// /// If `onErrors` is not null, it is set as [TestRenderingFlutterBinding.onError]. -void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback? onErrors }) { - assert(TestRenderingFlutterBinding.instance.renderView.child != null); // call layout() first! +void pumpFrame( + {EnginePhase phase = EnginePhase.layout, VoidCallback? onErrors}) { + assert(TestRenderingFlutterBinding.instance.renderView.child != + null); // call layout() first! if (onErrors != null) { TestRenderingFlutterBinding.instance.onErrors = onErrors; @@ -272,7 +295,7 @@ void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback? onErrors } class TestCallbackPainter extends CustomPainter { - const TestCallbackPainter({ required this.onPaint }); + const TestCallbackPainter({required this.onPaint}); final VoidCallback onPaint; @@ -319,7 +342,7 @@ class RenderSizedBox extends RenderBox { } @override - void performLayout() { } + void performLayout() {} @override bool hitTestSelf(Offset position) => true; @@ -327,7 +350,7 @@ class RenderSizedBox extends RenderBox { class FakeTickerProvider implements TickerProvider { @override - Ticker createTicker(TickerCallback onTick, [ bool disableAnimations = false ]) { + Ticker createTicker(TickerCallback onTick, [bool disableAnimations = false]) { return FakeTicker(); } } @@ -337,7 +360,7 @@ class FakeTicker implements Ticker { bool muted = false; @override - void absorbTicker(Ticker originalTicker) { } + void absorbTicker(Ticker originalTicker) {} @override String? get debugLabel => null; @@ -355,10 +378,10 @@ class FakeTicker implements Ticker { bool get shouldScheduleTick => throw UnimplementedError(); @override - void dispose() { } + void dispose() {} @override - void scheduleTick({ bool rescheduling = false }) { } + void scheduleTick({bool rescheduling = false}) {} @override TickerFuture start() { @@ -366,24 +389,26 @@ class FakeTicker implements Ticker { } @override - void stop({ bool canceled = false }) { } + void stop({bool canceled = false}) {} @override - void unscheduleTick() { } + void unscheduleTick() {} @override - String toString({ bool debugIncludeStack = false }) => super.toString(); + String toString({bool debugIncludeStack = false}) => super.toString(); @override DiagnosticsNode describeForError(String name) { - return DiagnosticsProperty(name, this, style: DiagnosticsTreeStyle.errorProperty); + return DiagnosticsProperty(name, this, + style: DiagnosticsTreeStyle.errorProperty); } } class TestClipPaintingContext extends PaintingContext { TestClipPaintingContext() : this._(ContainerLayer()); - TestClipPaintingContext._(this._containerLayer) : super(_containerLayer, Rect.zero); + TestClipPaintingContext._(this._containerLayer) + : super(_containerLayer, Rect.zero); final ContainerLayer _containerLayer; @@ -415,20 +440,20 @@ class TestPushLayerPaintingContext extends PaintingContext { @override void pushLayer( - ContainerLayer childLayer, - PaintingContextCallback painter, - Offset offset, { - Rect? childPaintBounds - }) { + ContainerLayer childLayer, PaintingContextCallback painter, Offset offset, + {Rect? childPaintBounds}) { pushedLayers.add(childLayer); - super.pushLayer(childLayer, painter, offset, childPaintBounds: childPaintBounds); + super.pushLayer(childLayer, painter, offset, + childPaintBounds: childPaintBounds); } } // Absorbs errors that don't have "overflowed" in their error details. void absorbOverflowedErrors() { - final Iterable errorDetails = TestRenderingFlutterBinding.instance.takeAllFlutterErrorDetails(); - final Iterable filtered = errorDetails.where((FlutterErrorDetails details) { + final Iterable errorDetails = + TestRenderingFlutterBinding.instance.takeAllFlutterErrorDetails(); + final Iterable filtered = + errorDetails.where((FlutterErrorDetails details) { return !details.toString().contains('overflowed'); }); if (filtered.isNotEmpty) { @@ -438,9 +463,11 @@ void absorbOverflowedErrors() { // Reports any FlutterErrors. void expectNoFlutterErrors() { - final Iterable errorDetails = TestRenderingFlutterBinding.instance.takeAllFlutterErrorDetails(); + final Iterable errorDetails = + TestRenderingFlutterBinding.instance.takeAllFlutterErrorDetails(); errorDetails.forEach(FlutterError.reportError); } -RenderConstrainedBox get box200x200 => - RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(height: 200.0, width: 200.0)); \ No newline at end of file +RenderConstrainedBox get box200x200 => RenderConstrainedBox( + additionalConstraints: + const BoxConstraints.tightFor(height: 200.0, width: 200.0));