I want to parse json for past cruise and display the data inside list view. I am getting this exception while parsing. Unhandled Exception: type 'CrusieModel' is not a subtype of type 'Map<String, dynamic>'. Also when i try to display the data inside listview it shows Null operator called on null value at itemCount.
My API class
final String baseUrl = "https://yourapilink";
String token = "eyJhbGciOiJIUzM4NCIsImtleSI6MjAxNzA5MjEsImlhdCI6MTYzMDk1MzAzNCiZXhwIjoxNjMxNTU3ODM0LCJpc3MiOiJodHRwOi8vYXBwLWFwaS5mcmVb2xzZW5jcnVpc2VzLmNvbSJ9.eyJSb2xlcyI6WyJNeUNydWlzZSJdLCJab2hvSUQiOiIyOTIxMTwMDAwMDAyODMwODgifQ.OCjwy_Q8mWaJUBWTIzAfUvX4voMDdry_Y_LLj6s8nxt514BVNQk3yptcZFnD48Hd";
Future<CrusieModel> getPastCruise( BuildContext context, String? token) async {
String url = baseUrl "api/v1/atcore/user?token=$token";
//Utilities.showLoaderDialog(context);
final response = await http.post(Uri.parse(url), headers: {
'Content-Type':'application/json',
'Authorization':'Bearer $token'
});
debugPrint("jsonBody past and future:::: ${response.body}");
print("jsonBody past and future:::: ${response.body}");
print("nntoken::: $token");
print("response Code cruise history:::: ${response.statusCode}");
if(response.statusCode == 200){
//Navigator.pop(context);
// return json.decode(response.body);
return CrusieModel.fromJson(json.decode(response.body));
}else if(response.statusCode == 500){
//Navigator.pop(context);
return Utilities.errorDialog("There was an error getting the information from Atcore or Zoho", context);
}else{
//Navigator.pop(context);
return Utilities.errorDialog("Something went wrong", context);
}
// return data;
}
My Model Class
import 'dart:convert';
CrusieModel crusieModelFromJson(String str) => CrusieModel.fromJson(json.decode(str));
String crusieModelToJson(CrusieModel data) => json.encode(data.toJson());
class CrusieModel {
CrusieModel({
this.pastCruises,
});
List<PastCruise>? pastCruises;
factory CrusieModel.fromJson(Map<String, dynamic> json) => CrusieModel(
pastCruises: List<PastCruise>.from(json["PastCruises"].map((x) => PastCruise.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"PastCruises": List<dynamic>.from(pastCruises!.map((x) => x.toJson())),
};
}
class PastCruise {
PastCruise({
this.cruiseId,
this.name,
this.shortName,
this.departureDate,
this.returnDate,
this.duration,
this.shortDescription,
this.departurePortCode,
this.departurePortName,
this.departurePortNameWithCountry,
this.returnPortCode,
this.returnPortName,
this.returnPortNameWithCountry,
this.shipCode,
this.shipName,
this.cruiseStatus,
this.cruiseStatusApp,
this.cruisingCategory,
this.cruiseCancelledInfo,
this.modifiedDate,
this.isAddOnHoliday,
this.bookingRef,
this.agentName,
this.guests,
});
String? cruiseId;
String? name;
String? shortName;
DateTime? departureDate;
DateTime? returnDate;
int? duration;
String? shortDescription;
String? departurePortCode;
String? departurePortName;
String? departurePortNameWithCountry;
String? returnPortCode;
String? returnPortName;
String? returnPortNameWithCountry;
String? shipCode;
String? shipName;
String? cruiseStatus;
String? cruiseStatusApp;
String? cruisingCategory;
String? cruiseCancelledInfo;
DateTime? modifiedDate;
bool? isAddOnHoliday;
String? bookingRef;
String? agentName;
String? guests;
factory PastCruise.fromJson(Map<String, dynamic> json) => PastCruise(
cruiseId: json["CruiseId"],
name: json["Name"],
shortName: json["ShortName"],
departureDate: DateTime.parse(json["DepartureDate"]),
returnDate: DateTime.parse(json["ReturnDate"]),
duration: json["Duration"],
shortDescription: json["ShortDescription"],
departurePortCode: json["DeparturePortCode"],
departurePortName: json["DeparturePortName"],
departurePortNameWithCountry: json["DeparturePortNameWithCountry"],
returnPortCode: json["ReturnPortCode"],
returnPortName: json["ReturnPortName"],
returnPortNameWithCountry: json["ReturnPortNameWithCountry"],
shipCode: json["ShipCode"],
shipName: json["ShipName"],
cruiseStatus: json["CruiseStatus"],
cruiseStatusApp: json["CruiseStatusApp"],
cruisingCategory: json["CruisingCategory"],
cruiseCancelledInfo: json["CruiseCancelledInfo"],
modifiedDate: DateTime.parse(json["ModifiedDate"]),
isAddOnHoliday: json["IsAddOnHoliday"],
bookingRef: json["BookingRef"],
agentName: json["AgentName"],
guests: json["Guests"],
);
Map<String, dynamic> toJson() => {
"CruiseId": cruiseId,
"Name": name,
"ShortName": shortName,
"DepartureDate": departureDate!.toIso8601String(),
"ReturnDate": returnDate!.toIso8601String(),
"Duration": duration,
"ShortDescription": shortDescription,
"DeparturePortCode": departurePortCode,
"DeparturePortName": departurePortName,
"DeparturePortNameWithCountry": departurePortNameWithCountry,
"ReturnPortCode": returnPortCode,
"ReturnPortName": returnPortName,
"ReturnPortNameWithCountry": returnPortNameWithCountry,
"ShipCode": shipCode,
"ShipName": shipName,
"CruiseStatus": cruiseStatus,
"CruiseStatusApp": cruiseStatusApp,
"CruisingCategory": cruisingCategory,
"CruiseCancelledInfo": cruiseCancelledInfo,
"ModifiedDate": modifiedDate!.toIso8601String(),
"IsAddOnHoliday": isAddOnHoliday,
"BookingRef": bookingRef,
"AgentName": agentName,
"Guests": guests,
};
}
My Listview Widget
At itemCount: snapshot.data!.pastCruises!.length,
I am getting Null Check operator used on null value
Widget listviewWidget(){
return FutureBuilder<CrusieModel>(
future: pastCruises,
builder: (context, snapshot){
log("${snapshot.data}", name: "DATA RECEIVED");
/* if(snapshot.hasData){*/
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data!.pastCruises!.length,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index){
CrusieModel cruiseData = snapshot.data! ;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child:
Stack(
children: [
Image.asset("assets/images/ticket_bg.png",
height: MediaQuery.of(context).size.height*0.35,
width: MediaQuery.of(context).size.width*0.90,
fit: BoxFit.fill,),
Container(
width: MediaQuery.of(context).size.width*0.90,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height*0.15,
child: Padding(
padding: const EdgeInsets.only(left: 50, right: 50, top: 30),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Departure", style: TextStyle(fontFamily: 'Montserrat',
color: CustomColors.subtitleText, fontSize: 12),),
Row(
children: [
Text(/*items[index].departureDate*/"25",
style: TextStyle(fontFamily: 'Montserrat', color: CustomColors.madison,
fontWeight: FontWeight.bold, fontSize: 32),),
Column(
children: [
Text(/*items[index].departureDateMonth*/"08",
style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.subtitleText,
fontWeight: FontWeight.bold, fontSize: 12),),
Text(/*items[index].departureDateYear*/"2008",
style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.madison,
fontWeight: FontWeight.bold, fontSize: 12),),
],
),
],
),
],
),
Column(
children: [
Icon(Icons.directions_boat),
Text("${cruiseData.pastCruises?[index].duration ?? ""}", style: TextStyle(fontFamily: 'Montserrat',fontWeight: FontWeight.w700),),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Return', style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.subtitleText, fontSize: 12),),
Row(
children: [
Text(/*items[index].returnDate*/"18",
style: TextStyle(fontFamily: 'Montserrat', color: CustomColors.madison,
fontWeight: FontWeight.bold, fontSize: 32),),
Column(
children: [
Text(/*items[index].returnDateMonth*/"03",
style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.subtitleText,
fontWeight: FontWeight.bold, fontSize: 12),),
Text(/*items[index].returnDateYear*/"2019",
style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.madison,
fontWeight: FontWeight.bold, fontSize: 12),),
],
),
],
),
],
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(50, 20, 50, 30),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Passenger", style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.subtitleText, fontSize: 12),),
Text("/*items[index].passengerName*/""amit kumar", style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.madison,
fontWeight: FontWeight.bold),)
],),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Booking Reference", style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.subtitleText, fontSize: 12),),
Text("${cruiseData.pastCruises![index].bookingRef}", style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.madison,
fontWeight: FontWeight.bold),)
],)
],),
SizedBox(height: 20,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("TRavel Agency", style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.subtitleText, fontSize: 12),),
Text("${cruiseData.pastCruises![index].agentName}", style: TextStyle(fontFamily: 'Montserrat',color: CustomColors.madison,
fontWeight: FontWeight.bold),)
],),
SizedBox(width: 10,)
],)
],
),
),
)
],
),
)
],
),
);
});
/*}else{
return Center(child: CircularProgressIndicator());
}*/
},
);
}
I am not getting what is the issue here. I just want to display past cruise parameters in a listview.
CodePudding user response:
Fist i proved the output
Code:
final String baseUrl = "https://appservice-staging.simpleclick.co.uk/";
String token = "eyJhbGciOiJIUzM4N";
@override
void initState() {
super.initState();
getPastCruise();
}
@override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
itemCount: yourModelName!.futureCruises!.length,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return ListTile(
title: Text(yourModelName!.futureCruises![index].duration!.toString()),
);
},
);
}
getPastCruise() async {
String url = '${baseUrl}api/v1/atcore/user?token=$token';
//Utilities.showLoaderDialog(context);
final response = await http.post(Uri.parse(url), headers: {
'Content-Type':'application/json',
'Authorization':'Bearer $token'
});
if(response.statusCode==200){
setState(() {
yourModelName=YourModelName.fromJson(jsonDecode(response.body));
}
YourModelName.dart
// To parse this JSON data, do
//
// final yourModelName = yourModelNameFromJson(jsonString);
import 'dart:convert';
YourModelName yourModelNameFromJson(String str) => YourModelName.fromJson(json.decode(str));
String yourModelNameToJson(YourModelName data) => json.encode(data.toJson());
class YourModelName {
YourModelName({
this.oceans,
this.pastCruises,
this.futureCruises,
});
Oceans? oceans;
List<PastCruise>? pastCruises;
List<FutureCruise>? futureCruises;
factory YourModelName.fromJson(Map<String, dynamic> json) => YourModelName(
oceans: Oceans.fromJson(json["Oceans"]),
pastCruises: List<PastCruise>.from(json["PastCruises"].map((x) => PastCruise.fromJson(x))),
futureCruises: List<FutureCruise>.from(json["FutureCruises"].map((x) => FutureCruise.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"Oceans": oceans!.toJson(),
"PastCruises": List<dynamic>.from(pastCruises!.map((x) => x.toJson())),
"FutureCruises": List<dynamic>.from(futureCruises!.map((x) => x.toJson())),
};
}
class FutureCruise {
FutureCruise({
this.cruiseId,
this.name,
this.shortName,
this.departureDate,
this.returnDate,
this.duration,
this.shortDescription,
this.departurePortCode,
this.departurePortName,
this.departurePortNameWithCountry,
this.returnPortCode,
this.returnPortName,
this.returnPortNameWithCountry,
this.shipCode,
this.shipName,
this.cruiseStatus,
this.cruiseStatusApp,
this.cruisingCategory,
this.cruiseCancelledInfo,
this.modifiedDate,
this.bookingRef,
this.bookedDate,
this.agentName,
this.fareTypeId,
this.fareDescription,
this.fareCode,
this.guests,
this.theme,
this.portTerminal,
this.gifMissing,
this.flights,
this.cabins,
});
CruiseId? cruiseId;
Name? name;
Name? shortName;
DateTime? departureDate;
DateTime? returnDate;
int? duration;
String? shortDescription;
PortCode? departurePortCode;
PortName? departurePortName;
PortNameWithCountry? departurePortNameWithCountry;
PortCode? returnPortCode;
PortName? returnPortName;
PortNameWithCountry? returnPortNameWithCountry;
ShipCode? shipCode;
ShipName? shipName;
CruiseStatus? cruiseStatus;
String? cruiseStatusApp;
CruisingCategory? cruisingCategory;
String? cruiseCancelledInfo;
DateTime? modifiedDate;
String? bookingRef;
DateTime? bookedDate;
AgentName? agentName;
FareTypeId? fareTypeId;
FareDescription? fareDescription;
FareCode? fareCode;
Guest? guests;
Theme? theme;
PortTerminal? portTerminal;
bool? gifMissing;
List<dynamic>? flights;
List<Cabin>? cabins;
factory FutureCruise.fromJson(Map<String, dynamic> json) => FutureCruise(
cruiseId: cruiseIdValues.map[json["CruiseId"]],
name: nameValues.map[json["Name"]],
shortName: nameValues.map[json["ShortName"]],
departureDate: DateTime.parse(json["DepartureDate"]),
returnDate: DateTime.parse(json["ReturnDate"]),
duration: json["Duration"],
shortDescription: json["ShortDescription"],
departurePortCode: portCodeValues.map[json["DeparturePortCode"]],
departurePortName: portNameValues.map[json["DeparturePortName"]],
departurePortNameWithCountry: portNameWithCountryValues.map[json["DeparturePortNameWithCountry"]],
returnPortCode: portCodeValues.map[json["ReturnPortCode"]],
returnPortName: portNameValues.map[json["ReturnPortName"]],
returnPortNameWithCountry: portNameWithCountryValues.map[json["ReturnPortNameWithCountry"]],
shipCode: shipCodeValues.map[json["ShipCode"]],
shipName: shipNameValues.map[json["ShipName"]],
cruiseStatus: cruiseStatusValues.map[json["CruiseStatus"]],
cruiseStatusApp: json["CruiseStatusApp"],
cruisingCategory: cruisingCategoryValues.map[json["CruisingCategory"]],
cruiseCancelledInfo: json["CruiseCancelledInfo"],
modifiedDate: DateTime.parse(json["ModifiedDate"]),
bookingRef: json["BookingRef"],
bookedDate: DateTime.parse(json["BookedDate"]),
agentName: agentNameValues.map[json["AgentName"]],
fareTypeId: fareTypeIdValues.map[json["FareTypeId"]],
fareDescription: fareDescriptionValues.map[json["FareDescription"]],
fareCode: fareCodeValues.map[json["FareCode"]],
guests: guestValues.map[json["Guests"]],
theme: themeValues.map[json["Theme"]],
portTerminal: portTerminalValues.map[json["PortTerminal"]],
gifMissing: json["GIFMissing"],
flights: List<dynamic>.from(json["Flights"].map((x) => x)),
cabins: List<Cabin>.from(json["Cabins"].map((x) => Cabin.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"CruiseId": cruiseIdValues.reverse[cruiseId],
"Name": nameValues.reverse[name],
"ShortName": nameValues.reverse[shortName],
"Duration": duration,
"ShortDescription": shortDescription,
"DeparturePortCode": portCodeValues.reverse[departurePortCode],
"DeparturePortName": portNameValues.reverse[departurePortName],
"DeparturePortNameWithCountry": portNameWithCountryValues.reverse[departurePortNameWithCountry],
"ReturnPortCode": portCodeValues.reverse[returnPortCode],
"ReturnPortName": portNameValues.reverse[returnPortName],
"ReturnPortNameWithCountry": portNameWithCountryValues.reverse[returnPortNameWithCountry],
"ShipCode": shipCodeValues.reverse[shipCode],
"ShipName": shipNameValues.reverse[shipName],
"CruiseStatus": cruiseStatusValues.reverse[cruiseStatus],
"CruiseStatusApp": cruiseStatusApp,
"CruisingCategory": cruisingCategoryValues.reverse[cruisingCategory],
"CruiseCancelledInfo": cruiseCancelledInfo,
"BookingRef": bookingRef,
"AgentName": agentNameValues.reverse[agentName],
"FareTypeId": fareTypeIdValues.reverse[fareTypeId],
"FareDescription": fareDescriptionValues.reverse[fareDescription],
"FareCode": fareCodeValues.reverse[fareCode],
"Guests": guestValues.reverse[guests],
"Theme": themeValues.reverse[theme],
"PortTerminal": portTerminalValues.reverse[portTerminal],
"GIFMissing": gifMissing,
"Flights": List<dynamic>.from(flights!.map((x) => x)),
"Cabins": List<dynamic>.from(cabins!.map((x) => x.toJson())),
};
}
enum AgentName { DIRECT, F9255, THE_0_F1234 }
final agentNameValues = EnumValues({
"DIRECT": AgentName.DIRECT,
"F9255": AgentName.F9255,
"0F1234": AgentName.THE_0_F1234
});
class Cabin {
Cabin({
this.cabinNumber,
this.deckId,
this.cabinGrade,
this.referenceNos,
this.guestNames,
this.checkInTime,
this.checkInCloses,
});
String? cabinNumber;
String? deckId;
String? cabinGrade;
String? referenceNos;
Guest? guestNames;
String? checkInTime;
String? checkInCloses;
factory Cabin.fromJson(Map<String, dynamic> json) => Cabin(
cabinNumber: json["CabinNumber"],
deckId: json["DeckId"],
cabinGrade: json["CabinGrade"],
referenceNos: json["ReferenceNos"],
guestNames: guestValues.map[json["GuestNames"]],
checkInTime: json["CheckInTime"],
checkInCloses: json["CheckInCloses"],
);
Map<String, dynamic> toJson() => {
"CabinNumber": cabinNumber,
"DeckId": deckId,
"CabinGrade": cabinGrade,
"ReferenceNos": referenceNos,
"GuestNames": guestValues.reverse[guestNames],
"CheckInTime": checkInTime,
"CheckInCloses": checkInCloses,
};
}
enum Guest { TEST_USER_JONATHAN_QUINNELL, EMPTY }
final guestValues = EnumValues({
"": Guest.EMPTY,
"Test User, Jonathan Quinnell": Guest.TEST_USER_JONATHAN_QUINNELL
});
enum CruiseId { T2122, S2124, T2129, L2222 }
final cruiseIdValues = EnumValues({
"L2222": CruiseId.L2222,
"S2124": CruiseId.S2124,
"T2122": CruiseId.T2122,
"T2129": CruiseId.T2129
});
enum CruiseStatus { ACTIVE }
final cruiseStatusValues = EnumValues({
"Active": CruiseStatus.ACTIVE
});
enum CruisingCategory { OCEAN }
final cruisingCategoryValues = EnumValues({
"Ocean": CruisingCategory.OCEAN
});
enum PortCode { GBDVR, GBLIV, GBSOU, GBROY }
final portCodeValues = EnumValues({
"GBDVR": PortCode.GBDVR,
"GBLIV": PortCode.GBLIV,
"GBROY": PortCode.GBROY,
"GBSOU": PortCode.GBSOU
});
enum PortName { DOVER, LIVERPOOL, SOUTHAMPTON, ROSYTH_EDINBURGH }
final portNameValues = EnumValues({
"Dover": PortName.DOVER,
"Liverpool": PortName.LIVERPOOL,
"Rosyth (Edinburgh)": PortName.ROSYTH_EDINBURGH,
"Southampton": PortName.SOUTHAMPTON
});
enum PortNameWithCountry { DOVER_ENGLAND, LIVERPOOL_ENGLAND, SOUTHAMPTON_ENGLAND, ROSYTH_EDINBURGH_SCOTLAND }
final portNameWithCountryValues = EnumValues({
"Dover, England": PortNameWithCountry.DOVER_ENGLAND,
"Liverpool, England": PortNameWithCountry.LIVERPOOL_ENGLAND,
"Rosyth (Edinburgh), Scotland": PortNameWithCountry.ROSYTH_EDINBURGH_SCOTLAND,
"Southampton, England": PortNameWithCountry.SOUTHAMPTON_ENGLAND
});
enum FareCode { F_F_1, EMPTY }
final fareCodeValues = EnumValues({
"": FareCode.EMPTY,
"F-F-1": FareCode.F_F_1
});
enum FareDescription { FREEDOM_FARE, EMPTY }
final fareDescriptionValues = EnumValues({
"": FareDescription.EMPTY,
"Freedom Fare": FareDescription.FREEDOM_FARE
});
enum FareTypeId { F, EMPTY }
final fareTypeIdValues = EnumValues({
"": FareTypeId.EMPTY,
"F": FareTypeId.F
});
enum Name { SWEDISH_WATERWAYS_WITH_A_TASTE_OF_DENMARK, EXPLORING_THE_AZORES_AND_PORTUGAL, LANDSCAPES_OF_THE_CANARY_ISLANDS, BLACK_SEA_DISCOVERY_MEDITERRANEAN_ADVENTURE }
final nameValues = EnumValues({
"Black Sea Discovery & Mediterranean Adventure": Name.BLACK_SEA_DISCOVERY_MEDITERRANEAN_ADVENTURE,
"Exploring the Azores and Portugal": Name.EXPLORING_THE_AZORES_AND_PORTUGAL,
"Landscapes of the Canary Islands": Name.LANDSCAPES_OF_THE_CANARY_ISLANDS,
"Swedish Waterways with a Taste of Denmark": Name.SWEDISH_WATERWAYS_WITH_A_TASTE_OF_DENMARK
});
enum PortTerminal { CRUISE_TERMINAL_2, ACC_EXHIBITION_CENTRE, EMPTY }
final portTerminalValues = EnumValues({
"ACC Exhibition Centre": PortTerminal.ACC_EXHIBITION_CENTRE,
"Cruise Terminal 2": PortTerminal.CRUISE_TERMINAL_2,
"": PortTerminal.EMPTY
});
enum ShipCode { BT, BS, BL }
final shipCodeValues = EnumValues({
"BL": ShipCode.BL,
"BS": ShipCode.BS,
"BT": ShipCode.BT
});
enum ShipName { BOLETTE, BOREALIS, BALMORAL }
final shipNameValues = EnumValues({
"Balmoral": ShipName.BALMORAL,
"Bolette": ShipName.BOLETTE,
"Borealis": ShipName.BOREALIS
});
enum Theme { THE_12_X_FORMAL_EVENINGS, THE_13_X_FORMAL_EVENINGS, EMPTY }
final themeValues = EnumValues({
"": Theme.EMPTY,
"1. 2 x Formal Evenings": Theme.THE_12_X_FORMAL_EVENINGS,
"1. 3 x Formal Evenings": Theme.THE_13_X_FORMAL_EVENINGS
});
class Oceans {
Oceans({
this.number,
this.status,
this.type,
this.points,
});
dynamic? number;
dynamic? status;
String? type;
int? points;
factory Oceans.fromJson(Map<String, dynamic> json) => Oceans(
number: json["Number"],
status: json["Status"],
type: json["Type"],
points: json["Points"],
);
Map<String, dynamic> toJson() => {
"Number": number,
"Status": status,
"Type": type,
"Points": points,
};
}
class PastCruise {
PastCruise({
this.cruiseId,
this.name,
this.shortName,
this.departureDate,
this.returnDate,
this.duration,
this.shortDescription,
this.departurePortCode,
this.departurePortName,
this.departurePortNameWithCountry,
this.returnPortCode,
this.returnPortName,
this.returnPortNameWithCountry,
this.shipCode,
this.shipName,
this.cruiseStatus,
this.cruiseStatusApp,
this.cruisingCategory,
this.cruiseCancelledInfo,
this.modifiedDate,
this.isAddOnHoliday,
this.bookingRef,
this.agentName,
this.guests,
});
String? cruiseId;
String? name;
String? shortName;
DateTime? departureDate;
DateTime? returnDate;
int? duration;
String? shortDescription;
PortCode? departurePortCode;
PortName? departurePortName;
PortNameWithCountry? departurePortNameWithCountry;
PortCode? returnPortCode;
PortName? returnPortName;
PortNameWithCountry? returnPortNameWithCountry;
String? shipCode;
String? shipName;
String? cruiseStatus;
String? cruiseStatusApp;
CruisingCategory? cruisingCategory;
String? cruiseCancelledInfo;
DateTime? modifiedDate;
bool? isAddOnHoliday;
String? bookingRef;
String? agentName;
String? guests;
factory PastCruise.fromJson(Map<String, dynamic> json) => PastCruise(
cruiseId: json["CruiseId"],
name: json["Name"],
shortName: json["ShortName"],
departureDate: DateTime.parse(json["DepartureDate"]),
returnDate: DateTime.parse(json["ReturnDate"]),
duration: json["Duration"],
shortDescription: json["ShortDescription"],
departurePortCode: portCodeValues.map[json["DeparturePortCode"]],
departurePortName: portNameValues.map[json["DeparturePortName"]],
departurePortNameWithCountry: portNameWithCountryValues.map[json["DeparturePortNameWithCountry"]],
returnPortCode: portCodeValues.map[json["ReturnPortCode"]],
returnPortName: portNameValues.map[json["ReturnPortName"]],
returnPortNameWithCountry: portNameWithCountryValues.map[json["ReturnPortNameWithCountry"]],
shipCode: json["ShipCode"],
shipName: json["ShipName"],
cruiseStatus: json["CruiseStatus"],
cruiseStatusApp: json["CruiseStatusApp"],
cruisingCategory: cruisingCategoryValues.map[json["CruisingCategory"]],
cruiseCancelledInfo: json["CruiseCancelledInfo"],
modifiedDate: DateTime.parse(json["ModifiedDate"]),
isAddOnHoliday: json["IsAddOnHoliday"],
bookingRef: json["BookingRef"],
agentName: json["AgentName"],
guests: json["Guests"],
);
Map<String, dynamic> toJson() => {
"CruiseId": cruiseId,
"Name": name,
"ShortName": shortName,
"Duration": duration,
"ShortDescription": shortDescription,
"DeparturePortCode": portCodeValues.reverse[departurePortCode],
"DeparturePortName": portNameValues.reverse[departurePortName],
"DeparturePortNameWithCountry": portNameWithCountryValues.reverse[departurePortNameWithCountry],
"ReturnPortCode": portCodeValues.reverse[returnPortCode],
"ReturnPortName": portNameValues.reverse[returnPortName],
"ReturnPortNameWithCountry": portNameWithCountryValues.reverse[returnPortNameWithCountry],
"ShipCode": shipCode,
"ShipName": shipName,
"CruiseStatus": cruiseStatus,
"CruiseStatusApp": cruiseStatusApp,
"CruisingCategory": cruisingCategoryValues.reverse[cruisingCategory],
"CruiseCancelledInfo": cruiseCancelledInfo,
"IsAddOnHoliday": isAddOnHoliday,
"BookingRef": bookingRef,
"AgentName": agentName,
"Guests": guests,
};
}
class EnumValues<T> {
Map<String, T> map;
Map<T, String>? reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap!;
}
}