File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -923,7 +923,8 @@ class _DescendantFinder extends Finder {
923
923
924
924
@override
925
925
Iterable <Element > apply (Iterable <Element > candidates) {
926
- return candidates.where ((Element element) => descendant.evaluate ().contains (element));
926
+ final Iterable <Element > descendants = descendant.evaluate ();
927
+ return candidates.where ((Element element) => descendants.contains (element));
927
928
}
928
929
929
930
@override
@@ -956,7 +957,8 @@ class _AncestorFinder extends Finder {
956
957
957
958
@override
958
959
Iterable <Element > apply (Iterable <Element > candidates) {
959
- return candidates.where ((Element element) => ancestor.evaluate ().contains (element));
960
+ final Iterable <Element > ancestors = ancestor.evaluate ();
961
+ return candidates.where ((Element element) => ancestors.contains (element));
960
962
}
961
963
962
964
@override
Original file line number Diff line number Diff line change @@ -361,6 +361,30 @@ void main() {
361
361
matchRoot: true ,
362
362
), findsOneWidget);
363
363
});
364
+
365
+ testWidgets ('is fast in deep tree' , (WidgetTester tester) async {
366
+ await tester.pumpWidget (
367
+ Directionality (
368
+ textDirection: TextDirection .ltr,
369
+ child: _deepWidgetTree (
370
+ depth: 1000 ,
371
+ child: Row (
372
+ children: < Widget > [
373
+ _deepWidgetTree (
374
+ depth: 1000 ,
375
+ child: Column (children: fooBarTexts),
376
+ ),
377
+ ],
378
+ ),
379
+ ),
380
+ ),
381
+ );
382
+
383
+ expect (find.ancestor (
384
+ of: find.text ('bar' ),
385
+ matching: find.byType (Row ),
386
+ ), findsOneWidget);
387
+ });
364
388
});
365
389
366
390
group ('pageBack' , () {
@@ -854,3 +878,12 @@ class _AlwaysRepaint extends CustomPainter {
854
878
onPaint ();
855
879
}
856
880
}
881
+
882
+ /// Wraps [child] in [depth] layers of [SizedBox]
883
+ Widget _deepWidgetTree ({required int depth, required Widget child}) {
884
+ Widget tree = child;
885
+ for (int i = 0 ; i < depth; i += 1 ) {
886
+ tree = SizedBox (child: tree);
887
+ }
888
+ return tree;
889
+ }
You can’t perform that action at this time.
0 commit comments