diff --git a/examples/layers/rendering/src/sector_layout.dart b/examples/layers/rendering/src/sector_layout.dart index 87e5db8fa7..905cb52e40 100644 --- a/examples/layers/rendering/src/sector_layout.dart +++ b/examples/layers/rendering/src/sector_layout.dart @@ -520,6 +520,7 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil void performLayout() { if (child == null || (!constraints.hasBoundedWidth && !constraints.hasBoundedHeight)) { size = constraints.constrain(Size.zero); + child?.layout(SectorConstraints(maxDeltaRadius: innerRadius), parentUsesSize: true); return; } assert(child is RenderSector); diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart index 1d19aecdfa..49c709db9f 100644 --- a/packages/flutter/lib/src/cupertino/date_picker.dart +++ b/packages/flutter/lib/src/cupertino/date_picker.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:math' as math; + import 'package:flutter/scheduler.dart'; import 'package:flutter/widgets.dart'; @@ -66,14 +68,25 @@ class _DatePickerLayoutDelegate extends MultiChildLayoutDelegate { if (index == 0 || index == columnWidths.length - 1) childWidth += remainingWidth / 2; - assert( - childWidth >= 0, - 'Insufficient horizontal space to render the CupertinoDatePicker ' - 'because the parent is too narrow at ${size.width}px.\n' - 'An additional ${-remainingWidth}px is needed to avoid overlapping ' - 'columns.', - ); - layoutChild(index, BoxConstraints.tight(Size(childWidth, size.height))); + // We can't actually assert here because it would break things badly for + // semantics, which will expect that we laid things out here. + assert(() { + if (childWidth < 0) { + FlutterError.reportError( + FlutterErrorDetails( + exception: FlutterError( + 'Insufficient horizontal space to render the ' + 'CupertinoDatePicker because the parent is too narrow at ' + '${size.width}px.\n' + 'An additional ${-remainingWidth}px is needed to avoid ' + 'overlapping columns.', + ), + ), + ); + } + return true; + }()); + layoutChild(index, BoxConstraints.tight(Size(math.max(0.0, childWidth), size.height))); positionChild(index, Offset(currentHorizontalOffset, 0.0)); currentHorizontalOffset += childWidth; diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index dfc2e3f9b3..5c9f545873 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -3584,9 +3584,10 @@ class _SemanticsGeometry { } else { _semanticsClipRect = _intersectRects(_semanticsClipRect, parent.describeApproximatePaintClip(child)); } - _semanticsClipRect = _transformRect(_semanticsClipRect, parent, child); - _paintClipRect = _transformRect(_paintClipRect, parent, child); - parent.applyPaintTransform(child, _transform); + _temporaryTransformHolder.setIdentity(); // clears data from previous call(s) + _applyIntermediatePaintTransforms(parent, child, _transform, _temporaryTransformHolder); + _semanticsClipRect = _transformRect(_semanticsClipRect, _temporaryTransformHolder); + _paintClipRect = _transformRect(_paintClipRect, _temporaryTransformHolder); } final RenderObject owner = ancestors.first; @@ -3609,14 +3610,41 @@ class _SemanticsGeometry { static final Matrix4 _temporaryTransformHolder = Matrix4.zero(); /// From parent to child coordinate system. - static Rect _transformRect(Rect rect, RenderObject parent, RenderObject child) { + static Rect _transformRect(Rect rect, Matrix4 transform) { + assert(transform != null); if (rect == null) return null; if (rect.isEmpty) return Rect.zero; - _temporaryTransformHolder.setIdentity(); // clears data from a previous call - parent.applyPaintTransform(child, _temporaryTransformHolder); - return MatrixUtils.inverseTransformRect(_temporaryTransformHolder, rect); + return MatrixUtils.inverseTransformRect(transform, rect); + } + + // Calls applyPaintTransform on all of the render objects between [child] and + // [ancestor]. This method handles cases where the immediate semantic parent + // is not the immediate render object parent of the child. + // + // It will mutate both transform and clipRectTransform. + static void _applyIntermediatePaintTransforms( + RenderObject ancestor, + RenderObject child, + Matrix4 transform, + Matrix4 clipRectTransform, + ) { + assert(ancestor != null); + assert(child != null); + assert(transform != null); + assert(clipRectTransform != null); + assert(clipRectTransform.isIdentity()); + RenderObject intermediateParent = child.parent; + assert(intermediateParent != null); + while (intermediateParent != ancestor) { + intermediateParent.applyPaintTransform(child, transform); + intermediateParent = intermediateParent.parent; + child = child.parent; + assert(intermediateParent != null); + } + ancestor.applyPaintTransform(child, transform); + ancestor.applyPaintTransform(child, clipRectTransform); } static Rect _intersectRects(Rect a, Rect b) { diff --git a/packages/flutter/lib/src/rendering/stack.dart b/packages/flutter/lib/src/rendering/stack.dart index 5404395931..50991f50a4 100644 --- a/packages/flutter/lib/src/rendering/stack.dart +++ b/packages/flutter/lib/src/rendering/stack.dart @@ -639,7 +639,7 @@ class RenderIndexedStack extends RenderStack { @override void visitChildrenForSemantics(RenderObjectVisitor visitor) { - if (index != null) + if (index != null && firstChild != null) visitor(_childAtIndex()); } diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart index eb126097b8..ae90212038 100644 --- a/packages/flutter/test/cupertino/date_picker_test.dart +++ b/packages/flutter/test/cupertino/date_picker_test.dart @@ -815,7 +815,7 @@ void main() { ); final dynamic exception = tester.takeException(); - expect(exception, isAssertionError); + expect(exception, isFlutterError); expect( exception.toString(), contains('Insufficient horizontal space to render the CupertinoDatePicker'), diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index f52b479592..405182550d 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -2280,6 +2280,7 @@ void main() { ), ); await tester.pumpAndSettle(); + expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 16.0)); expect(tester.getSize(find.text('text')).height, 16.0); expect(tester.getTopLeft(find.text('text')).dy, 0.0); diff --git a/packages/flutter/test/material/progress_indicator_test.dart b/packages/flutter/test/material/progress_indicator_test.dart index 2c13adae8a..59702ddf55 100644 --- a/packages/flutter/test/material/progress_indicator_test.dart +++ b/packages/flutter/test/material/progress_indicator_test.dart @@ -278,12 +278,15 @@ void main() { double progressValue; StateSetter setState; await tester.pumpWidget( - Center( - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setter) { - setState = setter; - return CircularProgressIndicator(value: progressValue); - } + Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: StatefulBuilder( + builder: (BuildContext context, StateSetter setter) { + setState = setter; + return CircularProgressIndicator(value: progressValue); + } + ), ), ) ); diff --git a/packages/flutter/test/material/slider_test.dart b/packages/flutter/test/material/slider_test.dart index d7b30daa95..f3abb74e84 100644 --- a/packages/flutter/test/material/slider_test.dart +++ b/packages/flutter/test/material/slider_test.dart @@ -1260,7 +1260,7 @@ void main() { hasSemantics( TestSemantics.root(children: [ TestSemantics.rootChild( - id: 2, + id: 1, value: '50%', increasedValue: '60%', decreasedValue: '40%', @@ -1299,7 +1299,7 @@ void main() { hasSemantics( TestSemantics.root(children: [ TestSemantics.rootChild( - id: 3, + id: 1, value: '40', increasedValue: '60', decreasedValue: '20', diff --git a/packages/flutter/test/widgets/custom_painter_test.dart b/packages/flutter/test/widgets/custom_painter_test.dart index eed74c3368..a23cfaad59 100644 --- a/packages/flutter/test/widgets/custom_painter_test.dart +++ b/packages/flutter/test/widgets/custom_painter_test.dart @@ -315,7 +315,7 @@ void _defineTests() { expect(tester.binding.pipelineOwner.semanticsOwner, isNotNull); semantics.dispose(); - }); + }, semanticsEnabled: false); testWidgets('Supports all actions', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); diff --git a/packages/flutter/test/widgets/fade_in_image_test.dart b/packages/flutter/test/widgets/fade_in_image_test.dart index b935bbc099..88d8d220d4 100644 --- a/packages/flutter/test/widgets/fade_in_image_test.dart +++ b/packages/flutter/test/widgets/fade_in_image_test.dart @@ -297,12 +297,15 @@ Future main() async { final TestImageProvider placeholderProvider = TestImageProvider(placeholderImage); final TestImageProvider imageProvider = TestImageProvider(targetImage); - await tester.pumpWidget(FadeInImage( - placeholder: placeholderProvider, - image: imageProvider, - fadeOutDuration: animationDuration, - fadeInDuration: animationDuration, - imageSemanticLabel: imageSemanticText, + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: FadeInImage( + placeholder: placeholderProvider, + image: imageProvider, + fadeOutDuration: animationDuration, + fadeInDuration: animationDuration, + imageSemanticLabel: imageSemanticText, + ), )); placeholderProvider.complete(); diff --git a/packages/flutter/test/widgets/implicit_semantics_test.dart b/packages/flutter/test/widgets/implicit_semantics_test.dart index ae4ff10f24..a08a889f0b 100644 --- a/packages/flutter/test/widgets/implicit_semantics_test.dart +++ b/packages/flutter/test/widgets/implicit_semantics_test.dart @@ -217,30 +217,30 @@ void main() { ); // SemanticsNode#0() - // └SemanticsNode#8() - // ├SemanticsNode#5(selected, label: "node 1", textDirection: ltr) - // ├SemanticsNode#6(selected, label: "node 2", textDirection: ltr) - // └SemanticsNode#7(selected, label: "node 3", textDirection: ltr) + // └SemanticsNode#1() + // ├SemanticsNode#2(selected, label: "node 1", textDirection: ltr) + // ├SemanticsNode#3(selected, label: "node 2", textDirection: ltr) + // └SemanticsNode#4(selected, label: "node 3", textDirection: ltr) expect( semantics, hasSemantics( TestSemantics.root( children: [ TestSemantics.rootChild( - id: 5, + id: 1, children: [ TestSemantics( - id: 6, + id: 2, flags: SemanticsFlag.isSelected.index, label: 'node 1', ), TestSemantics( - id: 7, + id: 3, flags: SemanticsFlag.isSelected.index, label: 'node 2', ), TestSemantics( - id: 8, + id: 4, flags: SemanticsFlag.isSelected.index, label: 'node 3', ), diff --git a/packages/flutter/test/widgets/keep_alive_test.dart b/packages/flutter/test/widgets/keep_alive_test.dart index 2d22837c0e..36f25de153 100644 --- a/packages/flutter/test/widgets/keep_alive_test.dart +++ b/packages/flutter/test/widgets/keep_alive_test.dart @@ -238,6 +238,7 @@ void main() { ' │ needs compositing\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ semantics node: SemanticsNode#1\n' ' │ semantic boundary\n' ' │ size: Size(800.0, 600.0)\n' ' │\n' @@ -384,6 +385,7 @@ void main() { ' │ needs compositing\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ semantics node: SemanticsNode#1\n' ' │ semantic boundary\n' ' │ size: Size(800.0, 600.0)\n' ' │\n' diff --git a/packages/flutter/test/widgets/scrollable_semantics_test.dart b/packages/flutter/test/widgets/scrollable_semantics_test.dart index 52088690d6..c5e61d709d 100644 --- a/packages/flutter/test/widgets/scrollable_semantics_test.dart +++ b/packages/flutter/test/widgets/scrollable_semantics_test.dart @@ -406,7 +406,7 @@ void main() { expect(semantics, hasSemantics(expectedSemantics, ignoreId: true, ignoreRect: true, ignoreTransform: true)); semantics.dispose(); - }); + }, semanticsEnabled: false); group('showOnScreen', () { diff --git a/packages/flutter/test/widgets/semantics_test.dart b/packages/flutter/test/widgets/semantics_test.dart index 7385f21904..b967692cbc 100644 --- a/packages/flutter/test/widgets/semantics_test.dart +++ b/packages/flutter/test/widgets/semantics_test.dart @@ -62,7 +62,7 @@ void main() { ignoreId: true, )); semantics.dispose(); - }); + }, semanticsEnabled: false); testWidgets('Detach and reattach assert', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); diff --git a/packages/flutter/test/widgets/simple_semantics_test.dart b/packages/flutter/test/widgets/simple_semantics_test.dart index ba2a32ddc5..076385e35e 100644 --- a/packages/flutter/test/widgets/simple_semantics_test.dart +++ b/packages/flutter/test/widgets/simple_semantics_test.dart @@ -55,16 +55,16 @@ void main() { expect(semantics, hasSemantics(TestSemantics.root( children: [ TestSemantics.rootChild( - id: 2, + id: 1, rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0), children: [ TestSemantics( - id: 3, + id: 2, rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0), flags: [SemanticsFlag.scopesRoute], children: [ TestSemantics( - id: 4, + id: 3, label: 'Hello!', textDirection: TextDirection.ltr, rect: const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0), diff --git a/packages/flutter/test/widgets/sliver_fill_viewport_test.dart b/packages/flutter/test/widgets/sliver_fill_viewport_test.dart index e5b60dd623..0a6683b7c1 100644 --- a/packages/flutter/test/widgets/sliver_fill_viewport_test.dart +++ b/packages/flutter/test/widgets/sliver_fill_viewport_test.dart @@ -91,6 +91,7 @@ void main() { ' │ └─child: RenderParagraph#00000\n' ' │ │ parentData: (can use size)\n' ' │ │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ │ semantics node: SemanticsNode#2\n' ' │ │ size: Size(800.0, 600.0)\n' ' │ │ textAlign: start\n' ' │ │ textDirection: ltr\n' @@ -115,6 +116,7 @@ void main() { ' └─child: RenderParagraph#00000\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ semantics node: SemanticsNode#3\n' ' │ size: Size(800.0, 600.0)\n' ' │ textAlign: start\n' ' │ textDirection: ltr\n' @@ -126,6 +128,7 @@ void main() { ' ║ \n' ' ║ "1"\n' ' ╚═══════════\n' + '' ), ); }); diff --git a/packages/flutter_driver/test/src/extension_test.dart b/packages/flutter_driver/test/src/extension_test.dart index d1f12f5d26..ad926d0cdb 100644 --- a/packages/flutter_driver/test/src/extension_test.dart +++ b/packages/flutter_driver/test/src/extension_test.dart @@ -103,7 +103,7 @@ void main() { expect(response['isError'], true); expect(response['response'], contains('Bad state: No semantics data found')); - }); + }, semanticsEnabled: false); testWidgets('throws state error multiple matches are found', (WidgetTester tester) async { final SemanticsHandle semantics = RendererBinding.instance.pipelineOwner.ensureSemantics(); diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index c7e88a3284..5b9fdb1073 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -71,7 +71,7 @@ typedef WidgetTesterCallback = Future Function(WidgetTester widgetTester); /// If the `semanticsEnabled` parameter is set to `true`, /// [WidgetTester.ensureSemantics] will have been called before the tester is /// passed to the `callback`, and that handle will automatically be disposed -/// after the callback is finished. +/// after the callback is finished. It defaults to true. /// /// This function uses the [test] function in the test package to /// register the given callback as a test. The callback, when run, @@ -100,7 +100,7 @@ void testWidgets( bool skip = false, test_package.Timeout timeout, Duration initialTimeout, - bool semanticsEnabled = false, + bool semanticsEnabled = true, }) { final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); final WidgetTester tester = WidgetTester._(binding); @@ -115,6 +115,7 @@ void testWidgets( test_package.addTearDown(binding.postTest); return binding.runTest( () async { + debugResetSemanticsIdCounter(); await callback(tester); semanticsHandle?.dispose(); }, diff --git a/packages/flutter_test/test/accessibility_test.dart b/packages/flutter_test/test/accessibility_test.dart index 9183f55f40..d8618a9a03 100644 --- a/packages/flutter_test/test/accessibility_test.dart +++ b/packages/flutter_test/test/accessibility_test.dart @@ -123,7 +123,7 @@ void main() { final Evaluation result = await textContrastGuideline.evaluate(tester); expect(result.passed, false); expect(result.reason, - 'SemanticsNode#21(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), label: "this is a test",' + 'SemanticsNode#3(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), label: "this is a test",' ' textDirection: ltr):\nExpected contrast ratio of at least ' '4.5 but found 1.17 for a font size of 14.0. The ' 'computed light color was: Color(0xfffafafa), The computed dark color was:' @@ -256,7 +256,7 @@ void main() { final Evaluation result = await androidTapTargetGuideline.evaluate(tester); expect(result.passed, false); expect(result.reason, - 'SemanticsNode#41(Rect.fromLTRB(376.0, 276.5, 424.0, 323.5), actions: [tap]): expected tap ' + 'SemanticsNode#3(Rect.fromLTRB(376.0, 276.5, 424.0, 323.5), actions: [tap]): expected tap ' 'target size of at least Size(48.0, 48.0), but found Size(48.0, 47.0)\n' 'See also: https://support.google.com/accessibility/android/answer/7101858?hl=en'); handle.dispose(); diff --git a/packages/flutter_test/test/finders_test.dart b/packages/flutter_test/test/finders_test.dart index 6615983058..afed4cf63e 100644 --- a/packages/flutter_test/test/finders_test.dart +++ b/packages/flutter_test/test/finders_test.dart @@ -33,7 +33,7 @@ void main() { group('semantics', () { testWidgets('Throws StateError if semantics are not enabled', (WidgetTester tester) async { expect(() => find.bySemanticsLabel('Add'), throwsStateError); - }); + }, semanticsEnabled: false); testWidgets('finds Semantically labeled widgets', (WidgetTester tester) async { final SemanticsHandle semanticsHandle = tester.ensureSemantics(); diff --git a/packages/flutter_test/test/widget_tester_test.dart b/packages/flutter_test/test/widget_tester_test.dart index 0d5420389d..7d8277c7ab 100644 --- a/packages/flutter_test/test/widget_tester_test.dart +++ b/packages/flutter_test/test/widget_tester_test.dart @@ -542,7 +542,7 @@ void main() { expect(() => tester.getSemantics(find.text('hello')), throwsA(isInstanceOf())); - }); + }, semanticsEnabled: false); testWidgets('throws when there are multiple results from the finder', (WidgetTester tester) async { final SemanticsHandle semanticsHandle = tester.ensureSemantics();