evaluate method

  1. @override
Future<Evaluation> evaluate(
  1. WidgetTester tester
)
override

Evaluate whether the current state of the tester conforms to the rule.

Implementation

@override
Future<Evaluation> evaluate(WidgetTester tester) async {
  // Compute elements to be evaluated.
  final List<Element> elements = finder.evaluate().toList();
  final Map<FlutterView, ui.Image> images = <FlutterView, ui.Image>{};
  final Map<FlutterView, ByteData> byteDatas = <FlutterView, ByteData>{};

  // Collate all evaluations into a final evaluation, then return.
  Evaluation result = const Evaluation.pass();
  for (final Element element in elements) {
    final FlutterView view = tester.viewOf(find.byElementPredicate((Element e) => e == element));
    final RenderView renderView = tester.binding.renderViews.firstWhere((RenderView r) => r.flutterView == view);
    final OffsetLayer layer = renderView.debugLayer! as OffsetLayer;

    late final ui.Image image;
    late final ByteData byteData;

    // Obtain a previously rendered image or render one for a new view.
    await tester.binding.runAsync(() async {
      image = images[view] ??= await layer.toImage(
        renderView.paintBounds,
        // Needs to be the same pixel ratio otherwise our dimensions
        // won't match the last transform layer.
        pixelRatio: 1 / view.devicePixelRatio,
      );
      byteData = byteDatas[view] ??= (await image.toByteData())!;
    });

    result = result + _evaluateElement(element, byteData, image);
  }

  return result;
}