如何創建帶有文本的圓形復選框?我想要圖片上的樣子。

uj5u.com熱心網友回復:
您可以制作一個按下時切換 bool 的按鈕,并根據 bool 是真還是假,您可以使邊框透明或不透明。這可能不是最好的解決方案,但它應該有效
class CustomCheckbox extends StatefulWidget {
@override
State<CustomCheckbox> createState() => _CustomCheckboxState();
}
class _CustomCheckboxState extends State<CustomCheckbox> {
bool isChecked = false;
@override
Widget build(BuildContext context) {
return RawMaterialButton(
onPressed: () {
setState(() => isChecked = !isChecked);
},
splashColor: Colors.transparent,
child: Text(
'AS',
style: TextStyle(
color: isChecked ? Colors.white : Colors.grey,
fontSize: 20
)
),
padding: EdgeInsets.all(13.0),
shape: CircleBorder(
side: BorderSide(
color: isChecked ? Colors.yellowAccent : Colors.transparent
)
),
);
}
}
uj5u.com熱心網友回復:
嘗試連續使用 ClipOval 兒童
ClipOval(
child:
Container(
color: yourColor
height: 10.0,
width: 10.0,
))
uj5u.com熱心網友回復:
class Checkbox extends StatefulWidget {
final String value;
final bool check;
const Checkbox({
Key? key, required this.value, required this.check,
}) : super(key: key);
@override
State<Checkbox> createState() => _CheckboxState();
}
class _CheckboxState extends State<Checkbox> {
late bool check;
@override
void initState() {
check = widget.check;
super.initState();
}
@override
Widget build(BuildContext context) {
return InkWell(
onTap: (){
setState(()=>check = !check);
},
child: Container(
padding: EdgeInsets.all(6),
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: check ? Colors.yellow : Colors.transparent,
width: 2),
),
child: Text(widget.value, style: TextStyle(color: check ? Colors.white
: Colors.grey)),
),
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/398607.html
