indexstack改變View
一個其他方式的詳細講解:https://segmentfault.com/a/1190000019396175?utm_source=tag-newest
/** * 集成自Stack,用来显示第index个child, * IndexedStack({ Key key, AlignmentGeometry alignment = AlignmentDirectional.topStart, TextDirection textDirection, StackFit sizing = StackFit.loose, this.index = 0, List<Widget> children = const <Widget>[], }) */
class TestIndexedStack extends StatefulWidget { var index = 0; Test1({this.index}); @override _Test1State createState() => _TestIndexedStack(); } class _TestIndexedStack extends State<TestIndexedStack> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: IndexedStack( index: widget.index, alignment: Alignment.center, children: <Widget>[ Text("第一层"), Text("第二层"), Text("第三层"), ], ), ); } }