如何从JSON Api获取对象的属性值并在flutter中初始化具有该值的变量

时间:2019-04-06 10:52:00

标签: flutter

在我的应用中,我正在从JSON API中读取数据。我希望在选中复选框后更新一个值。

下面是我的model.dart文件。我正在尝试使用JSON API中的值初始化我的checkbox.dart文件中的变量。有人可以帮忙吗?

class Package {
  String title;
  num price;
  List<ServiceTask> services;
  String id;

  Package({this.title, this.price, this.services, this.id});

  Package.fromJson(Map<String, dynamic> json) {
    title = json['title'];
  //  price = (json['price']).toDouble();
    price = (json['price']).toDouble();
    if (json['services'] != null) {
      services =  List<ServiceTask>();
      json['services'].forEach((v) {

        services.add(new ServiceTask.fromJson(v));
      });
    }
    id = json['id'];
  }

0 个答案:

没有答案