flutter - 如何在 Dart/Flutter 中扩展一个类

标签 flutter dart

我有 A 类:

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

我如何创建类 B,它使用如下附加变量扩展类 A:

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);
}

关于flutter - 如何在 Dart/Flutter 中扩展一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56879606/

相关文章:

flutter - 如何在 Flutter 中更改主题?

android - 在 Flutter 的登录屏幕中显示循环进度对话框,如何在 Flutter 中实现进度对话框?

Flutter:如何在 AppBar 左侧添加 logo 图片?

json - 将文件发送到api中

flutter - MediaQuery 与 IntrinsicHeight

json - 如何在 json_serializable flutter 中将 int 时间戳转换为 DateTime

flutter - Dart Flutter如何在类内部初始化类方法?

flutter 自定义字体未加载

flutter - DraggableScrollableSheet 在滚动前吸附到顶部

flutter - 使用 super.key 和 (Key? key) : super(key: key) in flutter 有什么区别