242 lines
5.7 KiB
Dart
242 lines
5.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:notas/platform/app_platform.dart';
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
class AppTitleBar extends StatelessWidget {
|
|
const AppTitleBar({
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (isAndroid || isIOS) {
|
|
return const SizedBox(height: 10);
|
|
}
|
|
|
|
if (isMacOS) {
|
|
return SizedBox(
|
|
height: 28,
|
|
child: Center(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Text(
|
|
'Mis Notas',
|
|
style: TextStyle(color: Colors.white70, fontSize: 13),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (isLinux) {
|
|
return const _KdeTitleBar();
|
|
}
|
|
|
|
return SizedBox(
|
|
height: 40,
|
|
child: WindowCaption(
|
|
brightness: Brightness.dark,
|
|
title: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Text('Mis Notas', style: TextStyle(color: Colors.white)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _KdeTitleBar extends StatefulWidget {
|
|
const _KdeTitleBar();
|
|
|
|
@override
|
|
State<_KdeTitleBar> createState() => _KdeTitleBarState();
|
|
}
|
|
|
|
class _KdeTitleBarState extends State<_KdeTitleBar> with WindowListener {
|
|
bool _isFullScreen = false;
|
|
bool _isMaximized = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
if (isDesktop) {
|
|
windowManager.addListener(this);
|
|
_refreshWindowState();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
if (isDesktop) {
|
|
windowManager.removeListener(this);
|
|
}
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _refreshWindowState() async {
|
|
final bool isFullScreen = await windowManager.isFullScreen();
|
|
final bool isMaximized = await windowManager.isMaximized();
|
|
|
|
if (!mounted) {
|
|
return;
|
|
}
|
|
|
|
setState(() {
|
|
_isFullScreen = isFullScreen;
|
|
_isMaximized = isMaximized;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onWindowEnterFullScreen() {
|
|
setState(() {
|
|
_isFullScreen = true;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onWindowLeaveFullScreen() {
|
|
setState(() {
|
|
_isFullScreen = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onWindowMaximize() {
|
|
setState(() {
|
|
_isMaximized = true;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onWindowUnmaximize() {
|
|
setState(() {
|
|
_isMaximized = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final IconData maximizeIcon =
|
|
(_isFullScreen || _isMaximized) ? Icons.fullscreen_exit : Icons.fullscreen;
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
border: Border(
|
|
bottom: BorderSide(
|
|
color: Colors.white.withValues(alpha: 0.12),
|
|
width: 0.5,
|
|
),
|
|
),
|
|
),
|
|
child: SizedBox(
|
|
height: 32,
|
|
child: Stack(
|
|
children: [
|
|
const DragToMoveArea(
|
|
child: SizedBox.expand(),
|
|
),
|
|
const IgnorePointer(
|
|
child: Center(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
'Mis Notas',
|
|
style: TextStyle(
|
|
color: Color.fromARGB(255, 163, 163, 163),
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
right: 0,
|
|
top: 0,
|
|
bottom: 0,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
_KdeButton(
|
|
icon: Icons.minimize,
|
|
onPressed: () => windowManager.minimize(),
|
|
),
|
|
_KdeButton(
|
|
icon: maximizeIcon,
|
|
onPressed: () async {
|
|
if (await windowManager.isFullScreen()) {
|
|
await windowManager.setFullScreen(false);
|
|
} else if (await windowManager.isMaximized()) {
|
|
await windowManager.unmaximize();
|
|
} else {
|
|
await windowManager.maximize();
|
|
}
|
|
},
|
|
),
|
|
_KdeButton(
|
|
icon: Icons.close,
|
|
isClose: true,
|
|
onPressed: () => windowManager.close(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _KdeButton extends StatelessWidget {
|
|
const _KdeButton({
|
|
required this.icon,
|
|
required this.onPressed,
|
|
this.isClose = false,
|
|
});
|
|
|
|
final IconData icon;
|
|
final VoidCallback onPressed;
|
|
final bool isClose;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MouseRegion(
|
|
cursor: SystemMouseCursors.click,
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: onPressed,
|
|
child: SizedBox(
|
|
width: 32,
|
|
height: double.infinity,
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkResponse(
|
|
highlightShape: BoxShape.circle,
|
|
containedInkWell: false,
|
|
radius: 10,
|
|
hoverColor: isClose ? Colors.red : Colors.white.withValues(alpha: 0.08),
|
|
onTap: onPressed,
|
|
child: Center(
|
|
child: Icon(
|
|
icon,
|
|
color: Colors.white70,
|
|
size: 16,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|