getData static method

Future<List<int>?> getData({
  1. required String path,
})

读取文件数据

path 文件路径 返回文件的字节数据,如果读取失败则返回null

Implementation

static Future<List<int>?> getData({required String path}) async {
  if (path.isEmpty || kIsWeb) {
    return null;
  }

  try {
    final file = File(path);
    if (await file.exists()) {
      return await file.readAsBytes();
    }
    return null;
  } catch (e) {
    developer.log('读取文件失败: $e');
    return null;
  }
}