如何为 await 和 async 覆盖 abstract class?
How to override abstract class for await and async?
如何覆盖 await
或 async
?
存储库
abstract class Repository {
Observable<dynamic> addUpdateWorkImage(WorkImage workImage);
}
RepositoryImpl
@override
Future<Observable> addUpdateWorkImage(WorkImage workImage) async {
if (workImage.id.isEmpty) {
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child('image.jpg'.toString());
final StorageUploadTask task =
firebaseStorageRef.putFile(workImage.imagePath);
StorageTaskSnapshot storageTaskSnapshot = await task.onComplete;
workImage.url = await storageTaskSnapshot.ref.getDownloadURL();
return Observable.fromFuture(
endpoints.workImageCollectionEndpoint.add(workImage.toJson()));
}
}
错误
'RepositoryImpl.addUpdateWorkImage' ('(WorkImage) → Future<Observable<dynamic>>') isn't a valid override of 'Repository.addUpdateWorkImage' ('(WorkImage) → Observable<dynamic>').
将抽象接口更新为 return Future
。
abstract class Repository {
Future<Observable<dynamic>> addUpdateWorkImage(WorkImage workImage);
}
如何覆盖 await
或 async
?
存储库
abstract class Repository {
Observable<dynamic> addUpdateWorkImage(WorkImage workImage);
}
RepositoryImpl
@override
Future<Observable> addUpdateWorkImage(WorkImage workImage) async {
if (workImage.id.isEmpty) {
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child('image.jpg'.toString());
final StorageUploadTask task =
firebaseStorageRef.putFile(workImage.imagePath);
StorageTaskSnapshot storageTaskSnapshot = await task.onComplete;
workImage.url = await storageTaskSnapshot.ref.getDownloadURL();
return Observable.fromFuture(
endpoints.workImageCollectionEndpoint.add(workImage.toJson()));
}
}
错误
'RepositoryImpl.addUpdateWorkImage' ('(WorkImage) → Future<Observable<dynamic>>') isn't a valid override of 'Repository.addUpdateWorkImage' ('(WorkImage) → Observable<dynamic>').
将抽象接口更新为 return Future
。
abstract class Repository {
Future<Observable<dynamic>> addUpdateWorkImage(WorkImage workImage);
}