在标签栏中添加垂直线作为分隔线作为分隔线

时间:2019-06-09 12:24:32

标签: flutter dart cross-platform tabbar

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

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

我需要这样:

enter image description here

3 个答案:

答案 0 :(得分:3)

最后对我有用

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

}

Output

答案 1 :(得分:1)

您需要的只是

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

答案 2 :(得分:0)

要实现小尺寸分隔符,您可以使用它。

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

}