Closed jfaltis closed 2 years ago
Fixed on v0.4.0
.
final parentFolder = openDocumentTree();
if (parentFolder == null) {
return; // No folder was selected
}
const kTxtMimeType = 'text/plain';
final createdFile = await createFile(
parentFolder,
mimeType: kTxtMimeType,
displayName: 'My Text File',
content: 'File data, can be anything depending on mime type!',
);
Thanks for opening the question. Any other questions let me know.
Cool, keep up the good work. How do you leverage this plugin to write to an existing file? Will you be able to use the dart File API or can/should you use
final createdFile = await createFile(
parentFolder,
mimeType: kTxtMimeType,
displayName: 'My Text File',
content: 'File data, can be anything depending on mime type!',
);
to overwrite an existing file?
The plugin example seems to be broken in v0.4.0
[jona@jona example]$ flutter run
Running "flutter pub get" in example... 1.123ms
Launching lib/main.dart on in debug mode...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
lib/main.dart:2:8: Error: Error when reading 'lib/screens/persisted_uris/persisted_uri_list.dart': No such file or directory
import 'screens/persisted_uris/persisted_uri_list.dart';
^
lib/main.dart:17:36: Error: Method not found: 'PersistedUriList'.
return const MaterialApp(home: PersistedUriList());
^^^^^^^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script '/opt/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1156
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/opt/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 11s
Running Gradle task 'assembleDebug'... 11,7s
Exception: Gradle task assembleDebug failed with exit code 1
I tried rn but to override seems it's not supported yet.
I'll create another feature-request issue to wrap this feature to you, to us.
Thanks for requesting it.
Also, I fixed the error related to the plugin example project and added a simple GitHub action that will block any future attempts to publish with an error like that, sorry for it.
Soon I'll release a new version v0.4.1
to make this fix available on pub.dev
.
For now you can try this workaround:
exists(...)
and delete(...)
method.bytes
or content
using createFile(...)
method.This will "update" the file.
I'm working on this issue #79 to add updateFile
method which doesn't force you to delete the file so this proposal above is just a temporary workaround.
I noticed that you are not closing the OutputStream when creating a file. Should I fix this and include it in my PR or should it be done seperately?
You can do it in separated branches/PRs, please.
Would be great if we could publish the OutputStream
fix as patch update and your new feature as minor update.
Closing since its already implemented by #85.
How would you use this plugin to write to a file in a folder which access was granted through SAF?
I tried to use the File class and writeAsString from dart:io but I was not able to obtain a proper path through the Uri with toFilePath().
causes
And once while testing toFilePath() did not cause an error. Opening the file did however.
It would be great to extend the plugin example with this functionality.