flutter Bottom AppBar如何實現(xiàn)不規(guī)則底部導(dǎo)航欄,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
10年積累的網(wǎng)站制作、成都網(wǎng)站建設(shè)經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有朔州免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
實現(xiàn)底部導(dǎo)航欄并點擊切換頁面可簡述為有三種方式
TabBar + TabBarView BottomNavigationBar + BottomNavigationBarItem 自定義 BottomAppBar
在這里 使用 BottomAppBar 來實現(xiàn)
/** * 有狀態(tài)StatefulWidget * 繼承于 StatefulWidget,通過 State 的 build 方法去構(gòu)建控件 */class BotomeMenumBarPage extends StatefulWidget { ////通過構(gòu)造方法傳值 BotomeMenumBarPage(); //主要是負責創(chuàng)建state @override BotomeMenumBarPageState createState() => BotomeMenumBarPageState();}/** * 在 State 中,可以動態(tài)改變數(shù)據(jù) * 在 setState 之后,改變的數(shù)據(jù)會觸發(fā) Widget 重新構(gòu)建刷新 */class BotomeMenumBarPageState extends State<BotomeMenumBarPage> { BotomeMenumBarPageState(); @override void initState() { ///初始化,這個函數(shù)在生命周期中只調(diào)用一次 super.initState(); } @override Widget build(BuildContext context) { //構(gòu)建頁面 return buildBottomTabScaffold(); } //當前顯示頁面的 int currentIndex = 0; //點擊導(dǎo)航項是要顯示的頁面 final pages = [ ChildItemView("首頁"), ChildItemView("發(fā)現(xiàn)"), ChildItemView("動態(tài)"), ChildItemView("我的") ]; Widget buildBottomTabScaffold() { return SizedBox( height: 100, child: Scaffold( //對應(yīng)的頁面 body: pages[currentIndex], //appBar: AppBar(title: const Text('Bottom App Bar')), //懸浮按鈕的位置 floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, //懸浮按鈕 floatingActionButton: FloatingActionButton( child: const Icon(Icons.add), onPressed: () { print("add press "); }, ), //其他菜單欄 bottomNavigationBar: BottomAppBar( //懸浮按鈕 與其他菜單欄的結(jié)合方式 shape: CircularNotchedRectangle(), // FloatingActionButton和BottomAppBar 之間的差距 notchMargin: 6.0, color: Colors.white, child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[ buildBotomItem(currentIndex, 0, Icons.home, "首頁"), buildBotomItem(currentIndex, 1, Icons.library_music, "發(fā)現(xiàn)"), buildBotomItem(currentIndex, -1, null, "發(fā)現(xiàn)"), buildBotomItem(currentIndex, 2, Icons.email, "消息"), buildBotomItem(currentIndex, 3, Icons.person, "我的"), ], ), ), )); } // ignore: slash_for_doc_comments /** * @param selectIndex 當前選中的頁面 * @param index 每個條目對應(yīng)的角標 * @param iconData 每個條目對就的圖標 * @param title 每個條目對應(yīng)的標題 */ buildBotomItem(int selectIndex, int index, IconData iconData, String title) { //未選中狀態(tài)的樣式 TextStyle textStyle = TextStyle(fontSize: 12.0,color: Colors.grey); MaterialColor iconColor = Colors.grey; double iconSize=20; EdgeInsetsGeometry padding = EdgeInsets.only(top: 8.0); if(selectIndex==index){ //選中狀態(tài)的文字樣式 textStyle = TextStyle(fontSize: 13.0,color: Colors.blue); //選中狀態(tài)的按鈕樣式 iconColor = Colors.blue; iconSize=25; padding = EdgeInsets.only(top: 6.0); } Widget padItem = SizedBox(); if (iconData != null) { padItem = Padding( padding: padding, child: Container( color: Colors.white, child: Center( child: Column( children: <Widget>[ Icon( iconData, color: iconColor, size: iconSize, ), Text( title, style: textStyle, ) ], ), ), ), ); } Widget item = Expanded( flex: 1, child: new GestureDetector( onTap: () { if (index != currentIndex) { setState(() { currentIndex = index; }); } }, child: SizedBox( height: 52, child: padItem, ), ), ); return item; }}
//子頁面class ChildItemView extends StatefulWidget { String _title; ChildItemView(this._title); @override _ChildItemViewState createState() => _ChildItemViewState();}class _ChildItemViewState extends State<ChildItemView> { @override Widget build(BuildContext context) { return Container( child: Center(child: Text(widget._title)), ); }}
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。
本文標題:flutterBottomAppBar如何實現(xiàn)不規(guī)則底部導(dǎo)航欄
網(wǎng)頁路徑:http://chinadenli.net/article48/ihodhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、企業(yè)建站、關(guān)鍵詞優(yōu)化、品牌網(wǎng)站建設(shè)、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)