From 6de318786b45eaa7d020393de227d0c52e530141 Mon Sep 17 00:00:00 2001 From: Marcos Date: Mon, 18 May 2026 23:09:11 +0200 Subject: [PATCH] feat: Update window bootstrap logic and improve note editor UI layout --- lib/platform/window_bootstrap_io.dart | 9 +- lib/screens/note_editor_screen.dart | 293 ++++++++++++++------------ 2 files changed, 169 insertions(+), 133 deletions(-) diff --git a/lib/platform/window_bootstrap_io.dart b/lib/platform/window_bootstrap_io.dart index 62fd7f5..49d2caa 100644 --- a/lib/platform/window_bootstrap_io.dart +++ b/lib/platform/window_bootstrap_io.dart @@ -9,18 +9,21 @@ Future bootstrapWindow() async { } await windowManager.ensureInitialized(); - final Size initialSize = await WindowStateStore.instance.loadWindowSize() ?? const Size(900, 700); final WindowOptions windowOptions = WindowOptions( size: initialSize, minimumSize: Size(400, 600), - center: true, + center: false, titleBarStyle: TitleBarStyle.hidden, ); - windowManager.waitUntilReadyToShow(windowOptions, () async { + await windowManager.waitUntilReadyToShow(windowOptions, () async { + // Re-apply size after the window is ready to ensure it takes effect. + try { + await windowManager.setSize(initialSize); + } catch (_) {} await windowManager.show(); await windowManager.setMinimumSize(const Size(400, 600)); await windowManager.setSize(initialSize); diff --git a/lib/screens/note_editor_screen.dart b/lib/screens/note_editor_screen.dart index dc2955a..f91ba94 100644 --- a/lib/screens/note_editor_screen.dart +++ b/lib/screens/note_editor_screen.dart @@ -1,3 +1,5 @@ +import 'dart:math' as math; + import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -21,7 +23,7 @@ class NoteEditorScreen extends StatefulWidget { return showGeneralDialog( context: context, barrierDismissible: false, - barrierColor: const Color.fromARGB(127, 0, 0, 0).withValues(alpha: 0.5), + barrierColor: Colors.transparent, transitionDuration: const Duration(milliseconds: 200), pageBuilder: (context, animation, secondaryAnimation) { return NoteEditorScreen(note: note); @@ -43,7 +45,7 @@ class _NoteEditorScreenState extends State { void initState() { super.initState(); _isNewNote = widget.note?.id == null; - + if (_isNewNote) { final DateTime now = DateTime.now(); _currentNote = Note( @@ -56,7 +58,7 @@ class _NoteEditorScreenState extends State { } else { _currentNote = widget.note!; } - + _titleController = TextEditingController(text: _currentNote.title); _bodyController = TextEditingController(text: _currentNote.body); } @@ -96,7 +98,10 @@ class _NoteEditorScreenState extends State { builder: (BuildContext context) { return AlertDialog( backgroundColor: const Color(0xFF303134), - title: const Text('Eliminar nota', style: TextStyle(color: Colors.white)), + title: const Text( + 'Eliminar nota', + style: TextStyle(color: Colors.white), + ), content: const Text( '¿Estás seguro de que deseas eliminar esta nota?', style: TextStyle(color: Colors.white70), @@ -104,14 +109,20 @@ class _NoteEditorScreenState extends State { actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), - child: const Text('Cancelar', style: TextStyle(color: Colors.white70)), + child: const Text( + 'Cancelar', + style: TextStyle(color: Colors.white70), + ), ), TextButton( onPressed: () { Navigator.of(context).pop(); Navigator.of(context).pop('delete'); }, - child: const Text('Eliminar', style: TextStyle(color: Colors.red)), + child: const Text( + 'Eliminar', + style: TextStyle(color: Colors.red), + ), ), ], ); @@ -136,137 +147,159 @@ class _NoteEditorScreenState extends State { @override Widget build(BuildContext context) { - return Dialog( - backgroundColor: Colors.transparent, - elevation: 0, - child: Container( - constraints: const BoxConstraints(maxWidth: 600), - decoration: BoxDecoration( - color: const Color.fromRGBO(24, 25, 26, 1), - borderRadius: BorderRadius.circular(16), - border: Border.all(color: Colors.white24, width: 1), - boxShadow: [ - BoxShadow( - color: Colors.black.withValues(alpha: 0.5), - blurRadius: 24, - offset: const Offset(0, 8), - ), - ], - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - // Header con botones y fechas - Container( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - decoration: BoxDecoration( - border: Border( - bottom: BorderSide(color: Colors.white12, width: 1), + return Material( + color: Colors.transparent, + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final double maxWidth = math.min(600, constraints.maxWidth - 48); + final double maxHeight = math.min(constraints.maxHeight * 0.88, 720); + final double overlayTop = MediaQuery.paddingOf(context).top + 32; + + return Stack( + children: [ + Positioned.fill( + top: overlayTop, + child: Container( + color: const Color.fromARGB(127, 0, 0, 0).withValues(alpha: 0.5), ), ), - child: Row( - children: [ - IconButton( - onPressed: _closeWithoutSaving, - icon: const Icon(Icons.close, color: Colors.white70), - tooltip: 'Cerrar sin guardar', - ), - const SizedBox(width: 8), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text( - 'Creado: ${_formatDate(_currentNote.createdAt)}', - style: const TextStyle(color: Colors.white54, fontSize: 12), + SafeArea( + child: Center( + child: Padding( + padding: EdgeInsets.only(top: overlayTop), + child: ConstrainedBox( + constraints: BoxConstraints( + maxWidth: maxWidth, + maxHeight: maxHeight, + ), + child: Container( + decoration: BoxDecoration( + color: const Color.fromRGBO(24, 25, 26, 1), + borderRadius: BorderRadius.circular(16), + border: Border.all(color: Colors.white24, width: 1), + boxShadow: [ + BoxShadow( + color: Colors.black.withValues(alpha: 0.5), + blurRadius: 24, + offset: const Offset(0, 8), + ), + ], ), - if (_currentNote.updatedAt != _currentNote.createdAt) - Text( - 'Modificado: ${_formatDate(_currentNote.updatedAt)}', - style: const TextStyle(color: Colors.white54, fontSize: 12), - ), - ], + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + decoration: BoxDecoration( + border: Border( + bottom: BorderSide(color: Colors.white12, width: 1), + ), + ), + child: Row( + children: [ + IconButton( + onPressed: _closeWithoutSaving, + icon: const Icon(Icons.close, color: Colors.white70), + tooltip: 'Cerrar sin guardar', + ), + const SizedBox(width: 8), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Creado: ${_formatDate(_currentNote.createdAt)}', + style: const TextStyle(color: Colors.white54, fontSize: 12), + ), + if (_currentNote.updatedAt != _currentNote.createdAt) + Text( + 'Modificado: ${_formatDate(_currentNote.updatedAt)}', + style: const TextStyle(color: Colors.white54, fontSize: 12), + ), + ], + ), + ), + ], + ), + ), + Expanded( + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextField( + controller: _titleController, + style: const TextStyle( + color: Colors.white, + fontSize: 28, + fontWeight: FontWeight.bold, + ), + decoration: const InputDecoration( + hintText: 'Título', + hintStyle: TextStyle(color: Colors.white30), + border: InputBorder.none, + contentPadding: EdgeInsets.zero, + ), + ), + const SizedBox(height: 16), + TextField( + controller: _bodyController, + maxLines: null, + style: const TextStyle( + color: Colors.white, + fontSize: 16, + height: 1.6, + ), + decoration: const InputDecoration( + hintText: 'Escribe tu nota...', + hintStyle: TextStyle(color: Colors.white30), + border: InputBorder.none, + contentPadding: EdgeInsets.zero, + ), + ), + ], + ), + ), + ), + ), + Container( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + decoration: BoxDecoration( + border: Border( + top: BorderSide(color: Colors.white12, width: 1), + ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + if (!_isNewNote) + IconButton( + onPressed: _deleteNote, + icon: const Icon(Icons.delete_outline, color: Colors.red), + tooltip: 'Eliminar nota', + ) + else + const SizedBox(width: 48), + FilledButton( + onPressed: _saveNote, + child: const Text('Guardar'), + ), + ], + ), + ), + ], + ), + ), ), ), - ], - ), - ), - // Contenido editable - Expanded( - child: SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.all(20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Título - TextField( - controller: _titleController, - style: const TextStyle( - color: Colors.white, - fontSize: 28, - fontWeight: FontWeight.bold, - ), - decoration: const InputDecoration( - hintText: 'Título', - hintStyle: TextStyle(color: Colors.white30), - border: InputBorder.none, - contentPadding: EdgeInsets.zero, - ), - ), - const SizedBox(height: 16), - // Cuerpo de la nota - TextField( - controller: _bodyController, - maxLines: null, - style: const TextStyle( - color: Colors.white, - fontSize: 16, - height: 1.6, - ), - decoration: const InputDecoration( - hintText: 'Escribe tu nota...', - hintStyle: TextStyle(color: Colors.white30), - border: InputBorder.none, - contentPadding: EdgeInsets.zero, - ), - ), - ], - ), ), ), - ), - // Footer con botones de acción - Container( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - decoration: BoxDecoration( - border: Border( - top: BorderSide(color: Colors.white12, width: 1), - ), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - // Botón de borrar (izquierda) - solo para notas existentes - if (!_isNewNote) - IconButton( - onPressed: _deleteNote, - icon: const Icon(Icons.delete_outline, color: Colors.red), - tooltip: 'Eliminar nota', - ) - else - const SizedBox(width: 48), // Espacio para mantener alineación - // Botón de guardar (derecha) - FilledButton( - onPressed: _saveNote, - child: const Text('Guardar'), - ), - ], - ), - ), - ], - ), + ], + ); + }, ), ); }