Skip to content

Commit 9b56cbb

Browse files
committed
fix: export error on Web platform
1 parent e20ce90 commit 9b56cbb

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

frontend/app_flowy/packages/appflowy_editor/example/lib/home_page.dart

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ class _HomePageState extends State<HomePage> {
5252
void initState() {
5353
super.initState();
5454

55-
_jsonString = Future<String>.value(
56-
jsonEncode(EditorState.empty().document.toJson()),
57-
);
55+
_jsonString = rootBundle.loadString('assets/example.json');
5856
_widgetBuilder = (context) => SimpleEditor(
5957
jsonString: _jsonString,
6058
themeData: _themeData,
@@ -259,11 +257,21 @@ class _HomePageState extends State<HomePage> {
259257
allowedExtensions: [fileType.extension],
260258
type: FileType.custom,
261259
);
262-
final path = result?.files.single.path;
263-
if (path == null) {
264-
return;
260+
var plainText = '';
261+
if (!kIsWeb) {
262+
final path = result?.files.single.path;
263+
if (path == null) {
264+
return;
265+
}
266+
plainText = await File(path).readAsString();
267+
} else {
268+
final bytes = result?.files.first.bytes;
269+
if (bytes == null) {
270+
return;
271+
}
272+
plainText = const Utf8Decoder().convert(bytes);
265273
}
266-
final plainText = await File(path).readAsString();
274+
267275
var jsonString = '';
268276
switch (fileType) {
269277
case ExportFileType.json:

0 commit comments

Comments
 (0)