简体   繁体   English

您如何使用 dart 中的抽象类执行 inheritance? 错误:超类 SpanishData 没有零参数构造函数

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

I'm trying to create an abstract class called SpanishData And then I want to create another class called alphabet that extends Spanish data我正在尝试创建一个名为 SpanishData 的抽象 class 然后我想创建另一个名为字母表的 class 扩展西班牙数据

I'm getting an error: the superclass SpanishData doesn't have a zero-argument constructor.我收到一个错误:超类 SpanishData 没有零参数构造函数。 How do I fix this?我该如何解决?

Here is my code:这是我的代码:

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(

      )


}

You need to refer to the properties of the parent class your class is extending.您需要参考您的class正在扩展的parent class的属性。 You can do this using the super keyword.您可以使用super关键字来执行此操作。

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

The code below works:下面的代码有效:

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(){}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复此 Flutter 错误:超类 'Bloc<numbertriviaevent, numbertriviastate> ' 没有零参数构造函数</numbertriviaevent,> - How to fix this Flutter error: The superclass 'Bloc<NumberTriviaEvent, NumberTriviaState>' doesn't have a zero argument constructor 超类&#39;Bloc<xxx, xxx> &#39; 在 dart 中没有零参数构造函数 - The superclass 'Bloc<xxx, xxx>' doesn't have a zero argument constructor in dart 超类“BluetoothDevice”没有零参数构造函数 - The superclass 'BluetoothDevice ' doesn't have a zero argument constructor 超类'Bloc<event, state> ' 没有零参数构造函数</event,> - The superclass 'Bloc<Event, State>' doesn't have a zero argument constructor 我收到一个错误错误:超类“xxxx”没有零参数构造函数 - I am getting an Error -error: The superclass 'xxxx' doesn't have a zero argument constructor 什么是零参数构造函数 Dart flutter - What is a zero argument constructor in Dart flutter Dart / Flutter - class 不必实现抽象类的抽象方法? - Dart / Flutter - class doesn't have to implement abstract class's abstract methods? 如何解决 PreferredSize flutter 中的零参数构造函数错误? - How to solve zero Argument constructor error in PreferredSize flutter? Dart/Flutter 中抽象类中的常量 - Constants in abstract classes in Dart/Flutter Dart - 你如何对列表进行多级排序<T> - Dart - How do you multi level sort on a list<T>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM