【发布时间】:2019-06-05 17:41:45
【问题描述】:
我正在尝试使用 PreferredSize 创建自定义 TabBar,但我无法将 TabBar 的颜色与我的 body 融合在一起,TabBar 和 body 之间似乎有一个边框。下面的图片将清楚地向您展示我想要完成的工作。
我试图创建一个与大宽度主体颜色相同的边框,但它似乎不起作用。这是我的代码:
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) 的乘积,那么这条线就会消失,这可能是颤振本身的错误吗?
【问题讨论】:
-
我很确定边框不是来自
TabBar本身。请显示您在哪里使用_buildTabBar函数。 -
@George 我已经编辑了上面显示的代码,您可以查看一下。
-
顺便删除图片是不行的。
-
你认为它可能是这个屏幕的主体提供了这个边框吗? IE。它不是
AppBar的一部分。 -
@George body 只是一个 DefaultTabController 和一个有颜色的 Container,没有边框。