-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#15: Build Place API and models using json_serlization
- Loading branch information
1 parent
2106d26
commit 5b9bfed
Showing
7 changed files
with
158 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'package:flutter_app/pages/places/places_models.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
import 'package:flutter_app/pages/places/models.dart'; | ||
// ignore: constant_identifier_names | ||
const BASE_URL = "https://maps.googleapis.com/maps/api/place"; | ||
// ignore: constant_identifier_names | ||
const API_KEY = "AIzaSyBex56icjz1uvDbOn80NDCMM6a7GqRiOBo"; | ||
// ignore: constant_identifier_names | ||
const PLACE_PARAMS = | ||
"/findplacefromtext/json?key=$API_KEY&inputtype=textquery&fields=photos,formatted_address,name,geometry&&input="; | ||
// ignore: constant_identifier_names | ||
const SEARCH_PLACE_ENDPOINT = BASE_URL + PLACE_PARAMS; | ||
|
||
class PlacesApiService { | ||
Future<Locations> getGoogleOffices() async { | ||
const googleLocationsURL = | ||
'https://about.google/static/data/locations.json'; | ||
|
||
Future<PlaceResponse> searchPlaces(String placeQuery) async { | ||
final googlePlacesURL = SEARCH_PLACE_ENDPOINT + placeQuery; | ||
// Retrieve the locations of Google offices | ||
final response = await http.get(googleLocationsURL); | ||
final response = await http.get(googlePlacesURL); | ||
if (response.statusCode == 200) { | ||
return Locations.fromJson(json.decode(response.body)); | ||
return PlaceResponse.fromJson(json.decode(response.body)); | ||
} else { | ||
throw HttpException( | ||
'Unexpected status code ${response.statusCode}:' | ||
' ${response.reasonPhrase}', | ||
uri: Uri.parse(googleLocationsURL)); | ||
uri: Uri.parse(googlePlacesURL)); | ||
} | ||
} | ||
} |
Oops, something went wrong.