| 1 | import 'package:flutter/material.dart'; |
| 2 | |
| 3 | class CheckboxWidget extends StatefulWidget { |
| 4 | CheckboxWidget({required this.value, required this.caption, required this.onChanged}); |
| 5 | |
| 6 | final bool value; |
| 7 | final String caption; |
| 8 | final Function(bool) onChanged; |
| 9 | |
| 10 | @override |
| 11 | CheckboxWidgetState createState() => CheckboxWidgetState(value, caption, onChanged); |
| 12 | } |
| 13 | |
| 14 | class CheckboxWidgetState extends State<CheckboxWidget> { |
| 15 | CheckboxWidgetState(this.value, this.caption, this.onChanged); |
| 16 | |
| 17 | bool value; |
| 18 | String caption; |
| 19 | Function(bool) onChanged; |
| 20 | |
| 21 | @override |
| 22 | Widget build(BuildContext context) { |
| 23 | return InkWell( |
| 24 | onTap: () { |
| 25 | value = !value; |
| 26 | onChanged(value); |
| 27 | setState(() {}); |
| 28 | }, |
| 29 | child: Row( |
| 30 | mainAxisAlignment: MainAxisAlignment.start, |
| 31 | children: <Widget>[ |
| 32 | Container( |
| 33 | height: 24.0, |
| 34 | width: 24.0, |
| 35 | margin: EdgeInsets.only(right: 10.0), |
| 36 | decoration: BoxDecoration( |
| 37 | border: Border.all( |
| 38 | color: Theme.of(context).colorScheme.outline, |
| 39 | width: 1.0, |
| 40 | ), |
| 41 | borderRadius: BorderRadius.all(Radius.circular(8.0)), |
| 42 | color: Theme.of(context).colorScheme.surface, |
| 43 | ), |
| 44 | child: value |
| 45 | ? Icon( |
| 46 | Icons.check, |
| 47 | color: Theme.of(context).colorScheme.primary, |
| 48 | size: 20.0, |
| 49 | ) |
| 50 | : null, |
| 51 | ), |
| 52 | Expanded( |
| 53 | child: Text( |
| 54 | caption, |
| 55 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 56 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 57 | ), |
| 58 | ), |
| 59 | ) |
| 60 | ], |
| 61 | ), |
| 62 | ); |
| 63 | } |
| 64 | } |