如何本地化BottomNavigationBarItem标签

时间:2020-11-04 20:05:11

标签: flutter dart flutter-widget

有什么解决方法可以将BottomNavigationBarItem翻译成其他语言? 我使用Lang.getString(context,key)来访问地图(从json文件加载)以获取正确的翻译,对这样的标签(即“ Home”)进行硬编码没有任何意义。我该怎么办?

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

1 个答案:

答案 0 :(得分:1)

从行中删除 const 关键字

 items: const <BottomNavigationBarItem>[
 ......
 ......
 ]