From 1c535de7e0714253c3d71ef8af07b1ea27e2e586 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 18 Oct 2019 16:40:42 -0700 Subject: [PATCH] Soften layer breakage (#42953) * Replace hard break of Layer.find/All with findAllAnnotations * Deprecate findAll --- .../lib/src/gestures/mouse_tracking.dart | 2 +- packages/flutter/lib/src/rendering/layer.dart | 90 ++++++++++---- packages/flutter/lib/src/rendering/view.dart | 8 +- .../test/rendering/annotated_region_test.dart | 78 ++++++------ .../rendering/layer_annotations_test.dart | 111 +++++++++--------- .../test/widgets/annotated_region_test.dart | 4 +- 6 files changed, 166 insertions(+), 127 deletions(-) diff --git a/packages/flutter/lib/src/gestures/mouse_tracking.dart b/packages/flutter/lib/src/gestures/mouse_tracking.dart index 2060cb312f..94cc5833e8 100644 --- a/packages/flutter/lib/src/gestures/mouse_tracking.dart +++ b/packages/flutter/lib/src/gestures/mouse_tracking.dart @@ -123,7 +123,7 @@ class MouseTracker extends ChangeNotifier { /// /// The second parameter is a function with which the [MouseTracker] can /// search for [MouseTrackerAnnotation]s at a given position. - /// Usually it is [Layer.findAll] of the root layer. + /// Usually it is [Layer.findAllAnnotations] of the root layer. /// /// All of the parameters must not be null. MouseTracker(this._router, this.annotationFinder) diff --git a/packages/flutter/lib/src/rendering/layer.dart b/packages/flutter/lib/src/rendering/layer.dart index 3314b7aea0..743e6f1cd4 100644 --- a/packages/flutter/lib/src/rendering/layer.dart +++ b/packages/flutter/lib/src/rendering/layer.dart @@ -18,8 +18,7 @@ import 'debug.dart'; /// /// See also: /// -/// * [Layer.find], [Layer.findAll], and [Layer.findAnnotations], which create -/// and use objects of this class. +/// * [Layer.findAnnotations], which create and use objects of this class. @immutable class AnnotationEntry { /// Create an entry of found annotation by providing the oject and related @@ -48,8 +47,8 @@ class AnnotationEntry { /// See also: /// /// * [AnnotationEntry], which are members of this class. -/// * [Layer.findAll], and [Layer.findAnnotations], which create and use an -/// object of this class. +/// * [Layer.findAllAnnotations], and [Layer.findAnnotations], which create and +/// use an object of this class. class AnnotationResult { final List> _entries = >[]; @@ -280,23 +279,28 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin { /// location described by `localPosition`. /// /// This method is called by the default implementation of [find] and - /// [findAll]. Override this method to customize how the layer should search - /// for annotations, or if the layer has its own annotations to add. + /// [findAllAnnotations]. Override this method to customize how the layer + /// should search for annotations, or if the layer has its own annotations to + /// add. + /// + /// The default implementation simply returns `false`, which means neither + /// the layer nor its children has annotations, and the annotation search + /// is not absorbed either (see below for explanation). /// /// ## About layer annotations /// /// {@template flutter.rendering.layer.findAnnotations.aboutAnnotations} - /// Annotation is an optional object of any type that can be carried with a + /// An annotation is an optional object of any type that can be carried with a /// layer. An annotation can be found at a location as long as the owner layer /// contains the location and is walked to. /// - /// The annotations are searched by first visitng each child recursively, then - /// this layer, resulting in an order from visually front to back. Annotations - /// must meet the given restrictions, such as type and position. + /// The annotations are searched by first visiting each child recursively, + /// then this layer, resulting in an order from visually front to back. + /// Annotations must meet the given restrictions, such as type and position. /// /// The common way for a value to be found here is by pushing an /// [AnnotatedRegionLayer] into the layer tree, or by adding the desired - /// annotation by overriding `findAnnotations`. + /// annotation by overriding [findAnnotations]. /// {@endtemplate} /// /// ## Parameters and return value @@ -326,7 +330,9 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin { AnnotationResult result, Offset localPosition, { @required bool onlyFirst, - }); + }) { + return false; + } /// Search this layer and its subtree for the first annotation of type `S` /// under the point described by `localPosition`. @@ -334,8 +340,10 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin { /// Returns null if no matching annotations are found. /// /// By default this method simply calls [findAnnotations] with `onlyFirst: - /// true` and returns the first result. It is encouraged to override - /// [findAnnotations] instead of this method. + /// true` and returns the annotation of the first result. Prefer overriding + /// [findAnnotations] instead of this method, because during an annotation + /// search, only [findAnnotations] is recursively called, while custom + /// behavior in this method is ignored. /// /// ## About layer annotations /// @@ -343,13 +351,13 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin { /// /// See also: /// - /// * [findAll], which is similar but returns all annotations found at the - /// given position. + /// * [findAllAnnotations], which is similar but returns all annotations found + /// at the given position. /// * [AnnotatedRegionLayer], for placing values in the layer tree. - AnnotationEntry find(Offset localPosition) { + S find(Offset localPosition) { final AnnotationResult result = AnnotationResult(); findAnnotations(result, localPosition, onlyFirst: true); - return result.entries.isEmpty ? null : result.entries.first; + return result.entries.isEmpty ? null : result.entries.first.annotation; } /// Search this layer and its subtree for all annotations of type `S` under @@ -358,8 +366,40 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin { /// Returns a result with empty entries if no matching annotations are found. /// /// By default this method simply calls [findAnnotations] with `onlyFirst: - /// false` and returns its result. It is encouraged to override - /// [findAnnotations] instead of this method. + /// false` and returns the annotations of its result. Prefer overriding + /// [findAnnotations] instead of this method, because during an annotation + /// search, only [findAnnotations] is recursively called, while custom + /// behavior in this method is ignored. + /// + /// ## About layer annotations + /// + /// {@macro flutter.rendering.layer.findAnnotations.aboutAnnotations} + /// + /// See also: + /// + /// * [find], which is similar but returns the first annotation found at the + /// given position. + /// * [findAllAnnotations], which is similar but returns an + /// [AnnotationResult], which contains more information, such as the local + /// position of the event related to each annotation, and is equally fast, + /// hence is preferred over [findAll]. + /// * [AnnotatedRegionLayer], for placing values in the layer tree. + @Deprecated('Use findAllAnnotations instead. This API will be removed in early 2020.') + Iterable findAll(Offset localPosition) { + final AnnotationResult result = findAllAnnotations(localPosition); + return result.entries.map((AnnotationEntry entry) => entry.annotation); + } + + /// Search this layer and its subtree for all annotations of type `S` under + /// the point described by `localPosition`. + /// + /// Returns a result with empty entries if no matching annotations are found. + /// + /// By default this method simply calls [findAnnotations] with `onlyFirst: + /// false` and returns the annotations of its result. Prefer overriding + /// [findAnnotations] instead of this method, because during an annotation + /// search, only [findAnnotations] is recursively called, while custom + /// behavior in this method is ignored. /// /// ## About layer annotations /// @@ -370,7 +410,7 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin { /// * [find], which is similar but returns the first annotation found at the /// given position. /// * [AnnotatedRegionLayer], for placing values in the layer tree. - AnnotationResult findAll(Offset localPosition) { + AnnotationResult findAllAnnotations(Offset localPosition) { final AnnotationResult result = AnnotationResult(); findAnnotations(result, localPosition, onlyFirst: false); return result; @@ -2247,10 +2287,10 @@ class FollowerLayer extends ContainerLayer { /// layer to the tree is the common way of adding an annotation. /// /// An annotation is an optional object of any type that, when attached with a -/// layer, can be retrieved using [Layer.find] or [Layer.findAll] with a -/// position. The search process is done recursively, controlled by a concept -/// of being opaque to a type of annotation, explained in the document of -/// [Layer.findAnnotations]. +/// layer, can be retrieved using [Layer.find] or [Layer.findAllAnnotations] +/// with a position. The search process is done recursively, controlled by a +/// concept of being opaque to a type of annotation, explained in the document +/// of [Layer.findAnnotations]. /// /// When an annotation search arrives, this layer defers the same search to each /// of this layer's children, respecting their opacity. Then it adds this diff --git a/packages/flutter/lib/src/rendering/view.dart b/packages/flutter/lib/src/rendering/view.dart index ed3d318a1f..be9b83847d 100644 --- a/packages/flutter/lib/src/rendering/view.dart +++ b/packages/flutter/lib/src/rendering/view.dart @@ -190,13 +190,13 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin /// /// See also: /// - /// * [Layer.findAll], which is used by this method to find all + /// * [Layer.findAllAnnotations], which is used by this method to find all /// [AnnotatedRegionLayer]s annotated for mouse tracking. Iterable hitTestMouseTrackers(Offset position) { // Layer hit testing is done using device pixels, so we have to convert // the logical coordinates of the event location back to device pixels // here. - return layer.findAll( + return layer.findAllAnnotations( position * configuration.devicePixelRatio ).annotations; } @@ -243,12 +243,12 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin final Rect bounds = paintBounds; final Offset top = Offset(bounds.center.dx, _window.padding.top / _window.devicePixelRatio); final Offset bottom = Offset(bounds.center.dx, bounds.center.dy - _window.padding.bottom / _window.devicePixelRatio); - final SystemUiOverlayStyle upperOverlayStyle = layer.find(top)?.annotation; + final SystemUiOverlayStyle upperOverlayStyle = layer.find(top); // Only android has a customizable system navigation bar. SystemUiOverlayStyle lowerOverlayStyle; switch (defaultTargetPlatform) { case TargetPlatform.android: - lowerOverlayStyle = layer.find(bottom)?.annotation; + lowerOverlayStyle = layer.find(bottom); break; case TargetPlatform.iOS: case TargetPlatform.fuchsia: diff --git a/packages/flutter/test/rendering/annotated_region_test.dart b/packages/flutter/test/rendering/annotated_region_test.dart index dc8a9102d8..30520daf3b 100644 --- a/packages/flutter/test/rendering/annotated_region_test.dart +++ b/packages/flutter/test/rendering/annotated_region_test.dart @@ -22,9 +22,9 @@ void main() { i += 1; } - expect(containerLayer.find(const Offset(0.0, 1.0)).annotation, 0); - expect(containerLayer.find(const Offset(0.0, 101.0)).annotation, 1); - expect(containerLayer.find(const Offset(0.0, 201.0)).annotation, 2); + expect(containerLayer.find(const Offset(0.0, 1.0)), 0); + expect(containerLayer.find(const Offset(0.0, 101.0)), 1); + expect(containerLayer.find(const Offset(0.0, 201.0)), 2); }); test('finds a value within the clip in a ClipRectLayer', () { @@ -41,9 +41,9 @@ void main() { i += 1; } - expect(containerLayer.find(const Offset(0.0, 1.0)).annotation, 0); - expect(containerLayer.find(const Offset(0.0, 101.0)).annotation, 1); - expect(containerLayer.find(const Offset(0.0, 201.0)).annotation, 2); + expect(containerLayer.find(const Offset(0.0, 1.0)), 0); + expect(containerLayer.find(const Offset(0.0, 101.0)), 1); + expect(containerLayer.find(const Offset(0.0, 201.0)), 2); }); @@ -61,9 +61,9 @@ void main() { i += 1; } - expect(containerLayer.find(const Offset(5.0, 5.0)).annotation, 0); - expect(containerLayer.find(const Offset(5.0, 105.0)).annotation, 1); - expect(containerLayer.find(const Offset(5.0, 205.0)).annotation, 2); + expect(containerLayer.find(const Offset(5.0, 5.0)), 0); + expect(containerLayer.find(const Offset(5.0, 105.0)), 1); + expect(containerLayer.find(const Offset(5.0, 205.0)), 2); }); test('finds a value under a TransformLayer', () { @@ -87,11 +87,11 @@ void main() { i += 1; } - expect(transformLayer.find(const Offset(0.0, 100.0)).annotation, 0); - expect(transformLayer.find(const Offset(0.0, 200.0)).annotation, 0); - expect(transformLayer.find(const Offset(0.0, 270.0)).annotation, 1); - expect(transformLayer.find(const Offset(0.0, 400.0)).annotation, 1); - expect(transformLayer.find(const Offset(0.0, 530.0)).annotation, 2); + expect(transformLayer.find(const Offset(0.0, 100.0)), 0); + expect(transformLayer.find(const Offset(0.0, 200.0)), 0); + expect(transformLayer.find(const Offset(0.0, 270.0)), 1); + expect(transformLayer.find(const Offset(0.0, 400.0)), 1); + expect(transformLayer.find(const Offset(0.0, 530.0)), 2); }); test('looks for child AnnotatedRegions before parents', () { @@ -101,7 +101,7 @@ void main() { parent.append(child); layer.append(parent); - expect(parent.find(Offset.zero).annotation, 2); + expect(parent.find(Offset.zero), 2); }); test('looks for correct type', () { @@ -111,7 +111,7 @@ void main() { layer.append(child2); layer.append(child1); - expect(layer.find(Offset.zero).annotation, 'hello'); + expect(layer.find(Offset.zero), 'hello'); }); test('does not clip Layer.find on an AnnotatedRegion with an unrelated type', () { @@ -121,7 +121,7 @@ void main() { parent.append(child); layer.append(parent); - expect(layer.find(const Offset(100.0, 100.0)).annotation, 1); + expect(layer.find(const Offset(100.0, 100.0)), 1); }); test('handles non-invertable transforms', () { @@ -133,10 +133,10 @@ void main() { parent.transform = Matrix4.diagonal3Values(1.0, 1.0, 1.0); - expect(parent.find(const Offset(0.0, 0.0)).annotation, 1); + expect(parent.find(const Offset(0.0, 0.0)), 1); }); }); - group('$AnnotatedRegion findAll', () { + group('$AnnotatedRegion findAllAnnotations', () { test('finds the first value in a OffsetLayer when sized', () { final ContainerLayer containerLayer = ContainerLayer(); final List layers = [ @@ -151,9 +151,9 @@ void main() { i += 1; } - expect(containerLayer.findAll(const Offset(0.0, 1.0)).annotations.toList(), equals([0])); - expect(containerLayer.findAll(const Offset(0.0, 101.0)).annotations.toList(), equals([1])); - expect(containerLayer.findAll(const Offset(0.0, 201.0)).annotations.toList(), equals([2])); + expect(containerLayer.findAllAnnotations(const Offset(0.0, 1.0)).annotations.toList(), equals([0])); + expect(containerLayer.findAllAnnotations(const Offset(0.0, 101.0)).annotations.toList(), equals([1])); + expect(containerLayer.findAllAnnotations(const Offset(0.0, 201.0)).annotations.toList(), equals([2])); }); test('finds a value within the clip in a ClipRectLayer', () { @@ -170,9 +170,9 @@ void main() { i += 1; } - expect(containerLayer.findAll(const Offset(0.0, 1.0)).annotations.toList(), equals([0])); - expect(containerLayer.findAll(const Offset(0.0, 101.0)).annotations.toList(), equals([1])); - expect(containerLayer.findAll(const Offset(0.0, 201.0)).annotations.toList(), equals([2])); + expect(containerLayer.findAllAnnotations(const Offset(0.0, 1.0)).annotations.toList(), equals([0])); + expect(containerLayer.findAllAnnotations(const Offset(0.0, 101.0)).annotations.toList(), equals([1])); + expect(containerLayer.findAllAnnotations(const Offset(0.0, 201.0)).annotations.toList(), equals([2])); }); @@ -190,9 +190,9 @@ void main() { i += 1; } - expect(containerLayer.findAll(const Offset(5.0, 5.0)).annotations.toList(), equals([0])); - expect(containerLayer.findAll(const Offset(5.0, 105.0)).annotations.toList(), equals([1])); - expect(containerLayer.findAll(const Offset(5.0, 205.0)).annotations.toList(), equals([2])); + expect(containerLayer.findAllAnnotations(const Offset(5.0, 5.0)).annotations.toList(), equals([0])); + expect(containerLayer.findAllAnnotations(const Offset(5.0, 105.0)).annotations.toList(), equals([1])); + expect(containerLayer.findAllAnnotations(const Offset(5.0, 205.0)).annotations.toList(), equals([2])); }); test('finds a value under a TransformLayer', () { @@ -216,11 +216,11 @@ void main() { i += 1; } - expect(transformLayer.findAll(const Offset(0.0, 100.0)).annotations.toList(), equals([0])); - expect(transformLayer.findAll(const Offset(0.0, 200.0)).annotations.toList(), equals([0])); - expect(transformLayer.findAll(const Offset(0.0, 270.0)).annotations.toList(), equals([1])); - expect(transformLayer.findAll(const Offset(0.0, 400.0)).annotations.toList(), equals([1])); - expect(transformLayer.findAll(const Offset(0.0, 530.0)).annotations.toList(), equals([2])); + expect(transformLayer.findAllAnnotations(const Offset(0.0, 100.0)).annotations.toList(), equals([0])); + expect(transformLayer.findAllAnnotations(const Offset(0.0, 200.0)).annotations.toList(), equals([0])); + expect(transformLayer.findAllAnnotations(const Offset(0.0, 270.0)).annotations.toList(), equals([1])); + expect(transformLayer.findAllAnnotations(const Offset(0.0, 400.0)).annotations.toList(), equals([1])); + expect(transformLayer.findAllAnnotations(const Offset(0.0, 530.0)).annotations.toList(), equals([2])); }); test('finds multiple nested, overlapping regions', () { @@ -237,7 +237,7 @@ void main() { parent.append(layer); } - expect(parent.findAll(const Offset(0.0, 0.0)).annotations.toList(), equals([3, 1, 2, 0,])); + expect(parent.findAllAnnotations(const Offset(0.0, 0.0)).annotations.toList(), equals([3, 1, 2, 0,])); }); test('looks for child AnnotatedRegions before parents', () { @@ -251,7 +251,7 @@ void main() { parent.append(child3); layer.append(parent); - expect(parent.findAll(Offset.zero).annotations.toList(), equals([4, 3, 2, 1])); + expect(parent.findAllAnnotations(Offset.zero).annotations.toList(), equals([4, 3, 2, 1])); }); test('looks for correct type', () { @@ -261,7 +261,7 @@ void main() { layer.append(child2); layer.append(child1); - expect(layer.findAll(Offset.zero).annotations.toList(), equals(['hello'])); + expect(layer.findAllAnnotations(Offset.zero).annotations.toList(), equals(['hello'])); }); test('does not clip Layer.find on an AnnotatedRegion with an unrelated type', () { @@ -271,7 +271,7 @@ void main() { parent.append(child); layer.append(parent); - expect(layer.findAll(const Offset(100.0, 100.0)).annotations.toList(), equals([1])); + expect(layer.findAllAnnotations(const Offset(100.0, 100.0)).annotations.toList(), equals([1])); }); test('handles non-invertable transforms', () { @@ -279,11 +279,11 @@ void main() { final TransformLayer parent = TransformLayer(transform: Matrix4.diagonal3Values(0.0, 1.0, 1.0)); parent.append(child); - expect(parent.findAll(const Offset(0.0, 0.0)).annotations.toList(), equals([])); + expect(parent.findAllAnnotations(const Offset(0.0, 0.0)).annotations.toList(), equals([])); parent.transform = Matrix4.diagonal3Values(1.0, 1.0, 1.0); - expect(parent.findAll(const Offset(0.0, 0.0)).annotations.toList(), equals([1])); + expect(parent.findAllAnnotations(const Offset(0.0, 0.0)).annotations.toList(), equals([1])); }); }); } diff --git a/packages/flutter/test/rendering/layer_annotations_test.dart b/packages/flutter/test/rendering/layer_annotations_test.dart index ef403f6cea..f7bf328b6e 100644 --- a/packages/flutter/test/rendering/layer_annotations_test.dart +++ b/packages/flutter/test/rendering/layer_annotations_test.dart @@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:vector_math/vector_math_64.dart'; void main() { - test('ContainerLayer.findAll returns all results from its children', () { + test('ContainerLayer.findAllAnnotations returns all results from its children', () { final Layer root = _Layers( ContainerLayer(), children: [ @@ -21,7 +21,7 @@ void main() { ).build(); expect( - root.findAll(Offset.zero).entries.toList(), + root.findAllAnnotations(Offset.zero).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 3, localPosition: Offset.zero), const AnnotationEntry(annotation: 2, localPosition: Offset.zero), @@ -40,12 +40,11 @@ void main() { ] ).build(); - final AnnotationEntry result = root.find(Offset.zero); - expect(result.annotation, 3); - expect(result.localPosition, Offset.zero); + final int result = root.find(Offset.zero); + expect(result, 3); }); - test('ContainerLayer.findAll returns empty result when finding nothing', () { + test('ContainerLayer.findAllAnnotations returns empty result when finding nothing', () { final Layer root = _Layers( ContainerLayer(), children: [ @@ -55,7 +54,7 @@ void main() { ] ).build(); - expect(root.findAll(Offset.zero).entries.isEmpty, isTrue); + expect(root.findAllAnnotations(Offset.zero).entries.isEmpty, isTrue); }); test('ContainerLayer.find returns null when finding nothing', () { @@ -71,7 +70,7 @@ void main() { expect(root.find(Offset.zero), isNull); }); - test('ContainerLayer.findAll stops at the first opaque child', () { + test('ContainerLayer.findAllAnnotations stops at the first opaque child', () { final Layer root = _Layers( ContainerLayer(), children: [ @@ -82,7 +81,7 @@ void main() { ).build(); expect( - root.findAll(Offset.zero).entries.toList(), + root.findAllAnnotations(Offset.zero).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 3, localPosition: Offset(0, 0)), const AnnotationEntry(annotation: 2, localPosition: Offset(0, 0)), @@ -90,7 +89,7 @@ void main() { ); }); - test('ContainerLayer.findAll returns children\'s opacity (true)', () { + test('ContainerLayer.findAllAnnotations returns children\'s opacity (true)', () { final Layer root = _appendAnnotationIfNotOpaque(1000, _Layers( ContainerLayer(), @@ -101,14 +100,14 @@ void main() { ); expect( - root.findAll(Offset.zero).entries.toList(), + root.findAllAnnotations(Offset.zero).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: Offset(0, 0)), ]), ); }); - test('ContainerLayer.findAll returns children\'s opacity (false)', () { + test('ContainerLayer.findAllAnnotations returns children\'s opacity (false)', () { final Layer root = _appendAnnotationIfNotOpaque(1000, _Layers( ContainerLayer(), @@ -119,7 +118,7 @@ void main() { ); expect( - root.findAll(Offset.zero).entries.toList(), + root.findAllAnnotations(Offset.zero).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: Offset(0, 0)), const AnnotationEntry(annotation: 1000, localPosition: Offset(0, 0)), @@ -127,7 +126,7 @@ void main() { ); }); - test('ContainerLayer.findAll returns false as opacity when finding nothing', () { + test('ContainerLayer.findAllAnnotations returns false as opacity when finding nothing', () { final Layer root = _appendAnnotationIfNotOpaque(1000, _Layers( ContainerLayer(), @@ -138,14 +137,14 @@ void main() { ); expect( - root.findAll(Offset.zero).entries.toList(), + root.findAllAnnotations(Offset.zero).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: Offset(0, 0)), ]), ); }); - test('OffsetLayer.findAll respects offset', () { + test('OffsetLayer.findAllAnnotations respects offset', () { const Offset insidePosition = Offset(-5, 5); const Offset outsidePosition = Offset(5, 5); @@ -159,20 +158,20 @@ void main() { ); expect( - root.findAll(insidePosition).entries.toList(), + root.findAllAnnotations(insidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1, localPosition: Offset(5, 5)), ]), ); expect( - root.findAll(outsidePosition).entries.toList(), + root.findAllAnnotations(outsidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: Offset(5, 5)), ]), ); }); - test('ClipRectLayer.findAll respects clipRect', () { + test('ClipRectLayer.findAllAnnotations respects clipRect', () { const Offset insidePosition = Offset(11, 11); const Offset outsidePosition = Offset(19, 19); @@ -191,20 +190,20 @@ void main() { ); expect( - root.findAll(insidePosition).entries.toList(), + root.findAllAnnotations(insidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1, localPosition: insidePosition), ]), ); expect( - root.findAll(outsidePosition).entries.toList(), + root.findAllAnnotations(outsidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: outsidePosition), ]), ); }); - test('ClipRRectLayer.findAll respects clipRRect', () { + test('ClipRRectLayer.findAllAnnotations respects clipRRect', () { // For a curve of radius 4 centered at (4, 4), // location (1, 1) is outside, while (2, 2) is inside. // Here we shift this RRect by (10, 10). @@ -230,20 +229,20 @@ void main() { ); expect( - root.findAll(insidePosition).entries.toList(), + root.findAllAnnotations(insidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1, localPosition: insidePosition), ]), ); expect( - root.findAll(outsidePosition).entries.toList(), + root.findAllAnnotations(outsidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: outsidePosition), ]), ); }); - test('ClipPathLayer.findAll respects clipPath', () { + test('ClipPathLayer.findAllAnnotations respects clipPath', () { // For this triangle, location (1, 1) is inside, while (2, 2) is outside. // 2 // ————— @@ -274,20 +273,20 @@ void main() { ); expect( - root.findAll(insidePosition).entries.toList(), + root.findAllAnnotations(insidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1, localPosition: insidePosition), ]), ); expect( - root.findAll(outsidePosition).entries.toList(), + root.findAllAnnotations(outsidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: outsidePosition), ]), ); }); - test('TransformLayer.findAll respects transform', () { + test('TransformLayer.findAllAnnotations respects transform', () { // Matrix `transform` enlarges the target by (2x, 4x), then shift it by // (10, 20). final Matrix4 transform = Matrix4.diagonal3Values(2, 4, 1) @@ -312,20 +311,20 @@ void main() { ); expect( - root.findAll(insidePosition).entries.toList(), + root.findAllAnnotations(insidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1, localPosition: Offset(15, 15)), ]), ); expect( - root.findAll(outsidePosition).entries.toList(), + root.findAllAnnotations(outsidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: outsidePosition), ]), ); }); - test('TransformLayer.findAll skips when transform is irreversible', () { + test('TransformLayer.findAllAnnotations skips when transform is irreversible', () { final Matrix4 transform = Matrix4.diagonal3Values(1, 0, 1); final Layer root = _appendAnnotationIfNotOpaque(1000, @@ -338,14 +337,14 @@ void main() { ); expect( - root.findAll(Offset.zero).entries.toList(), + root.findAllAnnotations(Offset.zero).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: Offset.zero), ]), ); }); - test('PhysicalModelLayer.findAll respects clipPath', () { + test('PhysicalModelLayer.findAllAnnotations respects clipPath', () { // For this triangle, location (1, 1) is inside, while (2, 2) is outside. // 2 // ————— @@ -381,13 +380,13 @@ void main() { ); expect( - root.findAll(insidePosition).entries.toList(), + root.findAllAnnotations(insidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1, localPosition: insidePosition), ]), ); expect( - root.findAll(outsidePosition).entries.toList(), + root.findAllAnnotations(outsidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: outsidePosition), ]), @@ -395,7 +394,7 @@ void main() { }); - test('LeaderLayer.findAll respects offset', () { + test('LeaderLayer.findAllAnnotations respects offset', () { const Offset insidePosition = Offset(-5, 5); const Offset outsidePosition = Offset(5, 5); @@ -412,20 +411,20 @@ void main() { ); expect( - root.findAll(insidePosition).entries.toList(), + root.findAllAnnotations(insidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1, localPosition: Offset(5, 5)), ]), ); expect( - root.findAll(outsidePosition).entries.toList(), + root.findAllAnnotations(outsidePosition).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 1000, localPosition: outsidePosition), ]), ); }); - test('AnnotatedRegionLayer.findAll should append to the list ' + test('AnnotatedRegionLayer.findAllAnnotations should append to the list ' 'and return the given opacity (false) during a successful hit', () { const Offset position = Offset(5, 5); @@ -439,7 +438,7 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), const AnnotationEntry(annotation: 1, localPosition: position), @@ -448,7 +447,7 @@ void main() { ); }); - test('AnnotatedRegionLayer.findAll should append to the list ' + test('AnnotatedRegionLayer.findAllAnnotations should append to the list ' 'and return the given opacity (true) during a successful hit', () { const Offset position = Offset(5, 5); @@ -462,7 +461,7 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), const AnnotationEntry(annotation: 1, localPosition: position), @@ -470,7 +469,7 @@ void main() { ); }); - test('AnnotatedRegionLayer.findAll has default opacity as false', () { + test('AnnotatedRegionLayer.findAllAnnotations has default opacity as false', () { const Offset position = Offset(5, 5); final Layer root = _appendAnnotationIfNotOpaque(1000, @@ -483,7 +482,7 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), const AnnotationEntry(annotation: 1, localPosition: position), @@ -492,7 +491,7 @@ void main() { ); }); - test('AnnotatedRegionLayer.findAll should still check children and return' + test('AnnotatedRegionLayer.findAllAnnotations should still check children and return' 'children\'s opacity (false) during a failed hit', () { const Offset position = Offset(5, 5); @@ -506,7 +505,7 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), const AnnotationEntry(annotation: 1000, localPosition: position), @@ -514,7 +513,7 @@ void main() { ); }); - test('AnnotatedRegionLayer.findAll should still check children and return' + test('AnnotatedRegionLayer.findAllAnnotations should still check children and return' 'children\'s opacity (true) during a failed hit', () { const Offset position = Offset(5, 5); @@ -528,14 +527,14 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), ]), ); }); - test('AnnotatedRegionLayer.findAll should not add to children\'s opacity ' + test('AnnotatedRegionLayer.findAllAnnotations should not add to children\'s opacity ' 'during a successful hit if it is not opaque', () { const Offset position = Offset(5, 5); @@ -549,7 +548,7 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), const AnnotationEntry(annotation: 1, localPosition: position), @@ -558,7 +557,7 @@ void main() { ); }); - test('AnnotatedRegionLayer.findAll should add to children\'s opacity ' + test('AnnotatedRegionLayer.findAllAnnotations should add to children\'s opacity ' 'during a successful hit if it is opaque', () { const Offset position = Offset(5, 5); @@ -572,7 +571,7 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), const AnnotationEntry(annotation: 1, localPosition: position), @@ -580,7 +579,7 @@ void main() { ); }); - test('AnnotatedRegionLayer.findAll should clip its annotation ' + test('AnnotatedRegionLayer.findAllAnnotations should clip its annotation ' 'using size and offset (positive)', () { // The target position would have fallen outside if not for the offset. const Offset position = Offset(100, 100); @@ -606,7 +605,7 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), const AnnotationEntry(annotation: 1, localPosition: position), @@ -615,7 +614,7 @@ void main() { ); }); - test('AnnotatedRegionLayer.findAll should clip its annotation ' + test('AnnotatedRegionLayer.findAllAnnotations should clip its annotation ' 'using size and offset (negative)', () { // The target position would have fallen inside if not for the offset. const Offset position = Offset(10, 10); @@ -634,7 +633,7 @@ void main() { ); expect( - root.findAll(position).entries.toList(), + root.findAllAnnotations(position).entries.toList(), _equalToAnnotationResult(>[ const AnnotationEntry(annotation: 2, localPosition: position), const AnnotationEntry(annotation: 1000, localPosition: position), diff --git a/packages/flutter/test/widgets/annotated_region_test.dart b/packages/flutter/test/widgets/annotated_region_test.dart index e4f5b66adc..7b37167b9c 100644 --- a/packages/flutter/test/widgets/annotated_region_test.dart +++ b/packages/flutter/test/widgets/annotated_region_test.dart @@ -34,12 +34,12 @@ void main() { int result = RendererBinding.instance.renderView.debugLayer.find(Offset( 10.0 * window.devicePixelRatio, 10.0 * window.devicePixelRatio, - ))?.annotation; + )); expect(result, null); result = RendererBinding.instance.renderView.debugLayer.find(Offset( 50.0 * window.devicePixelRatio, 50.0 * window.devicePixelRatio, - )).annotation; + )); expect(result, 1); }); }