flutter model object code example

Example: flutter model

class otpGenarate {
  bool status;
  int statusCode;
  String message;
  String timeStamp;
  Null trace;
  Payload payload;

  otpGenarate(
      {this.status,
      this.statusCode,
      this.message,
      this.timeStamp,
      this.trace,
      this.payload});

  otpGenarate.fromJson(Map<String, dynamic> json) {
    status = json['status'];
    statusCode = json['statusCode'];
    message = json['message'];
    timeStamp = json['timeStamp'];
    trace = json['trace'];
    payload =
        json['payload'] != null ? new Payload.fromJson(json['payload']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['status'] = this.status;
    data['statusCode'] = this.statusCode;
    data['message'] = this.message;
    data['timeStamp'] = this.timeStamp;
    data['trace'] = this.trace;
    if (this.payload != null) {
      data['payload'] = this.payload.toJson();
    }
    return data;
  }
}

class Payload {
  OtpDetails otpDetails;

  Payload({this.otpDetails});

  Payload.fromJson(Map<String, dynamic> json) {
    otpDetails = json['otpDetails'] != null
        ? new OtpDetails.fromJson(json['otpDetails'])
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.otpDetails != null) {
      data['otpDetails'] = this.otpDetails.toJson();
    }
    return data;
  }
}

class OtpDetails {
  String phoneNumber;
  String otp;
  int loginStatus;

  OtpDetails({this.phoneNumber, this.otp, this.loginStatus});

  OtpDetails.fromJson(Map<String, dynamic> json) {
    phoneNumber = json['phoneNumber'];
    otp = json['otp'];
    loginStatus = json['loginStatus'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['phoneNumber'] = this.phoneNumber;
    data['otp'] = this.otp;
    data['loginStatus'] = this.loginStatus;
    return data;
  }
}

Tags:

Misc Example