BottomNavigationBar 项目的 Flutter 本地化

Flutter localisation of BottomNavigationBar items

我正在创建一个在主页上带有底部导航栏的本地化应用程序。 如果我更改本地化,BottomNavigationBar 的项目名称不会更新,直到单击其中一个。 如何更新底部栏? 我想念什么?

代码:

@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),
      ),
    )
  ],

 );
}

那是因为您没有以任何方式再次构建此小部件。更改语言后,您需要再次重建此小部件。更新语言后,您可以使用任何状态管理库(如 BLOC 或提供商)通知此小部件的更改。 因此,当您单击任何项​​目时,它会重建,然后您会看到更改。

 ChangeNotifierProvider(
      create: (context) => AppLevelProvider(),
      child: BottomNavigationBar(),
 ),

您也可以在此处使用现有提供商并通知更改。请阅读有关状态管理的更多信息 here