diff --git a/packages/flutter/lib/src/rendering/stack.dart b/packages/flutter/lib/src/rendering/stack.dart index b9da094301..861423d16f 100644 --- a/packages/flutter/lib/src/rendering/stack.dart +++ b/packages/flutter/lib/src/rendering/stack.dart @@ -714,6 +714,8 @@ class RenderIndexedStack extends RenderStack { super.children, super.alignment, super.textDirection, + super.fit, + super.clipBehavior, int? index = 0, }) : _index = index; diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index d0205aa7e7..1b60f1d40d 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -3943,6 +3943,7 @@ class IndexedStack extends Stack { super.key, super.alignment, super.textDirection, + super.clipBehavior, StackFit sizing = StackFit.loose, this.index = 0, super.children, @@ -3956,6 +3957,8 @@ class IndexedStack extends Stack { assert(_debugCheckHasDirectionality(context)); return RenderIndexedStack( index: index, + fit:fit, + clipBehavior: clipBehavior, alignment: alignment, textDirection: textDirection ?? Directionality.maybeOf(context), ); @@ -3966,6 +3969,8 @@ class IndexedStack extends Stack { assert(_debugCheckHasDirectionality(context)); renderObject ..index = index + ..fit = fit + ..clipBehavior = clipBehavior ..alignment = alignment ..textDirection = textDirection ?? Directionality.maybeOf(context); } diff --git a/packages/flutter/test/widgets/stack_test.dart b/packages/flutter/test/widgets/stack_test.dart index cfae51756b..ea5c4909f4 100644 --- a/packages/flutter/test/widgets/stack_test.dart +++ b/packages/flutter/test/widgets/stack_test.dart @@ -799,4 +799,64 @@ void main() { "'alignment', or an explicit 'textDirection', to the Stack.", ); }); + + testWidgets('Can update clipBehavior of IndexedStack', + (WidgetTester tester) async { + await tester.pumpWidget(IndexedStack(textDirection: TextDirection.ltr)); + final RenderIndexedStack renderObject = + tester.renderObject(find.byType(IndexedStack)); + expect(renderObject.clipBehavior, equals(Clip.hardEdge)); + + // Update clipBehavior to Clip.antiAlias + + await tester.pumpWidget(IndexedStack( + textDirection: TextDirection.ltr, + clipBehavior: Clip.antiAlias, + )); + final RenderIndexedStack renderIndexedObject = + tester.renderObject(find.byType(IndexedStack)); + expect(renderIndexedObject.clipBehavior, equals(Clip.antiAlias)); + }); + + testWidgets('IndexedStack sizing: explicit', (WidgetTester tester) async { + final List logs = []; + Widget buildIndexedStack(StackFit sizing) { + return Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: ConstrainedBox( + constraints: const BoxConstraints( + minWidth: 2.0, + maxWidth: 3.0, + minHeight: 5.0, + maxHeight: 7.0, + ), + child: IndexedStack( + sizing: sizing, + children: [ + LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + logs.add(constraints.toString()); + return const Placeholder(); + }, + ), + ], + ), + ), + ), + ); + } + await tester.pumpWidget(buildIndexedStack(StackFit.loose)); + logs.add('=1='); + await tester.pumpWidget(buildIndexedStack(StackFit.expand)); + logs.add('=2='); + await tester.pumpWidget(buildIndexedStack(StackFit.passthrough)); + expect(logs, [ + 'BoxConstraints(0.0<=w<=3.0, 0.0<=h<=7.0)', + '=1=', + 'BoxConstraints(w=3.0, h=7.0)', + '=2=', + 'BoxConstraints(2.0<=w<=3.0, 5.0<=h<=7.0)', + ]); + }); }