Line data Source code
1 : import 'package:basf_flutter_components/basf_flutter_components.dart'; 2 : import 'package:flutter/material.dart'; 3 : 4 : const double _buttonHeight = 48; 5 : const EdgeInsetsGeometry _padding = EdgeInsets.all(15); 6 : const Size _minimumSize = Size(0, _buttonHeight); 7 : 8 : /// BASF button styles 9 : abstract class ButtonStyles { 10 : /// Contained text button style 11 1 : static ButtonStyle containedTextButtonStyle(Color primaryColor) => 12 2 : _TextButtonStyles().containedTextButtonStyle(primaryColor); 13 : 14 : /// Transparent text button style 15 1 : static ButtonStyle transparentTextButtonStyle(Color primaryColor) => 16 2 : _TextButtonStyles().transparentTextButtonStyle(primaryColor); 17 : 18 : /// Hint text button style 19 1 : static ButtonStyle hintTextButtonStyle(Color primaryColor) => 20 2 : _TextButtonStyles().hintTextButtonStyle(primaryColor); 21 : 22 : /// Primary outlined text button style∫ 23 1 : static ButtonStyle primaryOutlinedButtonStyle(Color primaryColor) => 24 2 : _OutlinedButtonStyles().primaryOutlinedButtonStyle(primaryColor); 25 : } 26 : 27 : class _TextButtonStyles extends ButtonStyles { 28 1 : ButtonStyle containedTextButtonStyle(Color primaryColor) => 29 1 : TextButton.styleFrom( 30 : primary: Colors.white, 31 : padding: _padding, 32 : minimumSize: _minimumSize, 33 : side: BorderSide.none, 34 1 : shape: RoundedRectangleBorder( 35 1 : borderRadius: BasfThemes.defaultBorderRadius, 36 : ), 37 1 : ).copyWith( 38 2 : backgroundColor: MaterialStateProperty.resolveWith((states) { 39 1 : if (states.contains(MaterialState.disabled)) { 40 : return BasfColors.grey; 41 : } else { 42 : return primaryColor; 43 : } 44 : }), 45 1 : foregroundColor: MaterialStateProperty.all(BasfColors.white), 46 : ); 47 : 48 1 : ButtonStyle transparentTextButtonStyle(Color primaryColor) { 49 1 : return TextButton.styleFrom( 50 : padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 5), 51 : backgroundColor: BasfColors.transparent, 52 : primary: primaryColor, 53 : minimumSize: Size.zero, 54 : side: BorderSide.none, 55 1 : shape: RoundedRectangleBorder( 56 1 : borderRadius: BasfThemes.defaultBorderRadius, 57 : ), 58 : tapTargetSize: MaterialTapTargetSize.shrinkWrap, 59 2 : textStyle: BasfThemes.mainTextTheme.caption, 60 1 : ).copyWith( 61 2 : foregroundColor: MaterialStateProperty.resolveWith((states) { 62 1 : return states.contains(MaterialState.disabled) 63 : ? BasfColors.grey 64 : : primaryColor; 65 : }), 66 : ); 67 : } 68 : 69 1 : ButtonStyle hintTextButtonStyle(Color primaryColor) { 70 2 : return transparentTextButtonStyle(primaryColor).copyWith( 71 3 : textStyle: MaterialStateProperty.all(BasfThemes.mainTextTheme.subtitle2), 72 1 : padding: MaterialStateProperty.all(const EdgeInsets.all(5)), 73 1 : foregroundColor: MaterialStateProperty.all(BasfColors.grey), 74 2 : overlayColor: MaterialStateProperty.all(BasfColors.grey.shade100), 75 : ); 76 : } 77 : } 78 : 79 : class _OutlinedButtonStyles extends ButtonStyles { 80 1 : ButtonStyle primaryOutlinedButtonStyle(Color primaryColor) => 81 1 : OutlinedButton.styleFrom( 82 : padding: _padding, 83 : minimumSize: _minimumSize, 84 1 : shape: RoundedRectangleBorder( 85 1 : borderRadius: BasfThemes.defaultBorderRadius, 86 : ), 87 1 : ).copyWith( 88 2 : side: MaterialStateProperty.resolveWith((states) { 89 1 : if (states.contains(MaterialState.disabled)) { 90 : return null; 91 : } else { 92 1 : return BorderSide(color: primaryColor); 93 : } 94 : }), 95 2 : backgroundColor: MaterialStateProperty.resolveWith((states) { 96 1 : if (states.contains(MaterialState.disabled)) { 97 : return BasfColors.grey; 98 : } else { 99 : return BasfColors.transparent; 100 : } 101 : }), 102 2 : foregroundColor: MaterialStateProperty.resolveWith((states) { 103 1 : if (states.contains(MaterialState.disabled)) { 104 : return BasfColors.white; 105 : } else { 106 : return primaryColor; 107 : } 108 : }), 109 : ); 110 : }