feat: export JSON in mobile and update mobile_example.json (#515)
* feat: add export json in mobile * chore: update editor style and example json for mobile showcase * chore: improve text content
This commit is contained in:
parent
adb05d4c49
commit
897033035c
1 changed files with 33 additions and 151 deletions
|
|
@ -11,6 +11,7 @@ import 'package:file_picker/file_picker.dart';
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
enum ExportFileType {
|
||||
|
|
@ -290,7 +291,31 @@ class _HomePageState extends State<HomePage> {
|
|||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
if (!kIsWeb) {
|
||||
if (kIsWeb) {
|
||||
final blob = html.Blob([result], 'text/plain', 'native');
|
||||
html.AnchorElement(
|
||||
href: html.Url.createObjectUrlFromBlob(blob).toString(),
|
||||
)
|
||||
..setAttribute('download', 'document.${fileType.extension}')
|
||||
..click();
|
||||
} else if (PlatformExtension.isMobile) {
|
||||
final appStorageDirectory = await getApplicationDocumentsDirectory();
|
||||
|
||||
final path = File(
|
||||
'${appStorageDirectory.path}/${DateTime.now()}.${fileType.extension}',
|
||||
);
|
||||
await path.writeAsString(result);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'This document is saved to the ${appStorageDirectory.path}',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// for desktop
|
||||
final path = await FilePicker.platform.saveFile(
|
||||
fileName: 'document.${fileType.extension}',
|
||||
);
|
||||
|
|
@ -304,13 +329,6 @@ class _HomePageState extends State<HomePage> {
|
|||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final blob = html.Blob([result], 'text/plain', 'native');
|
||||
html.AnchorElement(
|
||||
href: html.Url.createObjectUrlFromBlob(blob).toString(),
|
||||
)
|
||||
..setAttribute('download', 'document.${fileType.extension}')
|
||||
..click();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue