代码如下:
Material(
elevation: 3,
child: Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
),
child: TabBar(
controller: _controller,
isScrollable: false,
indicatorWeight: 0.0001,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
tabs: _data.map((item) {
int index = _data.indexOf(item);
return Container(
width: 42,
height: 42,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: index == _currentIndex
? LinearGradient(
colors: [Color(0xFF42c8ee), Color(0xFF4293ee)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)
: null,
shape: BoxShape.circle,
),
child: Wrap(
direction: Axis.vertical,
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
Image.asset(
item.value,
fit: BoxFit.contain,
width: 20,
height: 20,
color: index == _currentIndex ? Colors.white : null,
),
Text(
item.key,
style: TextStyle(
fontSize: 10,
color:
index == _currentIndex ? Colors.white : Colors.grey,
),
),
],
),
);
}).toList(),
),
),
)
就是用Material组件将你的view包裹起来设置elevation就行,切勿使用card等其他view包裹!