flutter自带的checkbox是方形的,需要圆形可以自定义一个,用法一样:
import 'package:flutter/material.dart';
class RoundCheckBox extends StatefulWidget {
var value = false;
Function(bool) onChanged;
RoundCheckBox({Key key, @required this.value, this.onChanged})
: super(key: key);
@override
_RoundCheckBoxState createState() => _RoundCheckBoxState();
}
class _RoundCheckBoxState extends State<RoundCheckBox> {
@override
Widget build(BuildContext context) {
return Center(
child: GestureDetector(
onTap: () {
widget.value = !widget.value;
widget.onChanged(widget.value);
},
child: Padding(
padding: const EdgeInsets.all(10.0),
child: widget.value
? Icon(
Icons.check_circle,
size: 25.0,
color: Colors.lightBlue,
)
: Icon(
Icons.panorama_fish_eye,
size: 25.0,
color: Colors.grey,
),
)),
);
}
}
欢迎学习flutter的同学加群一起学习:187670882