删除Flutter TabBar底部边框

时间:2019-06-05 17:41:45

标签: flutter dart

我正在尝试使用PreferredSize创建一个自定义TabBar,但是我无法将TabBar的颜色与我的身体融合在一起,TabBar与主体之间似乎存在边界。下面的图片将清楚地向您显示我要完成的工作。

enter image description here

我试图创建一个边框,该边框的颜色与具有较大宽度的主体相同,但似乎不起作用。这是我的代码:

  Widget _buildAppBar(context) {
return AppBar(
  title: Text(title),
  elevation: 0,
  flexibleSpace: Image.asset(
    'images/motif_batik_01.jpg',
    fit: BoxFit.cover,
    width: 1200,
  ),
  bottom: _buildTabBar(context)
);

}

  Widget _buildTabBar(context) {
return PreferredSize(
  preferredSize: Size.fromHeight(100.0),
  child: Container(
    decoration: BoxDecoration(
      color: Theme.of(context).backgroundColor,
      borderRadius: BorderRadius.only(
        topLeft: Radius.circular(50),
        topRight: Radius.circular(50),
      ),
    ),
    padding: EdgeInsets.only(
      top: 50,
      left: 20,
      right: 20,
    ),
    height: 100,
    child: TabBar(
      indicator: BoxDecoration(
        color: Colors.orange, borderRadius: BorderRadius.circular(20)
      ),
      labelStyle: TextStyle(color: Colors.white),
      unselectedLabelColor: Colors.orange,
      tabs: <Widget>[
        Tab(child: Text('A', style: TextStyle(fontSize: 18.0))),
        Tab(child: Text('B', style: TextStyle(fontSize: 18.0))),
      ],
    ),
  )
);

}

编辑说明:我发现,如果我的“ preferedSize”是40.0(40.0,80.0)的乘积,则该行消失了,这可能是颤振本身的错误吗?

5 个答案:

答案 0 :(得分:5)

indicator:BoxDecoration() 要么 indicatorColor:Colors.transparent

答案 1 :(得分:3)

无论您返回的是body,将其包装在下面的代码中。不要忘记关闭括号。

MediaQuery.removePadding(
context: context,
removeTop: true,

答案 2 :(得分:0)

您是否尝试过将容纳TabBar的AppBar的高度设置为0,

final topBar = AppBar(
      elevation: 0.0, <------------ here
      backgroundColor: Colors.white,
      bottom: TabBar(
        indicatorColor: Colors.black,
        indicatorWeight: 2.0,
        indicatorSize: TabBarIndicatorSize.tab,
        tabs: [
          Tab(
              child: Text(
            'Tab one',
            style: headerTextStyle,
          )),
          Tab(
              child: Text(
            'Tab two',
            style: headerTextStyle,
          )),
        ],
      ),
    );

答案 3 :(得分:0)

将指示器颜色添加到tabBar,将颜色添加到透明。

indicatorColor: Colors.transparent

答案 4 :(得分:-1)

añadeestas propiedades al

TabBar(  indicator: UnderlineTabIndicator(
            insets: EdgeInsets.all(5),
          ),
          indicatorWeight: 0,
          indicatorSize: TabBarIndicatorSize.tab,
          labelPadding: EdgeInsets.all(0), )
相关问题