mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: implement initalize editor from json and markdown
This commit is contained in:
parent
9a908abfdd
commit
853be71bf5
@ -99,8 +99,12 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
// Decoder Demo
|
||||
_buildSeparator(context, 'Decoder Demo'),
|
||||
_buildListTile(context, 'Import From JSON', () {}),
|
||||
_buildListTile(context, 'Import From Markdown', () {}),
|
||||
_buildListTile(context, 'Import From JSON', () {
|
||||
_importFile(ExportFileType.json);
|
||||
}),
|
||||
_buildListTile(context, 'Import From Markdown', () {
|
||||
_importFile(ExportFileType.markdown);
|
||||
}),
|
||||
|
||||
// Theme Demo
|
||||
_buildSeparator(context, 'Theme Demo'),
|
||||
@ -213,4 +217,32 @@ class _HomePageState extends State<HomePage> {
|
||||
..click();
|
||||
}
|
||||
}
|
||||
|
||||
void _importFile(ExportFileType fileType) async {
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
allowMultiple: false,
|
||||
allowedExtensions: [fileType.extension],
|
||||
type: FileType.custom,
|
||||
);
|
||||
final path = result?.files.single.path;
|
||||
if (path == null) {
|
||||
return;
|
||||
}
|
||||
final plainText = await File(path).readAsString();
|
||||
var jsonString = '';
|
||||
switch (fileType) {
|
||||
case ExportFileType.json:
|
||||
jsonString = jsonEncode(plainText);
|
||||
break;
|
||||
case ExportFileType.markdown:
|
||||
jsonString = jsonEncode(markdownToDocument(plainText).toJson());
|
||||
break;
|
||||
case ExportFileType.html:
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
_loadEditor(context, Future<String>.value(jsonString));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user