You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import 'dart:io';
main() async {
// Get the system temp directory.
var systemTempDir = Directory.systemTemp;
// Create a file.
var file = await new File('${systemTempDir.path}/foo.txt').create();
// Prints path ending with `foo.txt`.
print('The path is ${file.path}');
// Rename the file.
await file.rename('${systemTempDir.path}/bar.txt');
// Prints path ending with `bar.txt`.
print('The path is ${file.path}');
}
It incorrectly says that the original File object will have the updated path, when the API for rename() shows that it actually returns a new File instance for the renamed file.
The last lines should actually be something like:
// Rename the file.
var renamedFile = await file.rename('${systemTempDir.path}/bar.txt');
// Prints path ending with `bar.txt`.
print('The path is ${renamedFile.path}');
The text was updated successfully, but these errors were encountered:
Unfortunately, we're planning to remove the cookbook, since it's not well tested and has been rotting. That said, the repo it's taken from is open source, and it wouldn't hurt to fix the sample there:
Per this SO question, the Renaming a file, directory, or symlink example is wrong. The example code is:
It incorrectly says that the original
File
object will have the updated path, when the API forrename()
shows that it actually returns a newFile
instance for the renamed file.The last lines should actually be something like:
The text was updated successfully, but these errors were encountered: