secondary_button.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. // ignore: import_of_legacy_library_into_null_safe
  4. import 'package:textstyle_extensions/textstyle_extensions.dart';
  5. import '../size.dart';
  6. import '../styled_image_icon.dart';
  7. import '../text_style.dart';
  8. import '../theme.dart';
  9. import 'base_styled_button.dart';
  10. class SecondaryTextButton extends StatelessWidget {
  11. final String label;
  12. final VoidCallback? onPressed;
  13. const SecondaryTextButton(this.label, {Key? key, this.onPressed})
  14. : super(key: key);
  15. @override
  16. Widget build(BuildContext context) {
  17. final theme = context.watch<AppTheme>();
  18. TextStyle txtStyle = TextStyles.Footnote.textColor(theme.accent1Darker);
  19. return SecondaryButton(
  20. onPressed: onPressed, child: Text(label, style: txtStyle));
  21. }
  22. }
  23. class SecondaryIconButton extends StatelessWidget {
  24. /// Must be either an `AssetImage` for an `ImageIcon` or an `IconData` for a regular `Icon`
  25. final AssetImage icon;
  26. final Function()? onPressed;
  27. final Color? color;
  28. const SecondaryIconButton(this.icon, {Key? key, this.onPressed, this.color})
  29. : assert((icon is AssetImage) || (icon is IconData)),
  30. super(key: key);
  31. @override
  32. Widget build(BuildContext context) {
  33. final theme = context.watch<AppTheme>();
  34. return SecondaryButton(
  35. onPressed: onPressed,
  36. minHeight: 36,
  37. minWidth: 36,
  38. contentPadding: Insets.sm,
  39. child: StyledImageIcon(icon, size: 20, color: color ?? theme.grey),
  40. );
  41. }
  42. }
  43. class SecondaryButton extends StatefulWidget {
  44. final Widget child;
  45. final VoidCallback? onPressed;
  46. final double? minWidth;
  47. final double? minHeight;
  48. final double? contentPadding;
  49. final Function(bool)? onFocusChanged;
  50. const SecondaryButton(
  51. {Key? key,
  52. required this.child,
  53. this.onPressed,
  54. this.minWidth,
  55. this.minHeight,
  56. this.contentPadding,
  57. this.onFocusChanged})
  58. : super(key: key);
  59. @override
  60. _SecondaryButtonState createState() => _SecondaryButtonState();
  61. }
  62. class _SecondaryButtonState extends State<SecondaryButton> {
  63. bool _isMouseOver = false;
  64. @override
  65. Widget build(BuildContext context) {
  66. final theme = context.watch<AppTheme>();
  67. return MouseRegion(
  68. onEnter: (_) => setState(() => _isMouseOver = true),
  69. onExit: (_) => setState(() => _isMouseOver = false),
  70. child: BaseStyledButton(
  71. minWidth: widget.minWidth ?? 78,
  72. minHeight: widget.minHeight ?? 42,
  73. contentPadding: EdgeInsets.all(widget.contentPadding ?? Insets.m),
  74. bgColor: theme.surface,
  75. outlineColor:
  76. (_isMouseOver ? theme.accent1 : theme.grey).withOpacity(.35),
  77. hoverColor: theme.surface,
  78. onFocusChanged: widget.onFocusChanged,
  79. downColor: theme.greyWeak.withOpacity(.35),
  80. borderRadius: Corners.s5,
  81. child: IgnorePointer(child: widget.child),
  82. onPressed: widget.onPressed,
  83. ),
  84. );
  85. }
  86. }