md5 static method

Future<String?> md5(
  1. String filePath
)

计算文件的Md5, 无论文件多大都不会阻塞主线程

Implementation

static Future<String?> md5(String filePath) async {
  final fileMd5Plugin = BetterFileMd5Plugin();

  String? md5;
  final md5Completer = Completer();

  StreamSubscription subscription = fileMd5Plugin.resultStream.listen((event) {
    md5 = event;
    md5Completer.complete();
  });
  await fileMd5Plugin.fileMd5(filePath: filePath);

  await md5Completer.future;
  subscription.cancel();

  return md5;
}