[英]How to make checkbox shape to circular using flutter
Expecting the checkbox in circular shape with inside right tick mark期望带有内部右刻度标记的圆形复选框
Following is a sample Widget with round area and check mark in middle.以下是一个带有圆形区域和中间复选标记的示例小部件。 You can play around with this to achieve a circular check mark.
您可以使用它来实现圆形复选标记。
This sample is originally from this SO answer here .此示例最初来自此 SO answer here 。
bool _value = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Circle CheckBox"),
),
body: Center(
child: InkWell(
onTap: () {
setState(() {
_value = !_value;
});
},
child: Container(
decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.blue),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: _value
? Icon(
Icons.check,
size: 30.0,
color: Colors.white,
)
: Icon(
Icons.check_box_outline_blank,
size: 30.0,
color: Colors.blue,
),
),
),
)),
);
}
For this requirement pub dev providing a package circular_check_box为此,pub dev 提供了一个包circular_check_box
Refer this link https://pub.dev/packages/circular_check_box请参阅此链接https://pub.dev/packages/circular_check_box
Detail explanation will available in above link详细说明将在上面的链接中提供
Theme(
data: ThemeData(
checkboxTheme: CheckboxThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)))),
child: CheckboxListTile(
value: model.specialSale,
secondary: Icon(
CustomIcons.percentage,
color: Theme.of(context).primaryColor,
),
onChanged: (v) {
},
title: Text("Checked"),
),
),
There is a simple package you can add that keeps the functionality and animation of the checkbox: https://pub.dev/packages/getwidget您可以添加一个简单的包来保留复选框的功能和动画: https ://pub.dev/packages/getwidget
Implementation after installing and importing package:安装导入包后的实现:
GFCheckbox(
size: GFSize.SMALL,
activeBgColor: GFColors.DANGER,
type: GFCheckboxType.circle,
onChanged: (value) {
setState(() {
isChecked = value;
});
},
value: isChecked,
inactiveIcon: null,
),
Checkbox(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0)),
value: true
onChanged: (value) {},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.