首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在颤动中更新复杂模型中的值?

如何在颤动中更新复杂模型中的值?
EN

Stack Overflow用户
提问于 2020-08-11 07:07:43
回答 1查看 1K关注 0票数 0

在我的flutter应用程序中,对于像eleveator,storeroom,parking,buildAge,rentPrice这样的建筑,我有5个参数,这些参数的默认值在一开始就是0,我想在不改变其他值的情况下分步骤更新这个ApartemanRentOptionModel类中的每个值,最后将完整的值发送到服务器。

我有一个类用于Rent Apartemans选项,如下所示:

代码语言:javascript
运行
复制
    class ApartemanRentOptionModel {
    ApartemanRentOptionModel({
        this.eleveator,
        this.storeroom,
        this.parking,
        this.buildAge,
        this.rentPrice
       
    });

   
    bool eleveator;
    bool storeroom;
    bool parking;
    List<BuildAge> buildAge;
    List<RentPrice> rentPrice;
   

    factory ApartemanRentOptionModel.fromJson(Map<String, dynamic> json) => ApartemanRentOptionModel(
        eleveator: json["eleveator"],
        storeroom: json["storeroom"],
        parking: json["parking"],
        buildAge: List<BuildAge>.from(json["buildAge"].map((x) => BuildAge.fromJson(x))),
        rentPrice: List<RentPrice>.from(json["rentPrice"].map((x) => RentPrice.fromJson(x))),
        
    );

    Map<String, dynamic> toJson() => {
        "eleveator": eleveator,
        "storeroom": storeroom,
        "parking": parking,
        "buildAge": List<dynamic>.from(buildAge.map((x) => x.toJson())),
        "rentPrice": List<dynamic>.from(rentPrice.map((x) => x.toJson())),
        };
    }
 
  class BuildAge {
    BuildAge({
        this.buildAgeId,
        this.buildAgeTitle,
        this.buildAgeValue,
    });

    String buildAgeId;
    String buildAgeTitle;
    int buildAgeValue;

    factory BuildAge.fromJson(Map<String, dynamic> json) => BuildAge(
        buildAgeId: json["buildAgeID"],
        buildAgeTitle: json["buildAgeTitle"],
        buildAgeValue: json["buildAgeValue"],
    );

    Map<String, dynamic> toJson() => {
        "buildAgeID": buildAgeId,
        "buildAgeTitle": buildAgeTitle,
        "buildAgeValue": buildAgeValue,
    };
}

class RentPrice {
    RentPrice({
        this.rentPriceId,
        this.rentPriceTitle,
        this.rentPriceValue,
    });

    String rentPriceId;
    String rentPriceTitle;
    double rentPriceValue;

    factory RentPrice.fromJson(Map<String, dynamic> json) => RentPrice(
        rentPriceId: json["rentPriceID"],
        rentPriceTitle: json["rentPriceTitle"],
        rentPriceValue: json["rentPriceValue"].toDouble(),
    );

    Map<String, dynamic> toJson() => {
        "rentPriceID": rentPriceId,
        "rentPriceTitle": rentPriceTitle,
        "rentPriceValue": rentPriceValue,
    };
}

我需要使用如下函数更改BuildAgeRentPrice等数据中的值:

代码语言:javascript
运行
复制
    ApartemanRentOptionModel _currentApartemanData;

    changeCurretAparemanData(newdata) {
      _currentApartemanData.toJson().update("BuildAge", (value) => newdata)
      notifyListeners();
    return null;
  }

但是它不工作,没有任何变化,请帮助我如何在几次更新单个模型类的不同值。谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-08-11 07:25:30

您可以在模型中使用getter或setter函数,.getter函数用于从模型中获取值,setter函数用于设置或更新模型中的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63349249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档