123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- import 'package:fis_ui/index.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/pages/home/controller.dart';
- class TitleBarButtons extends StatefulWidget {
- final VoidCallback onMinimize;
- final VoidCallback onWindowClose;
- final VoidCallback? onMaximize;
- final Color iconColor;
- final Color backgroundColor;
- late final Color? hoverColor;
- late final Color? hoverIconColor;
- TitleBarButtons(
- this.onMinimize,
- this.onWindowClose,
- this.onMaximize,
- this.iconColor,
- this.backgroundColor, {
- Color? hoverColor,
- Color? hoverIconColor,
- }) {
- if (hoverColor == null) {
- this.hoverColor = const Color(0xff7bc3ff);
- } else {
- this.hoverColor = hoverColor;
- }
- if (hoverIconColor == null) {
- this.hoverIconColor = iconColor;
- } else {
- this.hoverIconColor = hoverIconColor;
- }
- }
- @override
- State<StatefulWidget> createState() {
- return _TitleBarButtonsState();
- }
- }
- class _TitleBarButtonsState extends State<TitleBarButtons> {
- @override
- Widget build(BuildContext context) {
- return Container(
- height: 40,
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- HoverIconButton(
- widget.iconColor,
- widget.onMinimize,
- FIcon(Icons.remove),
- widget.backgroundColor,
- hoverColor: widget.hoverColor,
- hoverIconColor: widget.hoverIconColor,
- ),
- if (widget.onMaximize != null) ...[
- HoverIconButton(
- widget.iconColor,
- widget.onMaximize!,
- Obx(() {
- var controller = Get.find<HomeController>();
- if (!controller.state.isMaximized) {
- return FIcon(Icons.crop_square);
- } else {
- return FIcon(Icons.filter_none);
- }
- }),
- widget.backgroundColor,
- hoverColor: widget.hoverColor,
- hoverIconColor: widget.hoverIconColor,
- ),
- ],
- HoverIconButton(
- widget.iconColor,
- widget.onWindowClose,
- FIcon(Icons.close),
- widget.backgroundColor,
- hoverColor: Colors.red,
- hoverIconColor: widget.hoverIconColor,
- ),
- ],
- ),
- );
- }
- }
- class HoverIconButton extends StatefulWidget {
- final Color iconColor;
- final Color backgroundColor;
- final VoidCallback onPressed;
- final Widget icon;
- late final Color? hoverColor;
- late final Color? hoverIconColor;
- late final double? width;
- late final double? height;
- HoverIconButton(
- this.iconColor,
- this.onPressed,
- this.icon,
- this.backgroundColor, {
- Color? hoverColor,
- Color? hoverIconColor,
- double? height,
- double? width,
- }) {
- if (hoverColor == null) {
- this.hoverColor = backgroundColor;
- } else {
- this.hoverColor = hoverColor;
- }
- this.height = height;
- this.width = width;
- if (hoverIconColor == null) {
- this.hoverIconColor = iconColor;
- } else {
- this.hoverIconColor = hoverIconColor;
- }
- }
- @override
- State<StatefulWidget> createState() {
- return HoverIconButtonState();
- }
- }
- class HoverIconButtonState extends State<HoverIconButton> {
- Color _backgroundColor = Colors.transparent;
- late Color _iconColor;
- late final Color hoverColor;
- late final Color hoverIconColor;
- @override
- void initState() {
- _iconColor = widget.iconColor;
- hoverColor = widget.hoverColor ?? widget.backgroundColor;
- hoverIconColor = widget.hoverIconColor ?? _iconColor;
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return MouseRegion(
- onEnter: (event) {
- setState(() {
- _iconColor = hoverIconColor;
- _backgroundColor = hoverColor;
- });
- },
- onExit: (event) {
- setState(() {
- _iconColor = widget.iconColor;
- _backgroundColor = widget.backgroundColor;
- });
- },
- child: Container(
- width: widget.width,
- height: widget.height,
- color: _backgroundColor,
- child: IconButton(
- color: _iconColor,
- onPressed: () {
- widget.onPressed.call();
- },
- icon: widget.icon,
- ),
- ),
- );
- }
- }
|