hover_text_button.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import 'package:fis_theme/theme.dart';
  2. import 'package:fis_ui/index.dart';
  3. import 'package:fis_ui/interface/active_widget.dart';
  4. import 'package:fis_ui/interface/interactive_container.dart';
  5. import 'package:flutter/material.dart';
  6. class FHoverTextButton extends FStatefulWidget implements FActiveWidget {
  7. ///按钮文字
  8. final String label;
  9. ///鼠标悬浮时颜色
  10. final Color? hoverColor;
  11. ///非鼠标悬浮颜色
  12. final Color? color;
  13. ///点击事件
  14. final GestureTapCallback onTap;
  15. /// 图标数值
  16. final IconData? iconData;
  17. /// 字号
  18. final double fontSize;
  19. /// 字体粗细
  20. final FontWeight fontWeight;
  21. /// 字体高度
  22. final double? fontHeight;
  23. @override
  24. final FInteractiveContainer businessParent;
  25. @override
  26. final String? name;
  27. FHoverTextButton({
  28. required this.label,
  29. required this.onTap,
  30. required this.businessParent,
  31. this.name,
  32. this.hoverColor,
  33. this.color,
  34. this.iconData,
  35. this.fontSize = 18,
  36. this.fontWeight = FontWeight.normal,
  37. this.fontHeight,
  38. });
  39. @override
  40. FState<FStatefulWidget> createState() {
  41. return _FHoverTextButtonState();
  42. }
  43. }
  44. class _FHoverTextButtonState extends FState<FHoverTextButton> {
  45. bool _isHover = false;
  46. @override
  47. FWidget build(BuildContext context) {
  48. Color _color;
  49. if (_isHover) {
  50. _color = widget.hoverColor ?? FTheme.ins.colorScheme.secondary;
  51. } else {
  52. _color = widget.color ?? FTheme.ins.colorScheme.primary;
  53. }
  54. return FMouseRegion(
  55. cursor: SystemMouseCursors.click,
  56. onHover: (_) {
  57. setState(() {
  58. _isHover = true;
  59. });
  60. },
  61. onExit: (_) {
  62. setState(() {
  63. _isHover = false;
  64. });
  65. },
  66. child: FGestureDetector(
  67. name: widget.name ?? widget.label,
  68. businessParent: widget.businessParent,
  69. child: _buildBody(_color),
  70. onTap: widget.onTap,
  71. ),
  72. );
  73. }
  74. FWidget _buildBody(Color color) {
  75. final textWidget = FText(
  76. widget.label,
  77. style: TextStyle(
  78. height: widget.fontHeight,
  79. fontWeight: widget.fontWeight,
  80. fontSize: widget.fontSize,
  81. color: color,
  82. ),
  83. );
  84. if (widget.iconData == null) {
  85. return textWidget;
  86. } else {
  87. final iconWidget = FIcon(
  88. widget.iconData!,
  89. size: widget.fontSize,
  90. color: color,
  91. );
  92. return FRow(
  93. mainAxisSize: MainAxisSize.min,
  94. children: [
  95. iconWidget,
  96. textWidget,
  97. ],
  98. );
  99. }
  100. }
  101. }