mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-18 01:13:06 +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
|
@override
|
||||||
ChecklistEditorState createState() {
|
ChecklistEditorState createState() {
|
||||||
return ChecklistEditorState(note);
|
return ChecklistEditorState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,28 +61,44 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
|||||||
var focusNodes = <UniqueKey, FocusScopeNode>{};
|
var focusNodes = <UniqueKey, FocusScopeNode>{};
|
||||||
var keys = <UniqueKey, ChecklistItem>{};
|
var keys = <UniqueKey, ChecklistItem>{};
|
||||||
|
|
||||||
TextEditingController _titleTextController = TextEditingController();
|
var _titleTextController = TextEditingController();
|
||||||
bool _noteModified;
|
bool _noteModified;
|
||||||
|
|
||||||
ChecklistEditorState(Note note) {
|
|
||||||
_titleTextController = TextEditingController(text: note.title);
|
|
||||||
checklist = Checklist(note);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _init() {
|
||||||
|
var note = widget.note;
|
||||||
|
_titleTextController = TextEditingController(text: note.title);
|
||||||
|
checklist = Checklist(note);
|
||||||
|
|
||||||
_noteModified = widget.noteModified;
|
_noteModified = widget.noteModified;
|
||||||
|
|
||||||
if (checklist.items.isEmpty) {
|
if (checklist.items.isEmpty) {
|
||||||
var item = checklist.buildItem(false, "");
|
var item = checklist.buildItem(false, "");
|
||||||
checklist.addItem(item);
|
checklist.addItem(item);
|
||||||
}
|
}
|
||||||
|
focusNodes = {};
|
||||||
|
keys = {};
|
||||||
for (var item in checklist.items) {
|
for (var item in checklist.items) {
|
||||||
keys[UniqueKey()] = item;
|
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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_titleTextController.dispose();
|
_titleTextController.dispose();
|
||||||
@ -91,15 +107,6 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(ChecklistEditor oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
|
|
||||||
if (oldWidget.noteModified != widget.noteModified) {
|
|
||||||
_noteModified = widget.noteModified;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UniqueKey _getKey(ChecklistItem item) {
|
UniqueKey _getKey(ChecklistItem item) {
|
||||||
for (var e in keys.entries) {
|
for (var e in keys.entries) {
|
||||||
if (e.value == item) {
|
if (e.value == item) {
|
||||||
|
@ -57,7 +57,7 @@ class JournalEditorState extends State<JournalEditor>
|
|||||||
with DisposableChangeNotifier
|
with DisposableChangeNotifier
|
||||||
implements EditorState {
|
implements EditorState {
|
||||||
Note note;
|
Note note;
|
||||||
TextEditingController _textController = TextEditingController();
|
var _textController = TextEditingController();
|
||||||
bool _noteModified;
|
bool _noteModified;
|
||||||
|
|
||||||
EditorHeuristics _heuristics;
|
EditorHeuristics _heuristics;
|
||||||
|
Reference in New Issue
Block a user