mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 23:08:59 +00:00
Flutter 3.29 beta (#2571)
This commit is contained in:
@@ -25,10 +25,7 @@ part 'locations.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class LatLng {
|
||||
LatLng({
|
||||
required this.lat,
|
||||
required this.lng,
|
||||
});
|
||||
LatLng({required this.lat, required this.lng});
|
||||
|
||||
factory LatLng.fromJson(Map<String, dynamic> json) => _$LatLngFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$LatLngToJson(this);
|
||||
@@ -83,10 +80,7 @@ class Office {
|
||||
|
||||
@JsonSerializable()
|
||||
class Locations {
|
||||
Locations({
|
||||
required this.offices,
|
||||
required this.regions,
|
||||
});
|
||||
Locations({required this.offices, required this.regions});
|
||||
|
||||
factory Locations.fromJson(Map<String, dynamic> json) =>
|
||||
_$LocationsFromJson(json);
|
||||
@@ -104,7 +98,8 @@ Future<Locations> getGoogleOffices() async {
|
||||
final response = await http.get(Uri.parse(googleLocationsURL));
|
||||
if (response.statusCode == 200) {
|
||||
return Locations.fromJson(
|
||||
json.decode(response.body) as Map<String, dynamic>);
|
||||
json.decode(response.body) as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
@@ -114,8 +109,7 @@ Future<Locations> getGoogleOffices() async {
|
||||
|
||||
// Fallback for when the above HTTP request fails.
|
||||
return Locations.fromJson(
|
||||
json.decode(
|
||||
await rootBundle.loadString('assets/locations.json'),
|
||||
) as Map<String, dynamic>,
|
||||
json.decode(await rootBundle.loadString('assets/locations.json'))
|
||||
as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,61 +23,63 @@ part of 'locations.dart';
|
||||
// **************************************************************************
|
||||
|
||||
LatLng _$LatLngFromJson(Map<String, dynamic> json) => LatLng(
|
||||
lat: (json['lat'] as num).toDouble(),
|
||||
lng: (json['lng'] as num).toDouble(),
|
||||
);
|
||||
lat: (json['lat'] as num).toDouble(),
|
||||
lng: (json['lng'] as num).toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$LatLngToJson(LatLng instance) => <String, dynamic>{
|
||||
'lat': instance.lat,
|
||||
'lng': instance.lng,
|
||||
};
|
||||
'lat': instance.lat,
|
||||
'lng': instance.lng,
|
||||
};
|
||||
|
||||
Region _$RegionFromJson(Map<String, dynamic> json) => Region(
|
||||
coords: LatLng.fromJson(json['coords'] as Map<String, dynamic>),
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
zoom: (json['zoom'] as num).toDouble(),
|
||||
);
|
||||
coords: LatLng.fromJson(json['coords'] as Map<String, dynamic>),
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
zoom: (json['zoom'] as num).toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$RegionToJson(Region instance) => <String, dynamic>{
|
||||
'coords': instance.coords,
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'zoom': instance.zoom,
|
||||
};
|
||||
'coords': instance.coords,
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'zoom': instance.zoom,
|
||||
};
|
||||
|
||||
Office _$OfficeFromJson(Map<String, dynamic> json) => Office(
|
||||
address: json['address'] as String,
|
||||
id: json['id'] as String,
|
||||
image: json['image'] as String,
|
||||
lat: (json['lat'] as num).toDouble(),
|
||||
lng: (json['lng'] as num).toDouble(),
|
||||
name: json['name'] as String,
|
||||
phone: json['phone'] as String,
|
||||
region: json['region'] as String,
|
||||
);
|
||||
address: json['address'] as String,
|
||||
id: json['id'] as String,
|
||||
image: json['image'] as String,
|
||||
lat: (json['lat'] as num).toDouble(),
|
||||
lng: (json['lng'] as num).toDouble(),
|
||||
name: json['name'] as String,
|
||||
phone: json['phone'] as String,
|
||||
region: json['region'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$OfficeToJson(Office instance) => <String, dynamic>{
|
||||
'address': instance.address,
|
||||
'id': instance.id,
|
||||
'image': instance.image,
|
||||
'lat': instance.lat,
|
||||
'lng': instance.lng,
|
||||
'name': instance.name,
|
||||
'phone': instance.phone,
|
||||
'region': instance.region,
|
||||
};
|
||||
'address': instance.address,
|
||||
'id': instance.id,
|
||||
'image': instance.image,
|
||||
'lat': instance.lat,
|
||||
'lng': instance.lng,
|
||||
'name': instance.name,
|
||||
'phone': instance.phone,
|
||||
'region': instance.region,
|
||||
};
|
||||
|
||||
Locations _$LocationsFromJson(Map<String, dynamic> json) => Locations(
|
||||
offices: (json['offices'] as List<dynamic>)
|
||||
offices:
|
||||
(json['offices'] as List<dynamic>)
|
||||
.map((e) => Office.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
regions: (json['regions'] as List<dynamic>)
|
||||
regions:
|
||||
(json['regions'] as List<dynamic>)
|
||||
.map((e) => Region.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$LocationsToJson(Locations instance) => <String, dynamic>{
|
||||
'offices': instance.offices,
|
||||
'regions': instance.regions,
|
||||
};
|
||||
'offices': instance.offices,
|
||||
'regions': instance.regions,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user