refactor: Improve code readability by formatting and simplifying widget structures
This commit is contained in:
@@ -116,8 +116,8 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
|
||||
RelativeRect _menuRectFromContext(BuildContext anchorContext) {
|
||||
final RenderBox button = anchorContext.findRenderObject()! as RenderBox;
|
||||
final RenderBox overlay = Overlay.of(anchorContext).context.findRenderObject()!
|
||||
as RenderBox;
|
||||
final RenderBox overlay =
|
||||
Overlay.of(anchorContext).context.findRenderObject()! as RenderBox;
|
||||
final Offset topLeft = button.localToGlobal(Offset.zero, ancestor: overlay);
|
||||
final Offset bottomRight = button.localToGlobal(
|
||||
button.size.bottomRight(Offset.zero),
|
||||
@@ -125,12 +125,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
);
|
||||
|
||||
return RelativeRect.fromRect(
|
||||
Rect.fromLTRB(
|
||||
topLeft.dx,
|
||||
topLeft.dy,
|
||||
bottomRight.dx,
|
||||
bottomRight.dy,
|
||||
),
|
||||
Rect.fromLTRB(topLeft.dx, topLeft.dy, bottomRight.dx, bottomRight.dy),
|
||||
Offset.zero & overlay.size,
|
||||
);
|
||||
}
|
||||
@@ -157,7 +152,8 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
isDirty: true,
|
||||
);
|
||||
|
||||
final bool hasChanges = draft.title != _baselineNote.title ||
|
||||
final bool hasChanges =
|
||||
draft.title != _baselineNote.title ||
|
||||
draft.body != _baselineNote.body ||
|
||||
draft.categoryId != _baselineNote.categoryId;
|
||||
|
||||
@@ -206,10 +202,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
for (final Category category in widget.categories)
|
||||
PopupMenuItem<Category?>(
|
||||
value: category,
|
||||
child: Text(category.name),
|
||||
),
|
||||
PopupMenuItem<Category?>(value: category, child: Text(category.name)),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -273,8 +266,11 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEditorBody() {
|
||||
Widget _buildEditorBody({required bool embedded}) {
|
||||
final AppPalette palette = _paletteOf(context);
|
||||
final BoxBorder? bodyBorder = embedded
|
||||
? null
|
||||
: Border.all(color: palette.border);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
@@ -309,7 +305,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
decoration: BoxDecoration(
|
||||
color: palette.transparent,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: palette.border),
|
||||
border: bodyBorder,
|
||||
),
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: QuillEditor.basic(
|
||||
@@ -372,18 +368,16 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
|
||||
final Widget editor = Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: _buildEditorBody(),
|
||||
child: _buildEditorBody(embedded: widget.embedded),
|
||||
);
|
||||
|
||||
if (widget.embedded) {
|
||||
return Container(color: palette.cardBackground, child: editor);
|
||||
return editor;
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: palette.cardBackground,
|
||||
appBar: AppBar(
|
||||
title: const Text('Editar nota'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Editar nota')),
|
||||
body: SafeArea(child: editor),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user