Pass fit property to RenderIndexedStack (#109295)

This commit is contained in:
Mahesh Jamdade
2022-08-16 17:38:26 +05:30
committed by GitHub
parent f4a64ef03d
commit f9331e2c6c
3 changed files with 67 additions and 0 deletions

View File

@@ -714,6 +714,8 @@ class RenderIndexedStack extends RenderStack {
super.children,
super.alignment,
super.textDirection,
super.fit,
super.clipBehavior,
int? index = 0,
}) : _index = index;

View File

@@ -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);
}

View File

@@ -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<RenderIndexedStack>(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<RenderIndexedStack>(find.byType(IndexedStack));
expect(renderIndexedObject.clipBehavior, equals(Clip.antiAlias));
});
testWidgets('IndexedStack sizing: explicit', (WidgetTester tester) async {
final List<String> logs = <String>[];
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: <Widget>[
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, <String>[
'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)',
]);
});
}