[Flutter]BottomNavigationBar

小黑
發佈於APP
2023/12/13閱讀時間約 1 分鐘

屬性

  • items:底部頁面導航項目。
  • currentIndex:目前頁面。
  • onTap:點擊按鈕後觸發事件。
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('第一頁'),
),
body: pages[currentIndex],
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.one), title: Text('第一頁')),
BottomNavigationBarItem(icon: Icon(Icons.two), title: Text('第二頁')),
BottomNavigationBarItem(icon: Icon(Icons.three), title: Text('第三頁')),
],
currentIndex: currentIndex, //目前頁面
fixedColor: Color.fromARGB(255, 255, 255, 255),
onTap: itemClick,
),
);
}

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