flutter model 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 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 toJson() {
    final Map data = new Map();
    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 json) {
    otpDetails = json['otpDetails'] != null
        ? new OtpDetails.fromJson(json['otpDetails'])
        : null;
  }

  Map toJson() {
    final Map data = new Map();
    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 json) {
    phoneNumber = json['phoneNumber'];
    otp = json['otp'];
    loginStatus = json['loginStatus'];
  }

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

Tags:

Misc Example