syncWithFile method

Future<void> syncWithFile()

Implementation

Future<void> syncWithFile() async {
  if (this.fileSyncer != null) {
    return;
  }
  final FileSyncer fileSyncer = FileSyncer();
  fileContentSubscription = fileSyncer.fileContent.listen(_fileContentListener);
  syncerActiveStatusSubscription = fileSyncer.syncerActiveStatus.listen(_syncerStatusListener);
  final bool result = await fileSyncer.syncWithFile();
  if (result) {
    this.fileSyncer = fileSyncer;
    emit(state.copyWith(isSyncedWithFile: true));
  } else {
    await fileContentSubscription?.cancel();
    await syncerActiveStatusSubscription?.cancel();
    fileContentSubscription = null;
    syncerActiveStatusSubscription = null;
  }
}