【问题标题】:In Flutter, how can I change the font of the items in a BottomNavigationBar?在 Flutter 中,如何更改 BottomNavigationBar 中项目的字体?
【发布时间】:2023-03-05 13:09:01
【问题描述】:

我在 stackoverflow 上搜索了这个问题的答案,但没有运气。从类似的问题(Style BottomNavigationBar in Flutter)我意识到我应该按照以下方式设置主题

答案在于需要设置textTheme bodyText2

return Theme(
        data: Theme.of(context).copyWith(
            textTheme: Theme.of(context).textTheme.copyWith(
                caption: GoogleFonts.aclonica(),
        )), // sets the inactive color of the `BottomNavigationBar`
        child: BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            backgroundColor: Colors.transparent,
            currentIndex: 0,
            fixedColor: Colors.teal,
            items: items.map((item) {
              return BottomNavigationBarItem(
                label: item.label,
                icon: getIconExcl(context, item),
              );
            }).toList()));

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    这是可以做到的,只需要知道要设置哪个textTheme。不要使用标题,请按以下方式使用 bodyText2

    return Theme(
            data: Theme.of(context).copyWith(
                textTheme: Theme.of(context).textTheme.copyWith(
                    bodyText2: GoogleFonts.aclonica(),
            )), // sets the inactive color of the `BottomNavigationBar`
            child: BottomNavigationBar(
                type: BottomNavigationBarType.fixed,
                backgroundColor: Colors.transparent,
                currentIndex: 0,
                fixedColor: Colors.teal,
                items: items.map((item) {
                  return BottomNavigationBarItem(
                    label: item.label,
                    icon: getIconExcl(context, item),
                  );
                }).toList()));
    

    【讨论】:

      猜你喜欢
      • 2019-04-22
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 2023-01-10
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多