From 47d03ce1e58d505a231c9a3fd24d0cfa8d5468d4 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 1 Aug 2024 16:09:09 +0800 Subject: [PATCH] :bug: Bug fixes --- lib/controllers/post_editor_controller.dart | 13 +++++++------ lib/screens/posts/post_editor.dart | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/controllers/post_editor_controller.dart b/lib/controllers/post_editor_controller.dart index 38d2026..677b4ae 100644 --- a/lib/controllers/post_editor_controller.dart +++ b/lib/controllers/post_editor_controller.dart @@ -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 value) { type = value['type']; - tags.value = value['tags'].map((x) => x['alias']).toList(); + tags.value = value['tags'].map((x) => x['alias']).toList().cast(); titleController.text = value['title'] ?? ''; descriptionController.text = value['description'] ?? ''; contentController.text = value['content'] ?? ''; diff --git a/lib/screens/posts/post_editor.dart b/lib/screens/posts/post_editor.dart index e763b69..113f42b 100644 --- a/lib/screens/posts/post_editor.dart +++ b/lib/screens/posts/post_editor.dart @@ -93,6 +93,7 @@ class _PostPublishScreenState extends State { } void cancelAction() { + _editorController.localClear(); AppRouter.instance.pop(); } @@ -104,6 +105,7 @@ class _PostPublishScreenState extends State { @override void initState() { super.initState(); + if (widget.edit == null) _editorController.localRead(); _editorController.contentController.addListener(() => setState(() {})); _syncWidget(); }