mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-16 00:14:08 +08:00
Try implementing State properly
I think I understand the 'State' class a bit better. But I need to cross check.
This commit is contained in:
@ -50,7 +50,7 @@ class ChecklistEditor extends StatefulWidget implements Editor {
|
||||
|
||||
@override
|
||||
ChecklistEditorState createState() {
|
||||
return ChecklistEditorState(note);
|
||||
return ChecklistEditorState();
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,28 +61,44 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
||||
var focusNodes = <UniqueKey, FocusScopeNode>{};
|
||||
var keys = <UniqueKey, ChecklistItem>{};
|
||||
|
||||
TextEditingController _titleTextController = TextEditingController();
|
||||
var _titleTextController = TextEditingController();
|
||||
bool _noteModified;
|
||||
|
||||
ChecklistEditorState(Note note) {
|
||||
_titleTextController = TextEditingController(text: note.title);
|
||||
checklist = Checklist(note);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_init();
|
||||
}
|
||||
|
||||
void _init() {
|
||||
var note = widget.note;
|
||||
_titleTextController = TextEditingController(text: note.title);
|
||||
checklist = Checklist(note);
|
||||
|
||||
_noteModified = widget.noteModified;
|
||||
|
||||
if (checklist.items.isEmpty) {
|
||||
var item = checklist.buildItem(false, "");
|
||||
checklist.addItem(item);
|
||||
}
|
||||
focusNodes = {};
|
||||
keys = {};
|
||||
for (var item in checklist.items) {
|
||||
keys[UniqueKey()] = item;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChecklistEditor oldWidget) {
|
||||
if (oldWidget.noteModified != widget.noteModified) {
|
||||
_noteModified = widget.noteModified;
|
||||
}
|
||||
if (oldWidget.note != widget.note) {
|
||||
_init();
|
||||
}
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_titleTextController.dispose();
|
||||
@ -91,15 +107,6 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChecklistEditor oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
|
||||
if (oldWidget.noteModified != widget.noteModified) {
|
||||
_noteModified = widget.noteModified;
|
||||
}
|
||||
}
|
||||
|
||||
UniqueKey _getKey(ChecklistItem item) {
|
||||
for (var e in keys.entries) {
|
||||
if (e.value == item) {
|
||||
|
@ -57,7 +57,7 @@ class JournalEditorState extends State<JournalEditor>
|
||||
with DisposableChangeNotifier
|
||||
implements EditorState {
|
||||
Note note;
|
||||
TextEditingController _textController = TextEditingController();
|
||||
var _textController = TextEditingController();
|
||||
bool _noteModified;
|
||||
|
||||
EditorHeuristics _heuristics;
|
||||
|
Reference in New Issue
Block a user