我想创建一个带有芯片的 TabBar,如下所示:
代码是:
class TabChip extends StatefulWidget{
final String chipTitle;
TabChip(this.chipTitle) : assert(chipTitle != null);
@override
State<StatefulWidget> createState() {
return _TabChipState();
}
}
class _TabChipState extends State<TabChip>{
bool isSelected = false;
@override
Widget build(BuildContext context) {
return RawChip(
avatar: CircleAvatar(),
label: Text(widget.chipTitle,
style: TextStyle(
color: isSelected ? Colors.white : Colors.red,
fontWeight: FontWeight.bold
),),
backgroundColor: isSelected ? Colors.red : Colors.white, // Switch colors if chip is selected
shape: StadiumBorder(side: BorderSide(color: Colors.red, width: 2.0)),
selectedColor: Colors.red,
selected: isSelected,
onPressed: (){
setState(() {
isSelected = isSelected ? false : true;
});
},
// onSelected: (bool value){
// setState(() {
// isSelected = true;
// });
// },
);
}
}
Now, I have been able to use a RawChip Widget to create the basic outline of this but when the chip is selected, a tick icon is shown in the avatar.
我想禁用头像。
我还想添加一次选择单个选项卡的功能。
我怎么做?