import 'package:flutter/material.dart'; class LabeledCheckbox extends StatelessWidget { const LabeledCheckbox({ Key? key, required this.label, required this.padding, required this.value, required this.onChanged, this.mainAxisAlignment = MainAxisAlignment.start, this.pageName = 'LabeledCheckbox', }) : super(key: key); @override final String pageName; /// 选择框文案 final Widget label; final MainAxisAlignment mainAxisAlignment; /// 间距 final EdgeInsets padding; /// 选择值 final bool value; /// 选择回调 final Function onChanged; @override Widget build(BuildContext context) { final labeledCheckboxbody = Padding( padding: padding, child: Flex( direction: Axis.horizontal, mainAxisAlignment: mainAxisAlignment, children: [ SizedBox( width: 28, child: Checkbox( value: value, checkColor: Colors.white, shape: RoundedRectangleBorder( side: BorderSide.none, borderRadius: BorderRadius.circular(4), ), activeColor: Theme.of(context).primaryColor, onChanged: (bool? newValue) { onChanged(newValue); }, ), ), Flexible( flex: 0, child: label, ), ], ), ); return GestureDetector( child: labeledCheckboxbody, onTap: () => onChanged(!value), ); } }