Line data Source code
1 : import 'package:basf_flutter_components/basf_flutter_components.dart'; 2 : import 'package:flutter/material.dart'; 3 : 4 : /// {@template option_button} 5 : /// Option button used on Radio 6 : /// {@endtemplate} 7 : class OptionButton extends StatelessWidget { 8 : /// {@macro option_button} 9 2 : const OptionButton({ 10 : super.key, 11 : required this.labelText, 12 : this.onPressed, 13 : required this.isSelected, 14 : this.description, 15 : }); 16 : 17 : /// Text for the button 18 : final String labelText; 19 : 20 : /// Action to be performed on pressed 21 : final VoidCallback? onPressed; 22 : 23 : /// Current state of the button 24 : final bool isSelected; 25 : 26 : /// Optional description of the button 27 : final String? description; 28 : 29 1 : @override 30 : Widget build(BuildContext context) { 31 1 : final theme = Theme.of(context); 32 : 33 1 : if (description == null) { 34 1 : return _optionButton(theme); 35 : } else { 36 1 : return Column( 37 1 : children: [ 38 1 : _optionButton(theme), 39 1 : VerticalSpacer.semi(), 40 1 : Text( 41 1 : description!, 42 3 : style: theme.textTheme.bodyText2?.copyWith(color: BasfColors.grey), 43 : ), 44 : ], 45 : ); 46 : } 47 : } 48 : 49 1 : Widget _optionButton(ThemeData theme) { 50 1 : return DecoratedBox( 51 : decoration: const BoxDecoration(boxShadow: [BasfShadows.lightShadow]), 52 1 : child: BasfTextButton.contained( 53 : expanded: true, 54 1 : onPressed: onPressed, 55 1 : style: TextButton.styleFrom( 56 1 : backgroundColor: isSelected ? null : BasfColors.white, 57 : elevation: 1, 58 1 : primary: theme.primaryColor, 59 : ), 60 1 : child: Text( 61 1 : labelText, 62 1 : style: TextStyle( 63 2 : color: isSelected ? BasfColors.backgroundGrey : theme.primaryColor, 64 : ), 65 : ), 66 : ), 67 : ); 68 : } 69 : }