| 1 | import 'package:flutter/material.dart'; |
| 2 | |
| 3 | class StandardCheckbox extends StatelessWidget { |
| 4 | StandardCheckbox( |
| 5 | {required this.value, |
| 6 | this.caption = '', |
| 7 | this.gradientBackground = false, |
| 8 | this.borderColor, |
| 9 | this.iconColor, |
| 10 | this.captionColor, |
| 11 | required this.onChanged}); |
| 12 | |
| 13 | final bool value; |
| 14 | final String caption; |
| 15 | final bool gradientBackground; |
| 16 | final Color? borderColor; |
| 17 | final Color? iconColor; |
| 18 | final Color? captionColor; |
| 19 | final Function(bool)? onChanged; |
| 20 | |
| 21 | @override |
| 22 | Widget build(BuildContext context) { |
| 23 | final baseGradient = LinearGradient(colors: [ |
| 24 | Theme.of(context).colorScheme.primary, |
| 25 | Theme.of(context).colorScheme.primary.withOpacity(0.7), |
| 26 | ], begin: Alignment.centerLeft, end: Alignment.centerRight); |
| 27 | |
| 28 | final boxBorder = Border.all( |
| 29 | color: borderColor ?? Theme.of(context).colorScheme.outline, |
| 30 | width: 2.0, |
| 31 | ); |
| 32 | |
| 33 | final checkedBoxDecoration = BoxDecoration( |
| 34 | gradient: gradientBackground ? baseGradient : null, |
| 35 | border: gradientBackground ? null : boxBorder, |
| 36 | borderRadius: BorderRadius.all(Radius.circular(8.0)), |
| 37 | ); |
| 38 | |
| 39 | final uncheckedBoxDecoration = |
| 40 | BoxDecoration(border: boxBorder, borderRadius: BorderRadius.all(Radius.circular(8.0))); |
| 41 | |
| 42 | return GestureDetector( |
| 43 | onTap: onChanged == null ? null : () => onChanged!(!value), |
| 44 | child: Row( |
| 45 | mainAxisSize: MainAxisSize.min, |
| 46 | mainAxisAlignment: MainAxisAlignment.start, |
| 47 | crossAxisAlignment: CrossAxisAlignment.start, |
| 48 | children: <Widget>[ |
| 49 | Container( |
| 50 | height: 24.0, |
| 51 | width: 24.0, |
| 52 | decoration: value ? checkedBoxDecoration : uncheckedBoxDecoration, |
| 53 | child: value |
| 54 | ? Icon( |
| 55 | Icons.check, |
| 56 | color: iconColor ?? Theme.of(context).colorScheme.primary, |
| 57 | size: 20.0, |
| 58 | ) |
| 59 | : Offstage(), |
| 60 | ), |
| 61 | if (caption.isNotEmpty) |
| 62 | Flexible( |
| 63 | child: Padding( |
| 64 | padding: EdgeInsets.only(left: 10), |
| 65 | child: Text( |
| 66 | caption, |
| 67 | softWrap: true, |
| 68 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 69 | fontSize: 16.0, |
| 70 | fontWeight: FontWeight.normal, |
| 71 | color: captionColor ?? Theme.of(context).colorScheme.onSurface, |
| 72 | decoration: TextDecoration.none, |
| 73 | ), |
| 74 | ), |
| 75 | ), |
| 76 | ) |
| 77 | ], |
| 78 | ), |
| 79 | ); |
| 80 | } |
| 81 | } |