DRY up some search and places code
This commit is contained in:
@ -2,6 +2,8 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:sendtrain/models/google_place_model.dart';
|
||||
import 'package:sendtrain/widgets/generic/elements/form_search_input.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class GooglePlacesService {
|
||||
@ -33,11 +35,12 @@ class GooglePlacesService {
|
||||
|
||||
if (result.isNotEmpty) {
|
||||
return result['places']
|
||||
.map<Suggestion>((p) => Suggestion(
|
||||
placeId: p['id'],
|
||||
description: p['displayName']['text'],
|
||||
address: p['formattedAddress'],
|
||||
imageReferences: p['photos']))
|
||||
.map<Suggestion>((p) => Suggestion<GooglePlaceModel>(
|
||||
GooglePlaceModel(
|
||||
placeId: p['id'],
|
||||
description: p['displayName']['text'],
|
||||
address: p['formattedAddress'],
|
||||
imageReferences: p['photos'])))
|
||||
.toList();
|
||||
} else {
|
||||
return null;
|
||||
@ -52,9 +55,10 @@ class GooglePlacesService {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
};
|
||||
|
||||
var request = Request('GET',
|
||||
Uri.parse('https://places.googleapis.com/v1/$name/media?key=$apiKey&maxWidthPx=800&skipHttpRedirect=true')
|
||||
);
|
||||
var request = Request(
|
||||
'GET',
|
||||
Uri.parse(
|
||||
'https://places.googleapis.com/v1/$name/media?key=$apiKey&maxWidthPx=800&skipHttpRedirect=true'));
|
||||
request.headers.addAll(headers);
|
||||
|
||||
StreamedResponse response = await request.send();
|
||||
@ -72,28 +76,3 @@ class GooglePlacesService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Suggestion {
|
||||
final String placeId;
|
||||
final String description;
|
||||
final String address;
|
||||
final List<dynamic>? imageReferences;
|
||||
|
||||
Suggestion(
|
||||
{required this.placeId,
|
||||
required this.description,
|
||||
required this.address,
|
||||
this.imageReferences});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Suggestion(description: $description, placeId: $placeId)';
|
||||
}
|
||||
|
||||
Map toJson() => {
|
||||
'placeId': placeId,
|
||||
'name': description,
|
||||
'address': address,
|
||||
'imageReferences': imageReferences
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user