2023-01-11 17:19:19 +00:00
|
|
|
class Crypto {
|
|
|
|
/// Crypto ticker
|
2023-01-10 21:25:20 +00:00
|
|
|
final String ticker;
|
|
|
|
|
2023-01-11 17:19:19 +00:00
|
|
|
/// Crypto name
|
2023-01-10 21:25:20 +00:00
|
|
|
final String name;
|
|
|
|
|
2023-01-11 17:19:19 +00:00
|
|
|
/// Crypto logo url
|
2023-01-10 21:25:20 +00:00
|
|
|
final String image;
|
|
|
|
|
2023-01-11 17:19:19 +00:00
|
|
|
Crypto({
|
2023-01-10 21:25:20 +00:00
|
|
|
required this.ticker,
|
|
|
|
required this.name,
|
|
|
|
required this.image,
|
|
|
|
});
|
|
|
|
|
2023-01-11 17:19:19 +00:00
|
|
|
factory Crypto.fromJson(Map<String, dynamic> json) {
|
2023-01-10 21:25:20 +00:00
|
|
|
try {
|
2023-01-11 17:19:19 +00:00
|
|
|
return Crypto(
|
2023-01-10 21:25:20 +00:00
|
|
|
ticker: json["ticker"] as String,
|
|
|
|
name: json["name"] as String,
|
|
|
|
image: json["image"] as String,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
final map = {
|
|
|
|
"ticker": ticker,
|
|
|
|
"name": name,
|
|
|
|
"image": image,
|
|
|
|
};
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2023-01-11 17:19:19 +00:00
|
|
|
Crypto copyWith({
|
2023-01-10 21:25:20 +00:00
|
|
|
String? ticker,
|
|
|
|
String? name,
|
|
|
|
String? image,
|
|
|
|
}) {
|
2023-01-11 17:19:19 +00:00
|
|
|
return Crypto(
|
2023-01-10 21:25:20 +00:00
|
|
|
ticker: ticker ?? this.ticker,
|
|
|
|
name: name ?? this.name,
|
|
|
|
image: image ?? this.image,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
2023-01-11 17:19:19 +00:00
|
|
|
return "Crypto: ${toJson()}";
|
2023-01-10 21:25:20 +00:00
|
|
|
}
|
|
|
|
}
|