flutter - 将按钮颜色更改为弯曲导航栏中选项卡上的主要颜色
问题描述
我使用 CurvedNavigationBar 作为我的底部导航栏。点击时,我想将此黑色图标颜色更改为原色。但是当它没有被点击时,我只想要 ti 作为黑色。我该怎么做?我尝试更改 CurvedNavigationBar 的最后三个属性,但没有获得所需的输出。
代码:
final bottomNavBar = CurvedNavigationBar(
items: [
SvgPicture.asset(
'assets/images/hand-shake.svg',
key: Key('SessionsPage'),
height: ScreenUtil().setHeight(26),
width: ScreenUtil().setWidth(26),
color: Colors.black,
),
SvgPicture.asset(
'assets/images/home.svg',
height: ScreenUtil().setHeight(26),
key: Key("FeedsPage"),
width: ScreenUtil().setWidth(26),
color: Colors.black,
),
Card(
elevation: 5,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(50)),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 24,
child: Icon(
Icons.edit,
color: Colors.black,
size: 35,
),
),
),
Image.asset(
'assets/images/booking_icon.png',
height: ScreenUtil().setHeight(26),
width: ScreenUtil().setWidth(26),
color: Colors.black,
),
StreamBuilder(
stream: usersRef
.document(CurrentUser().currentUser.databaseID)
.collection('Alerts')
.snapshots(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
return Stack(
children: <Widget>[
SvgPicture.asset(
'assets/images/noti.svg',
height: ScreenUtil().setHeight(26),
width: ScreenUtil().setWidth(26),
color: Colors.black,
),
CircleAvatar(
radius: 2,
)
],
);
default:
List rev1 = snapshot.data.documents.toList();
List res1 = [];
for (var i in rev1) {
if (i.data['seen'] == false) res1.add(i.documentID);
}
return Stack(
children: <Widget>[
SvgPicture.asset(
'assets/images/noti.svg',
height: ScreenUtil().setHeight(26),
width: ScreenUtil().setWidth(26),
color: Colors.black,
),
res1.length == 0
? CircleAvatar(
radius: 2,
)
: CircleAvatar(
radius: 8,
backgroundColor: Colors.white,
child: Text(
res1.length.toString(),
style: TextStyle(fontSize: 10),
),
),
],
);
}
// child: SvgPicture.asset(
// 'assets/images/noti.svg',
// height: ScreenUtil().setHeight(28),
// width: ScreenUtil().setWidth(28),
// color: whiteColor,
// ),
}),
],
onTap: onTabTapped,
index: _currentIndex,
backgroundColor: Colors.white,
buttonBackgroundColor: whiteColor,
color: Colors.white,
height: 60,
);
return Scaffold(bottomNavigationBar: bottomNavBar, body: returnBody());
}
}
解决方案
我不知道这个CurvedNavigationBar
小部件,但是,查看您的代码,我可以假设您已经在_currentIndex
变量中拥有选定的索引。
因此,您可以更改您的项目并验证此属性以定义正确的颜色:
CurvedNavigationBar(
items: [
SvgPicture.asset(
'assets/images/hand-shake.svg',
key: Key('SessionsPage'),
height: ScreenUtil().setHeight(26),
width: ScreenUtil().setWidth(26),
color: _currentIndex == 0 ? Colors.red : Colors.black,
),
// Other items, incrementing the index validation (e.g. == 1, == 2, etc)
],
// Other properties...
);
只需将 更改为Colors.red
您想要的颜色。
推荐阅读
- c++ - 用 C++ 画一棵 ASCII 艺术圣诞树
- python - 在 python 中读取 CSV 文件时如何跳过逗号?
- amazon-s3 - S3 Boto3 python - 将所有文件 acl 更改为公共读取
- geoserver - 我们曾经通过 viewparams 字段将参数发送到我们的 WMS 地理服务器 SQLViews。但是WMTS没有这个字段
- python - python- sqlite3.OperationalError:靠近“<”:语法错误
- sql - If else 在 Where 子句 SQL 中
- authentication - 通过JMeter进行多用户登录
- python - 将 TensorFlow 对象检测与 keras cnn 分类器集成
- java - 蜜罐样本测试奇数题
- python - 计算直线和椭圆之间的截点 - python