Interview frequency: …
Short answer
Get an app-specific path through path_provider, then use dart:io to read and write asynchronously while handling disk failures.
Explanation
A file suits cases where the unit you read and write is a document or a binary blob such as an image or an export. Do not assume a fixed path specific to one system; request a directory appropriate to the platform, and consider atomic writes, file size, and permissions. If you need to search inside many fields or relations, the file alone is not a suitable boundary.
Code example
final directory = await getApplicationDocumentsDirectory();
final file = File("${directory.path}/draft.json");
await file.writeAsString(jsonText);Common mistakes
- Hardcoding a path such as /data or C:\ in shared code.
- Performing a synchronous write on the UI thread for a large file.
- Treating the existence of the file as proof that its content is always valid.