召回新类颤振中的变量

时间:2021-07-15 14:16:12

标签: flutter class

一旦我登录应用程序,这个类就会被填满。我需要得到“late int unitOwnerId; ”当我在另一个类中进行 HTTP 调用时用作参数。

该类在应用程序开始时填充了一个调用,在该调用中它接收所有数据。该字段肯定有价值

我试试

  Unit? _unit;

之后是 _unit.unitOwnerId

这个但是我收到null ...我该怎么办?

    class Unit with AssociatedMixin {
  late int ownerId;
  late int id;
  late String storeName;
  late String businessName;
  late String vatNumber;
  late String fiscalCode;
  late String email;
  late String phone;
  late String address;
  late String city;
  late String cap;
  late String province;
  late bool hasCustomInvoicing;
  late bool isPa;
  late int scopeId;
  late num geoX;
  late num geoY;
  late int unitOwnerId;
  late int statusId;
  late String iban;
  late String recipientCode;
  late String fiscalRegime;
  late String legalNature;
  String? imageId;
  late String createdBy;
  //late int categoryId;
  late int subcategoryId;
  late int roleId;

  Unit.from(Map map, this.ownerId) {
    id = map['id'];
    storeName = map['store_name'];
    businessName = map['business_name'];
    vatNumber = map['vat_number'];
    fiscalCode = map['fiscal_code'];
    email = map['email'];
    phone = map['phone'];
    address = map['address'];
    city = map['city'];
    cap = map['cap'];
    province = map['province'];
    hasCustomInvoicing = map['has_custom_invoicing'];
    isPa = map['is_pa'];
    scopeId = map['scope_id'];
    geoX = map['geo_x'];
    geoY = map['geo_y'];
//    unitOwnerId = map['unit_owner_id'];
    statusId = map['status_id'] ?? 0;
    iban = map['iban'] ?? "n/a";
    recipientCode = map['recipient_code'];
    fiscalRegime = map['fiscal_regime'];
    legalNature = map['legal_nature'];
    imageId = map['image_id'];
    createdBy = map['created_by'];
    //categoryId = map['category_id'] ?? -1;
    subcategoryId = map['subcategoryId'] ?? -1;
    roleId = map['role_id'];
  }

  String get name => this.storeName;
  AccountType get type => AccountType.SHOP;

  String toString() => jsonEncode(toMap());

  int get cashId => unitOwnerId;

  Map toMap() => {
        "id": id,
        "store_name": storeName,
        "business_name": businessName,
        "vat_number": vatNumber,
        "fiscal_code": fiscalCode,
        "email": email,
        "phone": phone,
        "address": address,
        "city": city,
        "cap": cap,
        "province": province,
        "has_custom_invoicing": hasCustomInvoicing,
        "is_pa": isPa,
        "scope_id": scopeId,
        "geo_x": geoX,
        "geo_y": geoY,
        "unit_owner_id": unitOwnerId,
        "status_id": statusId,
        "iban": iban,
        "recipient_code": recipientCode,
        "fiscal_regime": fiscalRegime,
        "legal_nature": legalNature,
        "image_id": imageId,
        "created_by": createdBy,
        //"category_id": categoryId,
        "subcategory_id": subcategoryId,
        "role_id": roleId,
      };
}

2 个答案:

答案 0 :(得分:0)

去掉双斜线

//    unitOwnerId = map['unit_owner_id'];

答案 1 :(得分:0)

更多的代码会显示你如何使用这个类,但一个类应该总是有最终变量和一个构造函数。比您可以工厂数据并编写使用它们的方法。这应该在 initState 中调用。