class IndexedStackPage extends StatefulWidget {
IndexedStackPage({Key? key}) : super(key: key);
@override
_IndexedStackPageState createState() => _IndexedStackPageState();
}
class _IndexedStackPageState extends State {
// 当前子项索引
int currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘IndexedStack - ZeroFlutter’),
),
body: IndexedStack(
alignment: Alignment.center,
// 设置当前索引
index: currentIndex,
children: [
PageDetails(title: ‘首页’),
PageDetails(title: ‘消息’),
PageDetails(title: ‘我的’),
],
),
bottomNavigationBar: [下面聊到],
);
}
}
子项内容
这里我们简单使用一个 StatelessWidget
然后再脚手架中添加一个居中的 Text
用来显示一个页面 title
。
这里的