avoid_ slow_ async_ io
Use of an async 'dart:io' method.
Description
#The analyzer produces this diagnostic when an asynchronous file I/O method with a synchronous equivalent is used.
The following are the specific flagged asynchronous methods:
Directory.exists
Directory.stat
File.lastModified
File.exists
File.stat
FileSystemEntity.isDirectory
FileSystemEntity.isFile
FileSystemEntity.isLink
FileSystemEntity.type
Example
#
The following code produces this diagnostic because the async method
exists
is invoked:
import 'dart:io';
Future<void> g(File f) async {
await f.exists();
}
Common fixes
#Use the synchronous version of the method:
import 'dart:io';
void g(File f) {
f.existsSync();
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.