How to extend a class in Dart/Flutter
I have class A:
class A{
String title;
String content;
IconData iconData;
Function onTab;
A({this.title, this.content, this.iconData, this.onTab});
}
How can i create class B that extends class A with additional variable like following:
class B extends A{
bool read;
B({this.read});
}
Tried with this but not working
let o = new B(
title: "New notification",
iconData: Icons.notifications,
content: "Lorem ipsum doro si maet 100",
read: false,
onTab: (context) => {
});
Solution 1:
You have to define the constructor on the child class.
class B extends A {
bool read;
B({title, content, iconData, onTab, this.read}) : super(title: title, content: content, iconData: iconData, onTab: onTab);
}