I have following code that was written before and must be updated. I changed title
to label
to update the code but it got a new error:
return BottomNavigationBar(
onTap: (int index) => _homeScreenBloc.updatePageIndex(index),
backgroundColor: Colors.white,
type: BottomNavigationBarType.fixed,
selectedFontSize: 12.0,
unselectedFontSize: 12.0,
selectedItemColor: Color(0xFF6BC076),
unselectedItemColor: Color(0xFF8F8F91),
iconSize: 26,
currentIndex: _index,
elevation: 0,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
label: Text(_titles[0]),
icon: Icon(Icons.attach_money),
),
BottomNavigationBarItem(
label: Text(_titles[1]),
icon: Icon(Icons.account_balance_wallet),
),
BottomNavigationBarItem(
label: Text(_titles[2]),
icon: Icon(Icons.person_outline),
),
],
);
The error message is:
The argument type 'Text' can't be assigned to the parameter type 'String'.dartargument_type_not_assignable
How can I fix this?
CodePudding user response:
As the error describes, you cannot assign a Text widget to a String. The label parameter takes a String, not a Text widget. Below should work.
BottomNavigationBarItem(
label: _titles[0],
icon: Icon(Icons.attach_money),
),
BottomNavigationBarItem(
label: _titles[1],
icon: Icon(Icons.account_balance_wallet),
),
BottomNavigationBarItem(
label: _titles[2],
icon: Icon(Icons.person_outline),
),