I am creating a localized app with a Bottom Nav Bar on main page. If I change localization the BottomNavigationBar's items name not updating until click one of them. How can I update the Bottom Bar? What am I miss?
Code:
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
onTap: onTabTapped,
type: BottomNavigationBarType.fixed,
// new
currentIndex: _currentIndex,
selectedFontSize: 12,
unselectedFontSize: 12,
elevation: 10,
showSelectedLabels: true,
showUnselectedLabels: true,
items: [
new BottomNavigationBarItem(
icon: Icon(MyFlutterAppIOS.share_100, color: Colors.blueGrey),
title: Text(
allTranslations.text("sharetitle"),
style: TextStyle(
color: Colors.blueGrey,
),
),
),
new BottomNavigationBarItem(
icon: Icon(MyFlutterAppIOS.protect_100, color: Colors.blueGrey),
title: Text(
allTranslations.text("lblprivacypolicy"),
style: TextStyle(
color: Colors.blueGrey,
),
),
),
new BottomNavigationBarItem(
icon: Icon(MyFlutterAppIOS.protect_100, color: Colors.blueGrey),
title: Text(
allTranslations.text("lblterms"),
style: TextStyle(
color: Colors.blueGrey,
),
),
),
new BottomNavigationBarItem(
icon: Icon(MyFlutterAppIOS.info_100, color: Colors.blueGrey),
title: Text(
allTranslations.text("lblinfo"),
style: TextStyle(color: Colors.blueGrey),
),
)
],
);
}
That's because you are not building this widget again by any means. You need to rebuild this widget again once you change the language. You can use any state management library like BLOC or provider to notify the change to this widget once you update the language. So when you click on any item, it rebuilds, and then you see the changes.
ChangeNotifierProvider(
create: (context) => AppLevelProvider(),
child: BottomNavigationBar(),
),
You can also use an existing provider here and notify the changes. Please read more about state management here