我已经定义了一个这样的类,并用freezed library进行了注释。
@freezed
@immutable
abstract class CommentMediaAttachmentModel with _$CommentMediaAttachmentModel {
const factory CommentMediaAttachmentModel({
final String type,
final String mediaUrl,
final int width,
final int height
}) = _CommentMediaAttachmentModel;
bool isAnimated() {
return type == 'ANIMATED';
}
}我想添加一个快速函数isAnimated来确定type变量,但在编译时,它不允许我这样做:
lib/presentation/comment/model/comment_attachment_model.freezed.dart:292:7: Error: The non-abstract class '_$_CommentMediaAttachmentModel' is missing implementations for these members:
- CommentMediaAttachmentModel.isAnimated
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.在检查生成的类_$_CommentMediaAttachmentModel时,没有实现isAnimated函数。我怎样才能做到这一点呢?
编辑:下面是_$_CommentMediaAttachmentModel的代码。我不知道为什么我不能将这个代码片段粘贴到SO,它只是说代码格式不正确。我将使用屏幕截图来代替:

发布于 2020-10-22 23:39:02
基本上,您还需要在_$CommentMediaAttachmentModel中实现isAnimated。因为它是abstract类的mixin。
https://stackoverflow.com/questions/64485599
复制相似问题