我已经根据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}');
}
}
});
找到了解决方案。 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);
}
}
});