How do you perform inheritance with abstract classes in dart? error : superclass SpanishData doesn't have a zero argument constructor
1,870
You need to refer to the properties of the parent class
your class
is extending. You can do this using the super
keyword.
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(){}
}
Author by
An Tran
Updated on December 22, 2022Comments
-
An Tran over 1 year
I'm trying to create an abstract class called SpanishData And then I want to create another class called alphabet that extends Spanish data
I'm getting an error: the superclass SpanishData doesn't have a zero-argument constructor. 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( ) }