1. 程式人生 > 其它 >底部導航欄設定

底部導航欄設定

import'package:flutter/material.dart'; import'tabs/Home.dart'; import'tabs/Setting.dart'; import'tabs/Category.dart';
classTabsextendsStatefulWidget{ Tabs({Key?key}):super(key:key);
@override _TabsStatecreateState()=>_TabsState(); }
class_TabsStateextendsState<Tabs>{ int_currentIndex=0;
List_pageList=[ HomePage(), CategoryPage(), SeetingPage(), ]; @override Widgetbuild(BuildContextcontext){ returnScaffold( appBar:AppBar(title:Text("flutterDemo")), body:this._pageList[this._currentIndex], bottomNavigationBar:BottomNavigationBar( currentIndex:this._currentIndex,//配置選中的索引 onTap:(intindex){ print(index); setState((){ this._currentIndex=index; }); }, iconSize:36.0,//設定圖示大小 fixedColor:Colors.red,//選中的顏色 type:BottomNavigationBarType.fixed,//配置底部tabs可以有多個按鈕 items:[ BottomNavigationBarItem( icon:Icon(Icons.home), title:Text("首頁"), ), BottomNavigationBarItem( icon:Icon(Icons.category), title:Text("分類"), ), BottomNavigationBarItem( icon:Icon(Icons.settings), title:Text("設定"), ), ], ), ); } } ---------------- import'package:flutter/material.dart';
classHomePageextendsStatefulWidget{ HomePage({Key?key}):super(key:key);
@override _HomePageStatecreateState()=>_HomePageState(); }
class_HomePageStateextendsState<HomePage>{ @override Widgetbuild(BuildContextcontext){ returnContainer( child:Text("我是首頁元件"), ); } } 我是Eric,手機號是13522679763