【问题标题】:Add vertical line as a divider in tabbar as a divider在标签栏中添加垂直线作为分隔线作为分隔线
【发布时间】:2019-10-24 03:45:25
【问题描述】:

我有一个标签栏,我需要在标签之间放置一条垂直线作为分隔线,该怎么做? 这就是我使用标签栏的方式:

new TabBar(
                    unselectedLabelColor: Color.fromRGBO(119, 119, 119, 1),
                    labelColor: Colors.black,
                    controller: controller,
                    tabs: <Tab>[
                      new Tab(text: "Girls"),
                      new Tab(text: "Hero"),
                      new Tab(text: "Open"),
                    ]),

我需要它是这样的:

【问题讨论】:

  • 你找到解决办法了吗?
  • 不,我没有找到任何解决方案
  • 我找到了解决方案。请检查答案

标签: flutter dart cross-platform tabbar


【解决方案1】:

终于对我有用了

new TabBar(

          tabs: [
            _individualTab('assets/icons/bottom_nav/Home.png'),
            _individualTab('assets/icons/bottom_nav/Guys.png'),
            _individualTab('assets/icons/bottom_nav/Notes.png'),
            Tab(
              icon: ImageIcon(AssetImage('assets/icons/bottom_nav/Email.png')),
            ),
          ],
          labelColor: STColors.PRIMARY_COLOR,
          unselectedLabelColor: Colors.grey,
          indicatorColor: Colors.white,
          indicatorSize: TabBarIndicatorSize.tab,
          labelPadding: EdgeInsets.all(0),
          indicatorPadding: EdgeInsets.all(0),
        ),

独立标签功能

Widget _individualTab(String imagePath) {
return Container(
  height: 50 + MediaQuery
      .of(context)
      .padding
      .bottom,
  padding: EdgeInsets.all(0),
  width: double.infinity,
  decoration:  BoxDecoration(border: Border(right: BorderSide(color: STColors.LIGHT_BORDER, width: 1, style: BorderStyle.solid))),
  child: Tab(
    icon: ImageIcon(AssetImage(imagePath)),
  ),
);

}

【讨论】:

    【解决方案2】:

    要实现小尺寸的分隔符,你可以使用这个。

    Widget _individualTab(String imagePath) {
    return Container(
      height: 50,
      width: double.infinity,
      decoration:  BoxDecoration(
        border: Border(right: BorderSide(color: STColors.LIGHT_BORDER,
            width: 0,
            style: BorderStyle.solid),
        ),
      ),
      child: Stack(children: <Widget>[
        Center(
            child: Tab(
              icon: ImageIcon(AssetImage(imagePath)),
            ),
        ),
        Align(
          alignment: Alignment.centerRight,
          child: Container(
            color: STColors.appBlackMedium,
            width: 1,
            height: 25,
          ),
        )
      ],)
    );
    

    }

    【讨论】:

      【解决方案3】:

      你只需要

      indicator: BoxDecoration(
        border: Border(
          left: BorderSide(color: Colors.grey), // provides to left side
          right: BorderSide(color: Colors.grey), // for right side
        ),
      ),
      

      你的解决方案:

      new TabBar(
        indicator: BoxDecoration(border: Border(right: BorderSide(color: Colors.orange))),
        unselectedLabelColor: Color.fromRGBO(119, 119, 119, 1),
        labelColor: Colors.black,
        controller: controller,
        tabs: <Tab>[
          new Tab(text: "Girls"),
          new Tab(text: "Hero"),
          new Tab(text: "Open"),
        ]),
      

      【讨论】:

      • 不...它只是为选定的选项卡提供边框。这不是我真正需要的。即使未选择选项卡,它也需要在每个选项卡之间有垂直线。与我们的 VerticalDivider() 完全相同,但它不适用于标签栏。
      • 有人找到解决办法了吗?
      猜你喜欢
      • 2012-10-12
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多