avoid_slow_async_io
avoid_slow_async_io
동일한 동기 버전이 존재하는 비동기 dart:io 메서드를 사용하면 성능이 느려질 수 있어요. 이 규칙이 어떤 메서드들을 경고하고, 어떻게 고치면 되는지 정리해 드릴게요.
출처: 원문
본문
진단 메시지
Use of an async 'dart:io' method.
설명
분석기는 동기 버전이 따로 존재하는 비동기 파일 I/O 메서드를 사용할 때 이 진단을 만들어요.
경고 대상이 되는 비동기 메서드들은 다음과 같아요.
Directory.existsDirectory.statFile.lastModifiedFile.existsFile.statFileSystemEntity.isDirectoryFileSystemEntity.isFileFileSystemEntity.isLinkFileSystemEntity.type
예시
다음 코드는 비동기 메서드 exists를 호출하기 때문에 이 진단이 발생해요.
import 'dart:io';
Future<void> g(File f) async {
await f.exists();
}
일반적인 해결 방법
동기 버전의 메서드를 사용하면 돼요.
import 'dart:io';
void g(File f) {
f.existsSync();
}