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

View File

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