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

View File

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