账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Flutter类型扩展
    • 2020-01-01 00:00
    • 10
    79
    0

    接口返回了一个IEntryListItem类型的值

    我需要在IEntryListItem的基础上增加id等一些字段

    需要怎么写?

    比如

    class IEntryListItemExpend extend IEntryListItem {
        IEntryListItemExpend({
            this.isNew;
        })
        bool isNew;
    }
    IEntryListItem res = dio()....
    
    IEntryListItemExpend resExpend = res;
    
    resExpend.isNew = true;

    这样写会报错

    type 'IEntryListItem' is not a subtype of type 'IEntryListItemExpend'

    需要怎么写才能解决这个问题

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 共 0 条
    • Flutter类型扩展是指将Java或C#等编程语言的类型扩展功能移植到Flutter应用程序中。类型扩展可以实现一些Java或C#中的特性,如类型注解、泛型、接口、继承等,从而简化开发过程。

      以下是一个简单的Java类型的扩展示例:

      ```java public class CustomType { private int a; private String b;

      public CustomType(int a, String b) {
          this.a = a;
          this.b = b;
      }
      
      // 泛型访问器
      public T getA() {
          return a;
      }
      
      // 操作符重载
      public int getB() {
          return b;
      }
      
      // 接口方法
      @Override
      public void print() {
          System.out.println("CustomType: a = " + a + ", b = " + b);
      }
      

      } ```

      然后在Flutter中,我们可以使用dart:io库来创建文件流,并使用dart:math库来处理数学运算:

      ```dart import 'dart:io'; import 'dart:math';

      class CustomType { final int a; final String b;

      CustomType(int a, String b) { this.a = a; this.b = b; }

      final int getA() { return a; }

      final int getB() { return b; }

      final int getB() { return b; }

      final void print() { var result = a + b; print('Result: $result'); } }

      void main() { var customType = CustomType(5, 'hello'); customType.print();

      var file = File('/path/to/your/file.txt'); file.writeAsText('Result: $customType.getA() $customType.getB()');

      // 使用dart:io库创建文件流 var fileStream = File('/path/to/your/file.txt').openWrite(); fileStream.writeAsText('Result: $customType.getA() $customType.getB()'); fileStream.close(); } ```

      在这个例子中,我们首先创建了一个CustomType类,然后在main函数中使用它。然后我们使用dart:io库创建了一个文件流,并写入了一些文本。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部