[Flutter]Drawer

小黑
發佈於APP
2023/12/14閱讀時間約 3 分鐘
class MyApp extends StatefulWidget {
@override
myAppState createState() => myAppState();
}

class myAppState extends State<MyApp> {
//目前選擇頁索引值
int currentIndex = 0; //預設值

final pages = [One(), Two(), Three()];

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text('DrawerDemo'),
),
drawer: Drawer(
child: ListView(
children: <Widget>[
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text('Drawer Header'),
),
//選單
ListTile(
leading: new CircleAvatar(child: Icon(your_icon)),
title: Text('第一頁'),
onTap: () {
itemClick(0);
},
),
ListTile(
leading: new CircleAvatar(child: Icon(your_icon)),
title: Text('第二頁'),
onTap: () {
itemClick(1);
},
),
ListTile(
leading: new CircleAvatar(child: Icon(your_icon)),
title: Text('第三頁'),
onTap: () {
itemClick(2);
},
),
],
),
),
body: pages[currentIndex],
);
}

void itemClick(int index) {
setState(() {
currentIndex = index;
Navigator.of(context).pop();
});
}
}




7會員
78內容數
嗨,我是一名程式設計師,會在這分享開發與學習紀錄。
留言0
查看全部
發表第一個留言支持創作者!
從 Google News 追蹤更多 vocus 的最新精選內容