title_bar_buttons.dart 4.5 KB

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