title_bar_buttons.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import 'package:fis_ui/index.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/pages/home/controller.dart';
  5. class TitleBarButtons extends StatefulWidget {
  6. final VoidCallback onMinimize;
  7. final VoidCallback onWindowClose;
  8. final VoidCallback? onMaximize;
  9. final Color iconColor;
  10. final Color backgroundColor;
  11. late final Color? hoverColor;
  12. late final Color? hoverIconColor;
  13. TitleBarButtons(
  14. this.onMinimize,
  15. this.onWindowClose,
  16. this.onMaximize,
  17. this.iconColor,
  18. this.backgroundColor, {
  19. Color? hoverColor,
  20. Color? hoverIconColor,
  21. }) {
  22. if (hoverColor == null) {
  23. this.hoverColor = const Color(0xff7bc3ff);
  24. } else {
  25. this.hoverColor = hoverColor;
  26. }
  27. if (hoverIconColor == null) {
  28. this.hoverIconColor = iconColor;
  29. } else {
  30. this.hoverIconColor = hoverIconColor;
  31. }
  32. }
  33. @override
  34. State<StatefulWidget> createState() {
  35. return _TitleBarButtonsState();
  36. }
  37. }
  38. class _TitleBarButtonsState extends State<TitleBarButtons> {
  39. @override
  40. Widget build(BuildContext context) {
  41. return Container(
  42. height: 40,
  43. child: Row(
  44. crossAxisAlignment: CrossAxisAlignment.center,
  45. mainAxisAlignment: MainAxisAlignment.end,
  46. children: [
  47. HoverIconButton(
  48. widget.iconColor,
  49. widget.onMinimize,
  50. FIcon(Icons.remove),
  51. widget.backgroundColor,
  52. hoverColor: widget.hoverColor,
  53. hoverIconColor: widget.hoverIconColor,
  54. ),
  55. if (widget.onMaximize != null) ...[
  56. HoverIconButton(
  57. widget.iconColor,
  58. widget.onMaximize!,
  59. Obx(() {
  60. var controller = Get.find<HomeController>();
  61. if (!controller.state.isMaximized) {
  62. return FIcon(Icons.crop_square);
  63. } else {
  64. return FIcon(Icons.filter_none);
  65. }
  66. }),
  67. widget.backgroundColor,
  68. hoverColor: widget.hoverColor,
  69. hoverIconColor: widget.hoverIconColor,
  70. ),
  71. ],
  72. HoverIconButton(
  73. widget.iconColor,
  74. widget.onWindowClose,
  75. FIcon(Icons.close),
  76. widget.backgroundColor,
  77. hoverColor: Colors.red,
  78. hoverIconColor: widget.hoverIconColor,
  79. ),
  80. ],
  81. ),
  82. );
  83. }
  84. }
  85. class HoverIconButton extends StatefulWidget {
  86. final Color iconColor;
  87. final Color backgroundColor;
  88. final VoidCallback onPressed;
  89. final Widget icon;
  90. late final Color? hoverColor;
  91. late final Color? hoverIconColor;
  92. late final double? width;
  93. late final double? height;
  94. HoverIconButton(
  95. this.iconColor,
  96. this.onPressed,
  97. this.icon,
  98. this.backgroundColor, {
  99. Color? hoverColor,
  100. Color? hoverIconColor,
  101. double? height,
  102. double? width,
  103. }) {
  104. if (hoverColor == null) {
  105. this.hoverColor = backgroundColor;
  106. } else {
  107. this.hoverColor = hoverColor;
  108. }
  109. this.height = height;
  110. this.width = width;
  111. if (hoverIconColor == null) {
  112. this.hoverIconColor = iconColor;
  113. } else {
  114. this.hoverIconColor = hoverIconColor;
  115. }
  116. }
  117. @override
  118. State<StatefulWidget> createState() {
  119. return HoverIconButtonState();
  120. }
  121. }
  122. class HoverIconButtonState extends State<HoverIconButton> {
  123. Color _backgroundColor = Colors.transparent;
  124. late Color _iconColor;
  125. late final Color hoverColor;
  126. late final Color hoverIconColor;
  127. @override
  128. void initState() {
  129. _iconColor = widget.iconColor;
  130. hoverColor = widget.hoverColor ?? widget.backgroundColor;
  131. hoverIconColor = widget.hoverIconColor ?? _iconColor;
  132. super.initState();
  133. }
  134. @override
  135. Widget build(BuildContext context) {
  136. return MouseRegion(
  137. onEnter: (event) {
  138. setState(() {
  139. _iconColor = hoverIconColor;
  140. _backgroundColor = hoverColor;
  141. });
  142. },
  143. onExit: (event) {
  144. setState(() {
  145. _iconColor = widget.iconColor;
  146. _backgroundColor = widget.backgroundColor;
  147. });
  148. },
  149. child: Container(
  150. width: widget.width,
  151. height: widget.height,
  152. color: _backgroundColor,
  153. child: IconButton(
  154. color: _iconColor,
  155. onPressed: () {
  156. widget.onPressed.call();
  157. },
  158. icon: widget.icon,
  159. ),
  160. ),
  161. );
  162. }
  163. }