How do you perform inheritance with abstract classes in dart? error : superclass SpanishData doesn't have a zero argument constructor

How do you perform inheritance with abstract classes in dart? error : superclass SpanishData doesn't have a zero argument constructor

我正在尝试创建一个名为 SpanishData 的摘要 class 然后我想创建另一个 class 扩展西班牙语数据的字母表

我收到一个错误:superclass SpanishData 没有零参数构造函数。我该如何解决这个问题?

这是我的代码:

abstract class SpanishData{
  String englishWord;
  String spanishWord;
  String mp3;

  SpanishData(this.englishWord,this.spanishWord,this.mp3);

  void getList (){

  }



}


//the alphabet class

import '../SpanishDataAbstract.dart';


class Alphabet extends SpanishData{

  @override
  void getList(

      )


}

您需要参考 parent class 您的 class 正在扩展的属性。您可以使用 super 关键字来执行此操作。

The super() method on a class constructor allows a subclass to pass arguments and execute the constructor of its superclass. 

下面的代码有效:

abstract class SpanishData{
  String englishWord;
  String spanishWord;
  String mp3;

  SpanishData(this.englishWord,this.spanishWord,this.mp3);

  void getList (){

  }
}


class Alphabet extends SpanishData{

  // create a constructor of the alphabet class and call the parent constructor
  Alphabet(String englishWord, String spanishWord, String mp3) : super(englishWord, spanishWord, mp3);

  @override
  void getList(){}
}