Skip to content

Instantly share code, notes, and snippets.

@rubywai
Created June 7, 2025 04:49
Show Gist options
  • Save rubywai/609f1451f6a0fd854c3d86c4e148b7d8 to your computer and use it in GitHub Desktop.
Save rubywai/609f1451f6a0fd854c3d86c4e148b7d8 to your computer and use it in GitHub Desktop.
import 'package:json_annotation/json_annotation.dart';
part 'city_model.g.dart';
@JsonSerializable()
class CityModel {
final List<CitySearchModel> results;
CityModel({required this.results});
factory CityModel.fromJson(Map<String, dynamic> json) =>
_$CityModelFromJson(json);
Map<String, dynamic> toJson() => _$CityModelToJson(this);
}
@JsonSerializable()
class CitySearchModel {
final num id;
final String name;
final double latitude;
final double longitude;
final String country;
CitySearchModel({
required this.id,
required this.name,
required this.latitude,
required this.longitude,
required this.country,
});
factory CitySearchModel.fromJson(Map<String, dynamic> json) =>
_$CitySearchModelFromJson(json);
Map<String, dynamic> toJson() => _$CitySearchModelToJson(this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment