Add writeToFile, writeToFileAsBytes, writeToFileAsString#85
Add writeToFile, writeToFileAsBytes, writeToFileAsString#85alexcmgit merged 2 commits intolibsrcdev:masterfrom
Conversation
| result: MethodChannel.Result, | ||
| uri: String, | ||
| content: ByteArray, | ||
| mode: String, |
lib/src/saf/saf.dart
Outdated
| } | ||
|
|
||
| /// {@template sharedstorage.saf.writeToFile} | ||
| /// Convenient method to write to a file using either String or raw bytes. |
There was a problem hiding this comment.
| /// Convenient method to write to a file using either String or raw bytes. | |
| /// Convenient method to write to a file using either [String] or raw bytes [Uint8List]. |
You can also apply this change for createFile function.
lib/src/saf/saf.dart
Outdated
| } | ||
|
|
||
| final args = <String, dynamic>{ | ||
| 'uri': uri.toString(), |
There was a problem hiding this comment.
| 'uri': uri.toString(), | |
| 'uri': '$uri', |
lib/src/saf/saf.dart
Outdated
| var writeMode = 'wt'; | ||
|
|
||
| if (mode == FileMode.append || mode == FileMode.writeOnlyAppend) { | ||
| writeMode = 'wa'; | ||
| } |
There was a problem hiding this comment.
| var writeMode = 'wt'; | |
| if (mode == FileMode.append || mode == FileMode.writeOnlyAppend) { | |
| writeMode = 'wa'; | |
| } | |
| final writeMode = | |
| mode == FileMode.append || mode == FileMode.writeOnlyAppend ? 'wa' : 'wt'; |
lib/src/saf/saf.dart
Outdated
|
|
||
| /// {@template sharedstorage.saf.writeToFileAsString} | ||
| /// Convenient method to write to a file. | ||
| /// using `content` as String instead Uint8List. |
There was a problem hiding this comment.
| /// using `content` as String instead Uint8List. | |
| /// using `content` as [String] instead [Uint8List]. |
You can also apply this change for createFileAsString function.
|
|
||
| Given the document uri, opens the file in the specified `mode` and writes the `bytes` to it. | ||
|
|
||
| `mode` represents the mode in which the file will be opened for writing. Use `FileMode.write` for truncating and `FileMode.append` for appending to the file. |
There was a problem hiding this comment.
| `mode` represents the mode in which the file will be opened for writing. Use `FileMode.write` for truncating and `FileMode.append` for appending to the file. | |
| `mode` represents the mode in which the file will be opened for writing. Use `FileMode.write` for truncating (overwrite) and `FileMode.append` for appending to the file. |
|
|
||
|
|
| ); | ||
|
|
||
| /// Write to a file using a [Uint8List] as file contents [bytes] | ||
| final DocumentFile? createdFile = writeToFile( |
There was a problem hiding this comment.
| final DocumentFile? createdFile = writeToFile( | |
| final bool? success = writeToFile( |
Guess this function returns a boolean representing the whether or not the operation was successful, if not let me know but I think it was just a typo.
| ); | ||
|
|
||
| /// Append to a file using a [Uint8List] as file contents [bytes] | ||
| final DocumentFile? createdFile = writeToFile( |
There was a problem hiding this comment.
| final DocumentFile? createdFile = writeToFile( | |
| final bool? success = writeToFile( |
Guess this function returns a boolean representing the whether or not the operation was successful, if not let me know but I think it was just a typo.
|
Great work, I tested and it works gracefully on Android 10+ (Tested on Samsung A30 and POCO M4 PRO). I left some comments refering to small fixes related to the API documentation and code formatting. If you think something doesn't make sense just reply on it and lets discuss. You can also pull this branch: Thanks for the hard work! |
|
I am happy to hear that. I agree with all your changes! |
|
You did it! Happy to see your contribution here, I'll release on Any other requests or suggestions let me know! |

This PR implements #61.