BottomNavigationBarItem

BottomNavigationBarItem

有什么解决方法可以将BottomNavigationBarItem转换为不同的语言?
我使用Lang.getString(context,key)来访问 map (从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,
      )

最佳答案

从行中删除 const 关键字

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

08-05 09:06