Flutter 颤振动态改变铜条背景色
我想更改选项卡的背景色。我有5个标签,我只希望第一个标签的背景是透明的。也包括活动颜色和非活动颜色 选项卡条形码如下所示:Flutter 颤振动态改变铜条背景色,flutter,Flutter,我想更改选项卡的背景色。我有5个标签,我只希望第一个标签的背景是透明的。也包括活动颜色和非活动颜色 选项卡条形码如下所示: return new WillPopScope( onWillPop: () => new Future<bool>.value(true), child: new CupertinoTabScaffold( tabBar: new CupertinoTabBar( backgroundColor: Colors.white,
return new WillPopScope(
onWillPop: () => new Future<bool>.value(true),
child: new CupertinoTabScaffold(
tabBar: new CupertinoTabBar(
backgroundColor: Colors.white, //change here
activeColor: Colors.black, // here
inactiveColor: Colors.grey, // here too
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.access_time),
title: Text('Timeline'),
),
BottomNavigationBarItem(
icon: Icon(Icons.chat_bubble_outline),
title: Text('Talk'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
title: Text('Profile'),
),
],
),
tabBuilder: (BuildContext context, int index) {
return new DefaultTextStyle(
style: const TextStyle(
fontFamily: '.SF UI Text',
fontSize: 17.0,
color: CupertinoColors.black,
),
child: new CupertinoTabView(
builder: (BuildContext context) {
switch (index) {
case 0:
return HomeScreen();
break;
case 1:
return TimelineScreen();
break;
case 2:
return TalkScreen();
break;
case 3:
return SearchScreen();
break;
case 4:
return ProfileScreen();
break;
default:
break;
}
},
),
);
},
),
);
返回新的WillPopScope(
onWillPop:()=>新的未来值(true),
孩子:新杯子(
tabBar:新的CupertinoTabBar(
背景颜色:Colors.white,//在此处更改
activeColor:Colors.black,//此处
inactiveColor:Colors.grey,//这里也是
项目:常数[
底部导航气压计(
图标:图标(Icons.home),
标题:文本(“主页”),
),
底部导航气压计(
图标:图标(图标。访问时间),
标题:文本(“时间线”),
),
底部导航气压计(
图标:图标(图标、聊天、泡泡、轮廓),
标题:文本(“谈话”),
),
底部导航气压计(
图标:图标(Icons.search),
标题:文本(“搜索”),
),
底部导航气压计(
图标:图标(图标、账户和圆圈),
标题:文本(“概要文件”),
),
],
),
tabBuilder:(BuildContext,int-index){
返回新的DefaultTextStyle(
样式:consttextstyle(
fontFamily:“.SF UI文本”,
字体大小:17.0,
颜色:铜色。黑色,
),
孩子:新Cupertinobview(
生成器:(BuildContext上下文){
开关(索引){
案例0:
返回主屏幕();
打破
案例1:
返回TimelineScreen();
打破
案例2:
返回TalkScreen();
打破
案例3:
返回搜索屏幕();
打破
案例4:
返回ProfileScreen();
打破
违约:
打破
}
},
),
);
},
),
);
我尝试设置变量\u currentIndex
,并根据索引用户的身份进行更改,但我无法调用setState
,因为错误显示:
颤振:在构建时抛出了以下断言\u TabSwitchingView(脏,状态:颤振:选项卡切换视图状态(86c7b):
颤振:在生成期间调用setState()或markNeedsBuild()。
颤振:无法将此主屏幕小部件标记为需要构建,因为框架已在
颤振:构建小部件的过程。小部件可以标记为需要在构建阶段构建
颤振:只有当它的祖先之一正在建造时。此异常是允许的,因为框架
颤振:在子部件之前构建父部件,这意味着将始终构建脏的子部件。
颤振:否则,框架可能不会在构建阶段访问此小部件
有人有办法做到这一点吗 我发现了。我不确定这是否合适。 希望这有帮助
return new WillPopScope(
int currentIndex = 0;
onWillPop: () => new Future<bool>.value(true),
child: new CupertinoTabScaffold(
tabBar: new CupertinoTabBar(
onTap: (index) {
setState(() {
currentIndex = index;
});
},
backgroundColor: currentIndex == 0 ? Colors.transparent : Colors.white,
activeColor: currentIndex == 0 ? Colors.white : Colors.black,
inactiveColor: currentIndex == 0 ? Colors.white.withOpacity(0.5) : Colors.grey,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.access_time),
title: Text('Timeline'),
),
BottomNavigationBarItem(
icon: Icon(Icons.chat_bubble_outline),
title: Text('Talk'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
title: Text('Profile'),
),
],
),
tabBuilder: (BuildContext context, int index) {
return new DefaultTextStyle(
style: const TextStyle(
fontFamily: '.SF UI Text',
fontSize: 17.0,
color: CupertinoColors.black,
),
child: new CupertinoTabView(
builder: (BuildContext context) {
switch (index) {
case 0:
return HomeScreen();
break;
case 1:
return TimelineScreen();
break;
case 2:
return TalkScreen();
break;
case 3:
return SearchScreen();
break;
case 4:
return ProfileScreen();
break;
default:
break;
}
},
),
);
},
),
);
返回新的WillPopScope(
int currentIndex=0;
onWillPop:()=>新的未来值(true),
孩子:新杯子(
tabBar:新的CupertinoTabBar(
onTap:(索引){
设置状态(){
currentIndex=索引;
});
},
backgroundColor:currentIndex==0?颜色。透明:颜色。白色,
activeColor:currentIndex==0?颜色。白色:颜色。黑色,
inactiveColor:currentIndex==0?颜色。白色。不透明度(0.5):颜色。灰色,
项目:常数[
底部导航气压计(
图标:图标(Icons.home),
标题:文本(“主页”),
),
底部导航气压计(
图标:图标(图标。访问时间),
标题:文本(“时间线”),
),
底部导航气压计(
图标:图标(图标、聊天、泡泡、轮廓),
标题:文本(“谈话”),
),
底部导航气压计(
图标:图标(Icons.search),
标题:文本(“搜索”),
),
底部导航气压计(
图标:图标(图标、账户和圆圈),
标题:文本(“概要文件”),
),
],
),
tabBuilder:(BuildContext,int-index){
返回新的DefaultTextStyle(
样式:consttextstyle(
fontFamily:“.SF UI文本”,
字体大小:17.0,
颜色:铜色。黑色,
),
孩子:新Cupertinobview(
生成器:(BuildContext上下文){
开关(索引){
案例0:
返回主屏幕();
打破
案例1:
返回TimelineScreen();
打破
案例2:
返回TalkScreen();
打破
案例3:
返回搜索屏幕();
打破
案例4:
返回ProfileScreen();
打破
违约:
打破
}
},
),
);
},
),
);