【问题标题】:Flutter | How to make custom button of BottomNavigationBar in flutter?颤振 |如何在颤动中制作BottomNavigationBar的自定义按钮?
【发布时间】:2019-04-10 09:44:18
【问题描述】:

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

代码如下:

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

它只为图标提供一种颜色。

这就是我想要的:

【问题讨论】:

  • 这个功能最好使用Stack
  • 试试输入BottomNavigationBarType.fixed
  • 堆栈?可以固定位置吗? @CopsOnRoad 先生
  • 是的,它会在一个固定的位置。
  • ok,先生,我要试试。在堆栈中包装按钮图标对吗? @CopsOnRoad

标签: android flutter flutter-layout bottombar


【解决方案1】:

给你

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)),
            ),
          ),
        ],
      ),
    ),
  );
}

【讨论】:

  • 工作得很好,先生。这工作得很好。 !!上帝保佑你先生。谢谢 :) :) @CopsOnRoad
  • 嘿先生,@CopsOnRoad,我想问一下,也许这看起来微不足道,但我真的有麻烦。我在行中有 2 个小部件,行在列中,列在像这样的行中 ' row( ' ' column( ' ' row( ' ' text ' ' container ' 我想使用分隔文本和容器spacebetween,但他们仍然不想分开。有什么建议吗?这里是截图:imgur.com/lyfTfk7
  • 您必须在第二个Row 中使用Expanded
  • 哦,我明白了.. 所以如果我使用扩展,他们想分开吗?非常感谢您回答我的愚蠢问题。 :))
  • 我认为他们应该按照您想要的方式工作,如果不分享您想要做什么的屏幕截图,我会尽力帮助您。
【解决方案2】:

您可能想查看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")
                    ],
                  ),
                ),
              ),
            ),
          ),
          ]
      ),
    )

【讨论】:

  • 展开实际上是您的一个自定义按钮的开始。让我编辑我的答案,这样就更清楚了。
  • 不,它非常清晰易懂。谢谢你的好意帮助我先生。上帝保佑你:) @Robin Reiter
猜你喜欢
  • 2018-08-08
  • 2020-10-13
  • 2019-07-06
  • 2021-02-08
  • 2021-11-27
  • 1970-01-01
  • 1970-01-01
  • 2021-08-17
  • 1970-01-01
相关资源
最近更新 更多