withGUI method
- {String fileExtension = 'fmtc',
- bool? forceFilePicker,
- BuildContext? context}
Export the store with the platform specifc file picker interface or share sheet/dialog
Set forceFilePicker
to:
null
(default): uses the platform specific file picker on desktop platforms, and the share dialog/sheet on mobile platforms.true
: always force an attempt at using the file picker. This will cause an error on unsupported platforms, and so is not recommended.false
: always force an attempt at using the share sheet. This will cause an error on unsupported platforms, and so is not recommended.
context
(BuildContext) must be specified if using the share sheet, so
it is necessary to pass it unless forceFilePicker
is true
. Will cause
an unhandled null error if not passed when necessary.
If the file already exists, it will be deleted without warning. The default filename includes an 'export_' prefix, which will be removed automatically if present during importing.
Returns true
when successful, otherwise false
when unsuccessful or
unknown.
Implementation
Future<bool> withGUI({
String fileExtension = 'fmtc',
bool? forceFilePicker,
BuildContext? context,
}) async {
if (forceFilePicker ??
Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
final String? outputPath = await FilePicker.platform.saveFile(
dialogTitle: 'Export Cache Store',
fileName: 'export_${storeDirectory.storeName}.$fileExtension',
type: FileType.custom,
allowedExtensions: [fileExtension],
);
if (outputPath == null) return false;
await manual(File(outputPath));
return true;
} else {
final File exportFile = FMTC.instance.rootDirectory.directory >>>
'export_${storeDirectory.storeName}.$fileExtension';
final box = context!.findRenderObject() as RenderBox?;
await manual(exportFile);
final ShareResult result = await Share.shareXFiles(
[XFile(exportFile.absolute.path)],
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
await exportFile.delete();
return result.status == ShareResultStatus.success;
}
}