89 lines
2.5 KiB
Dart
89 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../constants.dart';
|
|
|
|
class CheckInputContainer extends StatefulWidget {
|
|
final bool? isChecked;
|
|
final IconData? icon;
|
|
final String label;
|
|
final String? subtitle;
|
|
final ValueChanged<bool> onChanged;
|
|
final double fontSize;
|
|
const CheckInputContainer({
|
|
Key? key,
|
|
this.isChecked,
|
|
this.icon,
|
|
required this.label,
|
|
this.subtitle,
|
|
required this.onChanged,
|
|
this.fontSize = 18
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_CheckInputContainerState createState() => _CheckInputContainerState();
|
|
}
|
|
|
|
class _CheckInputContainerState extends State<CheckInputContainer> {
|
|
bool? isChecked;
|
|
|
|
@override
|
|
void initState() {
|
|
setState(() {
|
|
isChecked = widget.isChecked;
|
|
});
|
|
super.initState();
|
|
}
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SizedBox(
|
|
width: 24,
|
|
height: 24,
|
|
child: Checkbox(
|
|
value: isChecked,
|
|
checkColor: kWhite,
|
|
activeColor: kPrimaryColor,
|
|
visualDensity: VisualDensity.compact,
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(kRadiusInput - 2)),
|
|
side: const BorderSide(color: kLine),
|
|
onChanged: (bool? value) {
|
|
setState(() {
|
|
isChecked = value;
|
|
});
|
|
widget.onChanged(value!);
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(width: kSpace3),
|
|
if (widget.icon != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: kSpace3, top: 1),
|
|
child: Icon(widget.icon, color: kPrimaryColor, size: 18),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// Les libellés viennent de clés pensées pour des champs et
|
|
// finissent par « : ». Une case à cocher n'introduit pas une
|
|
// valeur, elle en est une : on retire le deux-points.
|
|
Text(widget.label.replaceAll(RegExp(r'\s*:\s*$'), ''),
|
|
style: kTextSmall),
|
|
if (widget.subtitle != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 2),
|
|
child: Text(widget.subtitle!, style: kTextHint),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
} |