【发布时间】:2020-01-09 23:10:10
【问题描述】:
对于我正在构建的教育应用程序,我有一个需要copyWith 方法的模块接口:
abstract class Module {
// ...
Module copyWith() => throw 'You should call the instance\'s copyWith.';
}
问题是我在模块子类的扩展上使用了 generates the copyWith 方法的 codegen 包:
part 'audio_module.g.dart';
@immutable
@CopyWith()
class AudioModule implements Module {
/* ... */
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of audio_module;
// **************************************************************************
// CopyWithGenerator
// **************************************************************************
extension AudioModuleCopyWithExtension on AudioModule {
AudioModule copyWith(/* ... */) {
return AudioModule(/* ... */);
}
}
在我的 AudioModule 课程中,我因此收到此错误,因为我认为它不包括扩展方法:
Missing concrete implementation of 'Module.copyWith'.
Try implementing the missing method, or make the class abstract.
如果子类(以某种方式)确实实现了copyWith,为什么会发生这种情况?
谢谢
编辑
我最终使用的解决方法是改用functional_data code gen package,它使用copyWith 方法构建一个类,然后您可以扩展该类。没有扩展。
【问题讨论】:
标签: flutter dart interface abstract-class