From 9b56cbb64824851298b8218ac68753bbfb6d739c Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Wed, 9 Nov 2022 15:59:00 +0800 Subject: [PATCH] fix: export error on Web platform --- .../example/lib/home_page.dart | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/example/lib/home_page.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/home_page.dart index abb7344943..18d74655ed 100644 --- a/frontend/app_flowy/packages/appflowy_editor/example/lib/home_page.dart +++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/home_page.dart @@ -52,9 +52,7 @@ class _HomePageState extends State { void initState() { super.initState(); - _jsonString = Future.value( - jsonEncode(EditorState.empty().document.toJson()), - ); + _jsonString = rootBundle.loadString('assets/example.json'); _widgetBuilder = (context) => SimpleEditor( jsonString: _jsonString, themeData: _themeData, @@ -259,11 +257,21 @@ class _HomePageState extends State { allowedExtensions: [fileType.extension], type: FileType.custom, ); - final path = result?.files.single.path; - if (path == null) { - return; + var plainText = ''; + if (!kIsWeb) { + final path = result?.files.single.path; + if (path == null) { + return; + } + plainText = await File(path).readAsString(); + } else { + final bytes = result?.files.first.bytes; + if (bytes == null) { + return; + } + plainText = const Utf8Decoder().convert(bytes); } - final plainText = await File(path).readAsString(); + var jsonString = ''; switch (fileType) { case ExportFileType.json: