import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; import '../services/hover_color.dart'; class CustomTitleBar extends StatefulWidget { final VoidCallback? onSettings; final VoidCallback? onSaveCrop; final bool visible; const CustomTitleBar({super.key, this.onSettings, this.onSaveCrop, this.visible = true}); @override State createState() => _CustomTitleBarState(); } class _CustomTitleBarState extends State { bool _barHovered = false; @override Widget build(BuildContext context) { return Positioned( top: 0, left: 0, right: 0, child: AnimatedOpacity( opacity: widget.visible ? 1.0 : 0.0, duration: const Duration(milliseconds: 150), child: MouseRegion( cursor: SystemMouseCursors.grab, onEnter: (_) => setState(() => _barHovered = true), onExit: (_) => setState(() => _barHovered = false), child: AnimatedContainer( duration: const Duration(milliseconds: 120), color: _barHovered ? Colors.white.withValues(alpha: 0.06) : Colors.transparent, child: DragToMoveArea( child: SizedBox( height: 24, child: Stack( children: [ Positioned( left: 0, top: 0, bottom: 0, child: Row( mainAxisSize: MainAxisSize.min, children: [ if (widget.onSettings != null) _BarButton( icon: Icons.settings, onTap: widget.onSettings!, ), if (widget.onSaveCrop != null) _BarButton( icon: Icons.save_outlined, onTap: widget.onSaveCrop!, ), ], ), ), Positioned( right: 0, top: 0, bottom: 0, child: Row( mainAxisSize: MainAxisSize.min, children: [ _BarButton( icon: Icons.horizontal_rule, onTap: () => windowManager.minimize(), ), _BarButton( icon: Icons.close, onTap: () => windowManager.close(), ), ], ), ), ], ), ), ), ), ), ), ); } } class _BarButton extends StatefulWidget { final IconData icon; final VoidCallback onTap; const _BarButton({ required this.icon, required this.onTap, }); @override State<_BarButton> createState() => _BarButtonState(); } class _BarButtonState extends State<_BarButton> { bool _hovered = false; @override Widget build(BuildContext context) { return GestureDetector( onTap: widget.onTap, child: MouseRegion( cursor: SystemMouseCursors.click, onEnter: (_) => setState(() => _hovered = true), onExit: (_) => setState(() => _hovered = false), child: ValueListenableBuilder( valueListenable: HoverColor.notifier, builder: (context, hover, _) => Container( width: 32, height: 24, color: _hovered ? hover.withValues(alpha: 0.8) : Colors.transparent, child: Icon( widget.icon, color: Colors.white, size: 14, ), ), ), ), ); } }