Avoid mutating the state while building the Editor's bottom bar

getNote() mutates the state
This commit is contained in:
Vishesh Handa
2020-05-05 12:33:20 +02:00
parent b17c184900
commit b26cfe8b81
5 changed files with 11 additions and 6 deletions

View File

@ -161,7 +161,8 @@ class ChecklistEditorState extends State<ChecklistEditor>
], ],
), ),
bottomNavigationBar: Builder( bottomNavigationBar: Builder(
builder: (context) => buildEditorBottonBar(context, widget, this), builder: (context) =>
buildEditorBottonBar(context, widget, this, widget.note.parent),
), ),
); );
} }

View File

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/core/note.dart';
import 'package:gitjournal/core/notes_folder_fs.dart';
import 'package:gitjournal/error_reporting.dart'; import 'package:gitjournal/error_reporting.dart';
import 'package:share/share.dart'; import 'package:share/share.dart';
@ -99,9 +100,9 @@ Widget buildEditorBottonBar(
BuildContext context, BuildContext context,
Editor editor, Editor editor,
EditorState editorState, EditorState editorState,
NotesFolderFS parentFolder,
) { ) {
var note = editorState.getNote(); var folderName = parentFolder.pathSpec();
var folderName = note.parent.pathSpec();
if (folderName.isEmpty) { if (folderName.isEmpty) {
folderName = "Root Folder"; folderName = "Root Folder";
} }

View File

@ -86,7 +86,8 @@ class JournalEditorState extends State<JournalEditor> implements EditorState {
appBar: buildEditorAppBar(widget, this, noteModified: _noteModified), appBar: buildEditorAppBar(widget, this, noteModified: _noteModified),
body: editor, body: editor,
bottomNavigationBar: Builder( bottomNavigationBar: Builder(
builder: (context) => buildEditorBottonBar(context, widget, this), builder: (context) =>
buildEditorBottonBar(context, widget, this, note.parent),
), ),
); );
} }

View File

@ -117,7 +117,8 @@ class MarkdownEditorState extends State<MarkdownEditor> implements EditorState {
), ),
body: body, body: body,
bottomNavigationBar: Builder( bottomNavigationBar: Builder(
builder: (context) => buildEditorBottonBar(context, widget, this), builder: (context) =>
buildEditorBottonBar(context, widget, this, note.parent),
), ),
); );
} }

View File

@ -83,7 +83,8 @@ class RawEditorState extends State<RawEditor> implements EditorState {
appBar: buildEditorAppBar(widget, this, noteModified: _noteModified), appBar: buildEditorAppBar(widget, this, noteModified: _noteModified),
body: editor, body: editor,
bottomNavigationBar: Builder( bottomNavigationBar: Builder(
builder: (context) => buildEditorBottonBar(context, widget, this), builder: (context) =>
buildEditorBottonBar(context, widget, this, note.parent),
), ),
); );
} }