61 lines
1.4 KiB
Dart
61 lines
1.4 KiB
Dart
class CitySelectionResponse {
|
|
final List<CitySelection> cities;
|
|
|
|
CitySelectionResponse({required this.cities});
|
|
|
|
factory CitySelectionResponse.fromJson(Map<String, dynamic> json) {
|
|
return CitySelectionResponse(
|
|
cities: (json['cities'] as List<dynamic>?)
|
|
?.map((city) => CitySelection.fromJson(city as Map<String, dynamic>))
|
|
.toList() ??
|
|
[],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'cities': cities.map((city) => city.toJson()).toList(),
|
|
};
|
|
}
|
|
}
|
|
|
|
class CitySelection {
|
|
final int id;
|
|
final String cityName;
|
|
final String bannerImage;
|
|
|
|
CitySelection({
|
|
required this.id,
|
|
required this.cityName,
|
|
required this.bannerImage,
|
|
});
|
|
|
|
factory CitySelection.fromJson(Map<String, dynamic> json) {
|
|
return CitySelection(
|
|
id: json['id'] as int? ?? 0,
|
|
cityName: json['cityName'] as String? ?? '',
|
|
bannerImage: json['bannerImage'] as String? ?? '',
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'cityName': cityName,
|
|
'bannerImage': bannerImage,
|
|
};
|
|
}
|
|
|
|
// Helper method to get the image URL with fallback
|
|
String getImageUrl() {
|
|
if (bannerImage.isEmpty || !bannerImage.startsWith('http')) {
|
|
return 'assets/images/card_banner.png';
|
|
}
|
|
return bannerImage;
|
|
}
|
|
|
|
// Helper method to check if image is network image
|
|
bool isNetworkImage() {
|
|
return bannerImage.isNotEmpty && bannerImage.startsWith('http');
|
|
}
|
|
} |