@@ -15,6 +15,7 @@ import 'binding.dart';
1515import 'debug.dart' ;
1616import 'framework.dart' ;
1717import 'localizations.dart' ;
18+ import 'visibility.dart' ;
1819import 'widget_span.dart' ;
1920
2021export 'package:flutter/animation.dart' ;
@@ -3962,12 +3963,80 @@ class Stack extends MultiChildRenderObjectWidget {
39623963///
39633964/// * [Stack] , for more details about stacks.
39643965/// * The [catalog of layout widgets] (https://flutter.dev/widgets/layout/).
3965- class IndexedStack extends Stack {
3966+ class IndexedStack extends StatelessWidget {
39663967 /// Creates a [Stack] widget that paints a single child.
39673968 ///
39683969 /// The [index] argument must not be null.
39693970 const IndexedStack ({
39703971 super .key,
3972+ this .alignment = AlignmentDirectional .topStart,
3973+ this .textDirection,
3974+ this .clipBehavior = Clip .hardEdge,
3975+ this .sizing = StackFit .loose,
3976+ this .index = 0 ,
3977+ this .children = const < Widget > [],
3978+ });
3979+
3980+ /// How to align the non-positioned and partially-positioned children in the
3981+ /// stack.
3982+ ///
3983+ /// Defaults to [AlignmentDirectional.topStart] .
3984+ ///
3985+ /// See [Stack.alignment] for more information.
3986+ final AlignmentGeometry alignment;
3987+
3988+ /// The text direction with which to resolve [alignment] .
3989+ ///
3990+ /// Defaults to the ambient [Directionality] .
3991+ final TextDirection ? textDirection;
3992+
3993+ /// {@macro flutter.material.Material.clipBehavior}
3994+ ///
3995+ /// Defaults to [Clip.hardEdge] .
3996+ final Clip clipBehavior;
3997+
3998+ /// How to size the non-positioned children in the stack.
3999+ ///
4000+ /// Defaults to [StackFit.loose] .
4001+ ///
4002+ /// See [Stack.fit] for more information.
4003+ final StackFit sizing;
4004+
4005+ /// The index of the child to show.
4006+ ///
4007+ /// If this is null, none of the children will be shown.
4008+ final int ? index;
4009+
4010+ /// The child widgets of the stack.
4011+ ///
4012+ /// Only the child at index [index] will be shown.
4013+ ///
4014+ /// See [Stack.children] for more information.
4015+ final List <Widget > children;
4016+
4017+ @override
4018+ Widget build (BuildContext context) {
4019+ final List <Widget > wrappedChildren = List <Widget >.generate (children.length, (int i) {
4020+ return Visibility .maintain (
4021+ visible: i == index,
4022+ child: children[i],
4023+ );
4024+ });
4025+ return _RawIndexedStack (
4026+ alignment: alignment,
4027+ textDirection: textDirection,
4028+ clipBehavior: clipBehavior,
4029+ sizing: sizing,
4030+ index: index,
4031+ children: wrappedChildren,
4032+ );
4033+ }
4034+ }
4035+
4036+ /// The render object widget that backs [IndexedStack] .
4037+ class _RawIndexedStack extends Stack {
4038+ /// Creates a [Stack] widget that paints a single child.
4039+ const _RawIndexedStack ({
39714040 super .alignment,
39724041 super .textDirection,
39734042 super .clipBehavior,
@@ -3984,7 +4053,7 @@ class IndexedStack extends Stack {
39844053 assert (_debugCheckHasDirectionality (context));
39854054 return RenderIndexedStack (
39864055 index: index,
3987- fit: fit,
4056+ fit: fit,
39884057 clipBehavior: clipBehavior,
39894058 alignment: alignment,
39904059 textDirection: textDirection ?? Directionality .maybeOf (context),
0 commit comments