efe602a5da
- Added NoteEncryption class for encrypting and decrypting note content using AES-GCM. - Updated NoteRepository to handle synchronization of notes and categories with the server, including encryption of note data before sending. - Introduced SyncRequest and SyncResponse models for managing synchronization data. - Enhanced LocalVaultService to store and retrieve the encryption key. - Modified HomeScreen and SettingsScreen to trigger synchronization after note operations and manage API endpoint settings. - Added SyncStatusIndicator to provide visual feedback on synchronization status in the app title bar. - Created Category model to manage note categories with encryption support. - Updated note model to include UUID, server version, deletion status, and category ID. - Added necessary UI elements for displaying and managing the encryption key in SettingsScreen. - Updated dependencies in pubspec.yaml for cryptography and HTTP handling.
283 lines
7.0 KiB
Dart
283 lines
7.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:notas/platform/app_platform.dart';
|
|
import 'package:notas/widgets/sync_status_indicator.dart';
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
class AppTitleBar extends StatelessWidget {
|
|
const AppTitleBar({
|
|
this.syncStatus = SyncStatus.idle,
|
|
this.syncErrorMessage,
|
|
super.key,
|
|
});
|
|
|
|
final SyncStatus syncStatus;
|
|
final String? syncErrorMessage;
|
|
|
|
@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),
|
|
),
|
|
const SizedBox(width: 8),
|
|
SyncStatusIndicator(
|
|
status: syncStatus,
|
|
errorMessage: syncErrorMessage,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (isLinux) {
|
|
return _KdeTitleBar(
|
|
syncStatus: syncStatus,
|
|
syncErrorMessage: syncErrorMessage,
|
|
);
|
|
}
|
|
|
|
return SizedBox(
|
|
height: 40,
|
|
child: WindowCaption(
|
|
brightness: Brightness.dark,
|
|
title: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Text('Mis Notas', style: TextStyle(color: Colors.white)),
|
|
const SizedBox(width: 8),
|
|
SyncStatusIndicator(
|
|
status: syncStatus,
|
|
errorMessage: syncErrorMessage,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _KdeTitleBar extends StatefulWidget {
|
|
const _KdeTitleBar({
|
|
this.syncStatus = SyncStatus.idle,
|
|
this.syncErrorMessage,
|
|
});
|
|
|
|
final SyncStatus syncStatus;
|
|
final String? syncErrorMessage;
|
|
|
|
@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(
|
|
left: 0,
|
|
top: 0,
|
|
bottom: 0,
|
|
child: IgnorePointer(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: Center(
|
|
child: SyncStatusIndicator(
|
|
status: widget.syncStatus,
|
|
errorMessage: widget.syncErrorMessage,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
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,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|