feat: Refactor NoteEditorScreen build method for improved readability and maintainability
This commit is contained in:
@@ -345,170 +345,10 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Widget _buildEditorContent({required bool isMobile}) {
|
||||||
Widget build(BuildContext context) {
|
final double titleSpacing = isMobile ? 16.0 : 8.0;
|
||||||
if (_isMobileLayout) {
|
|
||||||
return Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: SafeArea(
|
|
||||||
child: Container(
|
|
||||||
color: const Color.fromARGB(255, 24, 25, 26),
|
|
||||||
child: Column(
|
|
||||||
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: 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),
|
|
||||||
Expanded(
|
|
||||||
child: TextField(
|
|
||||||
controller: _bodyController,
|
|
||||||
keyboardType: TextInputType.multiline,
|
|
||||||
maxLines: null,
|
|
||||||
expands: true,
|
|
||||||
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'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return LayoutBuilder(
|
return Column(
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
|
||||||
final double maxWidth = math.min(constraints.maxWidth - 32, 600);
|
|
||||||
final double maxHeight = math.min(constraints.maxHeight - 32, 720);
|
|
||||||
|
|
||||||
return Stack(
|
|
||||||
children: [
|
|
||||||
Positioned.fill(
|
|
||||||
child: ModalBarrier(
|
|
||||||
dismissible: false,
|
|
||||||
color: const Color.fromARGB(54, 0, 0, 0).withValues(alpha: 0.5),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned.fill(
|
|
||||||
child: Center(
|
|
||||||
child: SizedBox(
|
|
||||||
width: maxWidth,
|
|
||||||
height: maxHeight,
|
|
||||||
child: Material(
|
|
||||||
color: const Color.fromRGBO(24, 25, 26, 1),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
side: BorderSide(color: Colors.white24, width: 1),
|
|
||||||
),
|
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
@@ -546,8 +386,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
|||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (_currentNote.updatedAt !=
|
if (_currentNote.updatedAt != _currentNote.createdAt)
|
||||||
_currentNote.createdAt)
|
|
||||||
Text(
|
Text(
|
||||||
'Modificado: ${_formatDate(_currentNote.updatedAt)}',
|
'Modificado: ${_formatDate(_currentNote.updatedAt)}',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
@@ -581,7 +420,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
|||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
SizedBox(height: titleSpacing),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _bodyController,
|
controller: _bodyController,
|
||||||
@@ -639,8 +478,50 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (_isMobileLayout) {
|
||||||
|
return Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: SafeArea(
|
||||||
|
child: Container(
|
||||||
|
color: const Color.fromARGB(255, 24, 25, 26),
|
||||||
|
child: _buildEditorContent(isMobile: true),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
|
final double maxWidth = math.min(constraints.maxWidth - 32, 600);
|
||||||
|
final double maxHeight = math.min(constraints.maxHeight - 32, 720);
|
||||||
|
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
Positioned.fill(
|
||||||
|
child: ModalBarrier(
|
||||||
|
dismissible: false,
|
||||||
|
color: const Color.fromARGB(54, 0, 0, 0).withValues(alpha: 0.5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned.fill(
|
||||||
|
child: Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: maxWidth,
|
||||||
|
height: maxHeight,
|
||||||
|
child: Material(
|
||||||
|
color: const Color.fromRGBO(24, 25, 26, 1),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
side: BorderSide(color: Colors.white24, width: 1),
|
||||||
|
),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
child: _buildEditorContent(isMobile: false),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user