Flutter给Widget增加背景样式
直接上代码:下面代码如果放到列表里,实现了选择和不选的按钮效果,index是按钮的索引。
Widget _getTabWidget(int index){
BoxDecoration boxDecorationTabNormal = BoxDecoration(
color: Color(0xff818DFF),
//border: Border.all(width: 0.5, style: BorderStyle.solid,color: Color(0xffefefef)),
//borderRadius: BorderRadius.horizontal(right: Radius.circular(5))
);
BoxDecoration boxDecorationTabSelected = BoxDecoration(
color: Color(0xff3446F2),
//border: Border.all(width: 0.5, style: BorderStyle.solid,color: Color(0xffffffff)),
//borderRadius: BorderRadius.horizontal(right: Radius.circular(5))
);
return new Container(
child: GestureDetector(
child: new Container(
width: 90,
height: 40,
margin: EdgeInsets.only(left:10),
decoration: this._selectedDateTabIndex == index ? boxDecorationTabSelected : boxDecorationTabNormal,
child:Row(
mainAxisAlignment:MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(top:5,left: 5,right: 5,bottom: 5),
child: Text(
_tabButtonList.elementAt(index),
textAlign:TextAlign.center,
style: TextStyle(
color: Color(0xffffffff) ,
fontSize: 16,
),
)
),
]
)
),
onTap:(){
setState(() {
_selectedDateTabIndex = index;
});
this._updateList(_selectedTypeTabIndex);
}
),
);
}
本站内容来源于作者发布和网络转载,如有版权相关问题请及时与我们取得联系,我们将立即删除。