颤振如何使Fotto中的BottomNavigationBar自定义按钮?

时间:2019-04-10 09:44:18

标签: android flutter bottombar

我想创建一个带有文本和图标的按钮,并带有自定义背景颜色和自定义宽度。具有固定位置(不可滚动)。您想帮我吗?

代码如下:

 bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.shifting,
        currentIndex: 0, // this will be set when a new tab is tapped
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.supervised_user_circle), title: Text('Players'),backgroundColor: Colors.red),
          BottomNavigationBarItem(icon: Icon(Icons.whatshot), title: Text('Trending'),backgroundColor: Colors.blueAccent),
          BottomNavigationBarItem(icon: Icon(Icons.access_time), title: Text('Highlights'),backgroundColor: Colors.yellow)
        ]

它只为图标提供颜色。

这就是我想要的:

enter image description here

2 个答案:

答案 0 :(得分:1)

您可能想看看BottomAppBar的概念。
此栏接受任何小部件作为子项,而不仅仅是BottomNavigationBarItems。

您可以尝试以下方法:

BottomAppBar(
      child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Expanded(
            child: SizedBox(
              height: 44,
              child: Material(
                type: MaterialType.transparency,
                child: InkWell(
                  onTap: () {},
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Icon(Icons.add, color: Colors.blue, size: 24),
                      Text("Add")
                    ],
                  ),
                ),
              ),
            ),
          ),
          ]
      ),
    )

答案 1 :(得分:1)

你在这里

enter image description here

Widget build(context) {
  return Scaffold(
    bottomNavigationBar: Container(
      height: 56,
      margin: EdgeInsets.symmetric(vertical: 24, horizontal: 12),
      child: Row(
        children: <Widget>[
          Container(
            width: 66,
            color: Colors.green,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[Icon(Icons.chat, color: Colors.white), Text("CHAT", style: TextStyle(color: Colors.white))],
            ),
          ),
          Container(
            width: 66,
            color: Colors.green,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[Icon(Icons.notifications_active, color: Colors.white), Text("NOTIF", style: TextStyle(color: Colors.white))],
            ),
          ),
          Expanded(
            child: Container(
              alignment: Alignment.center,
              color: Colors.red,
              child: Text("BUY NOW", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
            ),
          ),
        ],
      ),
    ),
  );
}