处理用户在Zefyr中删除图像的情况

问题描述 投票:0回答:1

我已经根据the docs here挂接了我的图像委托。唯一值得注意的更改是,我的pickImage函数改为使用filePicker并立即存储用户的图像,并将地址返回到Firebase中的图像。

@override
Future<String> pickImage(bool isGallery) async {
  if (!isGallery) return null;

  final filePath = await FilePicker.getFilePath(type: FileType.IMAGE);

  if (filePath == null) return null;

  final fileName = path.basename(filePath);
  final iconRef = storageReference.child('page_images').child(fileName);
  final uploadTask = iconRef.putFile(File(filePath));

  final snapshot = await uploadTask.onComplete;
  final downloadUrl = await snapshot.ref.getDownloadURL();

  return downloadUrl;
}

找出用户何时删除此图像以便我也可以从存储中删除它的一种好方法?听changes,我可以获取所有Operation并遍历它们,以告诉我哪些是删除,但我认为没有附加数据可以看到what被删除:

textController.document.changes.listen((NotusChange change) {
  for (var i = 0; i < change.change.length; i++) {
    final operation = change.change.elementAt(i);

    if (operation.isDelete) {
      print('Value: ${operation.value}'); // Prints number of deleted characters

      // This is just for inserts, else it's null
      print('Value: ${operation.data}');
    }
  }
});
flutter wysiwyg
1个回答
0
投票

找到了解决方案。 invert上有一个Delta方法,您可以用它来获得与刚刚进行的转换相反的操作。我认为Zefyr使用此功能来撤消操作。与delete相对,insert带有要应用的更改,包括要添加到文本中的属性(即图像):

textController.document.changes.listen((NotusChange change) {
  final undoDelta = change.change.invert(change.before);

  for (final operation in undoDelta.toList()) {
    // Since `invert is essentially an undo, an isInsert would
    // correspond to an isDelete.
    if (operation.isInsert && operation.hasAttribute('embed')) {
      final embedPath = operation.attributes['embed']['source'] as String;
      print(embedPath);
    }
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.