🐛 Bug fixes

This commit is contained in:
LittleSheep 2024-08-01 16:09:09 +08:00
parent c41a71388d
commit 47d03ce1e5
2 changed files with 9 additions and 6 deletions

View File

@ -45,7 +45,6 @@ class PostEditorController extends GetxController {
PostEditorController() {
SharedPreferences.getInstance().then((inst) {
_prefs = inst;
localRead();
_saveTimer = Timer.periodic(
const Duration(seconds: 3),
(Timer t) {
@ -144,10 +143,12 @@ class PostEditorController extends GetxController {
}
void localRead() {
if (_prefs.containsKey('post_editor_local_save')) {
isRestoreFromLocal.value = true;
payload = jsonDecode(_prefs.getString('post_editor_local_save')!);
}
SharedPreferences.getInstance().then((inst) {
if (inst.containsKey('post_editor_local_save')) {
isRestoreFromLocal.value = true;
payload = jsonDecode(inst.getString('post_editor_local_save')!);
}
});
}
void localClear() {
@ -259,7 +260,7 @@ class PostEditorController extends GetxController {
set payload(Map<String, dynamic> value) {
type = value['type'];
tags.value = value['tags'].map((x) => x['alias']).toList();
tags.value = value['tags'].map((x) => x['alias']).toList().cast<String>();
titleController.text = value['title'] ?? '';
descriptionController.text = value['description'] ?? '';
contentController.text = value['content'] ?? '';

View File

@ -93,6 +93,7 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
}
void cancelAction() {
_editorController.localClear();
AppRouter.instance.pop();
}
@ -104,6 +105,7 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
@override
void initState() {
super.initState();
if (widget.edit == null) _editorController.localRead();
_editorController.contentController.addListener(() => setState(() {}));
_syncWidget();
}