如何在顫動的BottomNavigationBarItem中設置BackGroundColor?

馬里塞爾萬

[在此處輸入圖像描述][1]這就是我的代碼如何BottomNavigationBarItemflutter. 我在下面添加了我的模型屏幕圖像..任何人請幫助我

bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,

          backgroundColor: Color(0xffffcc2a),
          showUnselectedLabels: true,
          currentIndex: _currentIndex,
          elevation: 20.0,
          onTap: callPage,

          selectedItemColor: Color(0xff3666ad),
          unselectedItemColor: Color(0xff3666ad),

          // this will be set when a new tab is tapped
          items: [
            BottomNavigationBarItem(
              icon: new Icon(
                Icons.ballot,
                color: Color(0xff3666ad),
              ),
              label: 'Insurance',
            ),
            BottomNavigationBarItem(
              icon: new FaIcon(
                FontAwesomeIcons.car,
                color: Color(0xff3666ad),
              ),
              label: 'Motor',
            ),
            BottomNavigationBarItem(
              icon: new Icon(
                Icons.medical_services,
                color: Color(0xff3666ad),
              ),
              label: ('Health'),
            ),
            BottomNavigationBarItem(
              // backgroundColor: Color(0xffffcc2a),
              icon: new Icon(
                Icons.flight,
                color: Color(0xff3666ad),
              ),
              label: ('Travel'),
            ),
            BottomNavigationBarItem(
              // backgroundColor: Color(0xffffcc2a),
              icon: new Icon(
                Icons.local_fire_department,
                color: Color(0xff3666ad),
              ),
              label: ('Fire'),
            ),
            BottomNavigationBarItem(
              // backgroundColor: Color(0xffffcc2a),
              icon: FaIcon(
                FontAwesomeIcons.layerGroup,
                color: Color(0xff3666ad),
              ),
              label: ('Misc'),
            )
          ],
        ),
耶欣謝赫

我在bottomNavigationBar這種情況下使用自定義,以您想要的方式和風格來玩。


class _TestWidgetState extends State<TestWidget> {
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: Container(
        color: Colors.green, // main background
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            NavItem(
              icon: const Icon(Icons.ac_unit),
              isSelected: 0 == _currentIndex,
              label: "Item 1",
              onTap: () {
                setState(() {
                  _currentIndex = 0;
                });
              },
            ),
            NavItem(
              icon: Icon(Icons.umbrella),
              isSelected: 1 == _currentIndex,
              label: "Item 2",
              onTap: () {
                setState(() {
                  _currentIndex = 1;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}

class NavItem extends StatelessWidget {
  const NavItem({
    Key? key,
    required this.icon,
    required this.isSelected,
    required this.onTap,
    required this.label,
  }) : super(key: key);

  final bool isSelected;
  final VoidCallback onTap;
  final String label;
  final Widget icon; // you may use different widget

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: (InkWell(
        onTap: onTap,
        child: Container(
          color: isSelected
              ? Colors.pink
              : Colors.amber, //selected background pink
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              icon,
              Text("$label"),
            ],
          ),
        ),
      )),
    );
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在顫振中將三個條目放在一行中(設置 ui)

如何在顫動中停止重複洛蒂動畫

如何在顫振中自動填充其他框中的值?

如何在顫動中禁用特定的下拉菜單項值

如何在顫動畫布中僅繪製文本的筆觸?

如何在顫動中為卡片添加顏色漸變

如何在顫動中更改我的圖標按鈕的顏色?

如何在顫振中實現滑動類別欄?

如何在顫動中更改底部工作表對話框內的文本?

如何在顫振中推動和彈出直到特定路線

如何在顫動中顯示圖像滑塊?

如何在顫動中在屏幕上顯示小部件?

如何在顫動中製作帶有圓邊的按鈕?

如何在顫動中將 GridView 變形為 Carousel?

如何在顫動中按時更改文本按鈕顏色?

如何在顫動的下拉按鈕中增加文本和箭頭之間的空白?

如何在顫動中創建圓形標籤欄?

如何在顫動中按下的按鈕上創建地圖值列表

如何在顫動中製作展開/折疊小部件?

如何在 Tailwind 中為文本漸變顏色變化設置動畫?

如何在物化自動完成輸入中設置默認值?

如何在可變打字稿中動態設置當前時間

如何在從 javascript 傳遞的 flash (swf) 中設置動態變量?

如何在模態中設置 div 的高度以使其滾動?

如何在 React 中為動態渲染的組件設置狀態變量

如何在默认浏览器中从 BottomNavigationBarItem 打开 URL?

如何在 reactjs 中映射 backgroundColor 键值?

如何在 UWP 中的綁定中設置 ConvertParameter

如何在顫動中單擊切換按鈕時更改多個列表顏色