I am using the BottomNavigationBar in my Flutter app. I have three items. I want 2 of them to have the default color for selected and unselected labels. But I want to give a unique color to one label. Below is the code
import 'package:flutter/material.dart';
import 'package:playticket/screens/01.dart';
class CustomNavBar extends StatefulWidget {
CustomNavBar({Key? key}) : super(key: key);
@override
State<CustomNavBar> createState() => _CustomNavBarState();
}
class _CustomNavBarState extends State<CustomNavBar> {
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
List<Widget> _screens = [
Screen1(),
Screen1(),
Screen1(),
];
return Scaffold(
body: _screens[_currentIndex],
bottomNavigationBar: SizedBox(
height: 90,
child: BottomNavigationBar(
backgroundColor: Colors.white,
type: BottomNavigationBarType.fixed,
selectedLabelStyle: TextStyle(fontSize: 12, fontFamily: "Poppins", fontWeight: FontWeight.w600),
unselectedLabelStyle: TextStyle(fontSize: 12, fontFamily: "Poppins", fontWeight: FontWeight.w600),
unselectedItemColor: Color(0xff909090),
currentIndex: _currentIndex,
selectedItemColor: Color(0xff3D3D3D),
onTap: (value) {
setState(() => _currentIndex = value);
},
items: [
BottomNavigationBarItem(
activeIcon: ImageIcon(AssetImage("assets/images/home-icon.png"), size: 25,),
label: "Home",
icon: ImageIcon(AssetImage("assets/images/home-icon.png"), size: 25, color: Color(0xff909090),),
),
BottomNavigationBarItem(
icon: Image.asset("assets/images/add-box-fill.png", width: 28, height: 28,),
label: "Create",
),
BottomNavigationBarItem(
activeIcon: ImageIcon(AssetImage("assets/images/ticket-icon.png"), size: 25, color: Color(0xff3D3D3D),),
label: "Reminder",
icon: ImageIcon(AssetImage("assets/images/ticket-icon.png"), size: 25, color: Color(0xff909090),)
),
],
),
),
);
}
}
I want the label of 2nd BottomNavigationBarItem "Create" must have red color even it is selected or not.
How can I achieve this
2
Answers
Hey, I try to give you an alternative:
instead of using an image or an icon, I change it to a Container with a Column that contains an Icon and Text. also set the background color of the container to red to achieve a unique color for that label.then set an empty string to the label property to hide the default label of that item.
You could try this with the selected and unselected color property of the BottomNavigationBar: