问题描述
我是Flutter的新手,实际上我不是编码员,但我正在尝试构建一个可以执行基本操作(例如登录页面,注册,将用户数据显示在屏幕上)的应用程序,并且我还可以看到每个应用程序我卡在底部导航栏中的应用程序的其他个人资料,我从没想过要通过它很难实现。
我没有放弃,而是决定四处搜寻,并得出不同的结果(其中一些难以理解和令人困惑)。
我正在尝试构建一个导航栏,以最少的内存使用(有效的代码)路由到不同的页面
我很困惑,现在不知道该怎么办!请帮助其他编码器(如果有人解决了这个问题,我会认为自己是编码器,不要想太多)
root = Tk()
root.geometry('700x200')
root.resizable(height = 0,width = 0)
root.title("eWMS Inbound Upload File")
Label(root,text="browse for source file to be converted to the eWMS format").place(x=200,y=50)
Label(root,text="Generate eWMS format template and Save on Computer").place(x=200,y=80)
Label(root,text="Select XLS File and Convert it to CSV with separator semicolon( ; ) ").place(x=200,y=110)
Button(root,text="Select Source File",command=openfile,width=20).place(x=10,y=50)
Button(root,text="Convert to Upload Format",command=createtemplate,y=80)
Button(root,text="Convert XLS to CSV",command=convertocsv,y=110)
root.mainloop()
解决方法
在下面尝试此代码,在脚手架穿刺处插入此代码,也不要忘记插入包装。
bottomNavigationBar: CurvedNavigationBar(
color: Colors.black26,backgroundColor: Color(0xFFFFC5C5),buttonBackgroundColor: Colors.greenAccent,height: 50.0,animationCurve: Curves.bounceInOut,items: <Widget>[
Icon(Icons.translate,size: 20,color: Colors.black),Icon(Icons.translate,Icon(Icons.list,Icon(Icons.account_balance,// Icon(Icons.camera,],index: 2,animationDuration: Duration(milliseconds: 400),onTap: (index) {
debugPrint("Curent index is $index");
}
)
,
好的,我看到您的图标中没有提到颜色,因此页面更改使我们可以应用相同的逻辑来避免混淆。
所以让我们在_tabs最终列表下面声明一个颜色列表
List<Color> selectedColor = [Colors.grey[900],Colors.grey[900],Colors.grey[900]];
现在我们将这些分配给我们的图标
items: [
BottomNavigationBarItem(
icon: Icon(
Icons.home,color: selectedColor[0],//Add here
),title: Text("Home"),),BottomNavigationBarItem(
icon: Icon(
Icons.list,color: selectedColor[1],title: Text("List"),BottomNavigationBarItem(
icon: Icon(
Icons.person,color: selectedColor[2],title: Text("Profile"),
现在,由于此原因,列表中的所有颜色均为灰色
void updateColor(int num){
//here I am again declaring it because when I select the other color the list should //always remain same for the effect you want
selectedColor = [Colors.grey[900],Colors.grey[900]];
setState(() {
switch(num){
case 1 : selectedColor[0] = Colors.Red;
break;
case 2 : selectedColor[1] = Colors.Red;
break;
case 3 : selectedColor[2] = Colors.Red;
break;
}
});
}
现在我们要做的是在您的onChanged函数上调用此函数,或者您也可以在onTap中提及它,但我不明白为什么您同时使用两者
我会用
void _onItemTapped(int _selectedIndex) {
setState(() { //Is something wrong with my setState?
_selectedIndex = index;
updateColor(_selectedIndex);
});
_pageController.jumpToPage(_selectedIndex);
}
,
您可以简单地更改底部导航栏中的颜色,如下所示。
-
改变主色调
color: Colors.orange,
-
更改背景颜色
backgroundColor: Colors.white,
-
更改图标背景色
buttonBackgroundColor: Colors.orangeAccent,
-
更改图标大小
Icon(Icons.person,size: 30),
示例代码如下
bottomNavigationBar: CurvedNavigationBar(
color: Colors.orange,backgroundColor: Colors.white,buttonBackgroundColor: Colors.orangeAccent,items: <Widget>[
Icon(Icons.person,Icon(Icons.close,Icon(Icons.settings,onTap: (index) {
//Handle button tap
},
希望这能解决您的问题。