'How to localize BottomNavigationBarItem labels
Is there any workaround to translate the BottomNavigationBarItem into different languages? I use Lang.getString(context, key) to access a map(loaded from a json file) to fetch the right translation, it doesn't make any sense to hard code the label like this, label: "Home". what should I do?
PageView(
controller: pageController,
onPageChanged: _pageSwipped,
children: <Widget>[Page1()],
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.list),
label: Lang.getString(context, key), // it doesn't work because it should be constant.
),
],
currentIndex: _currenIndex,
selectedItemColor: Colors.blue,
iconSize: _deviceSize.size.height * 0.046,
selectedFontSize: _deviceSize.size.height * 0.023,
unselectedItemColor: Colors.grey,
onTap: _bottomTapped,
)
Solution 1:[1]
Remove const keyword from line
items: const <BottomNavigationBarItem>[
......
......
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Chinmay Mourya |