我有A类:

class A{
    String title;
    String content;
    IconData iconData;
    Function onTab;
    A({this.title, this.content, this.iconData, this.onTab});
}

我如何创建用其他变量扩展类A的类B,如下所示:
class B extends A{
    bool read;
    B({this.read});
}

尝试过但不起作用
let o = new B(
          title: "New notification",
          iconData: Icons.notifications,
          content: "Lorem ipsum doro si maet 100",
          read: false,
          onTab: (context) => {

          });

最佳答案

您必须在子类上定义构造函数。

class B extends A {
  bool read;
  B({title, content, iconData, onTab, this.read}) : super(title: title, content: content, iconData: iconData, onTab: onTab);
}

07-26 09:32