Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing translation and country code #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class PickerDemoState extends State<PickerDemo> {
}

void showPlacePicker() async {
LocationResult? result = await Navigator.of(context).push(
MaterialPageRoute(builder: (context) => PlacePicker("YOUR API KEY")));
LocationResult? result = await Navigator.of(context).push(MaterialPageRoute(
builder: (context) => PlacePicker("YOUR API KEY", 'AZ')));

// Handle the result in your way
print(result);
Expand Down
3 changes: 2 additions & 1 deletion lib/entities/localization_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LocalizationItem {
String noResultsFound;
String unnamedLocation;
String tapToSelectLocation;

String searchPlace;

LocalizationItem({
this.languageCode = 'en_us',
Expand All @@ -14,5 +14,6 @@ class LocalizationItem {
this.noResultsFound = 'No results found',
this.unnamedLocation = 'Unnamed location',
this.tapToSelectLocation = 'Tap to select this location',
this.searchPlace = 'Search place',
});
}
13 changes: 8 additions & 5 deletions lib/widgets/place_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ class PlacePicker extends StatefulWidget {
/// API key generated from Google Cloud Console. You can get an API key
/// [here](https://cloud.google.com/maps-platform/)
final String apiKey;
final String countryCode;

/// Location to be displayed when screen is showed. If this is set or not null, the
/// map does not pan to the user's current location.
final LatLng? displayLocation;
LocalizationItem? localizationItem;
LatLng defaultLocation = LatLng(10.5381264, 73.8827201);
LatLng defaultLocation = LatLng(40.371642, 49.840411);

PlacePicker(this.apiKey,
PlacePicker(this.apiKey, this.countryCode,
{this.displayLocation, this.localizationItem, LatLng? defaultLocation}) {
if (this.localizationItem == null) {
this.localizationItem = new LocalizationItem();
Expand Down Expand Up @@ -137,14 +138,14 @@ class PlacePickerState extends State<PlacePicker> {
locationResult = null;
_delayedPop();
return Future.value(false);
} else {
} else {
return Future.value(true);
}
},
child: Scaffold(
appBar: AppBar(
key: this.appBarKey,
title: SearchInput(searchPlace),
title: SearchInput(searchPlace, widget.localizationItem!),
centerTitle: true,
automaticallyImplyLeading: false,
),
Expand Down Expand Up @@ -193,7 +194,8 @@ class PlacePickerState extends State<PlacePicker> {
Padding(
child: Text(widget.localizationItem!.nearBy,
style: TextStyle(fontSize: 16)),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
padding:
EdgeInsets.symmetric(horizontal: 24, vertical: 8),
),
Expanded(
child: ListView(
Expand Down Expand Up @@ -293,6 +295,7 @@ class PlacePickerState extends State<PlacePicker> {

var endpoint =
"https://maps.googleapis.com/maps/api/place/autocomplete/json?"
"components=country:${widget.countryCode}&"
"key=${widget.apiKey}&"
"language=${widget.localizationItem!.languageCode}&"
"input={$place}&sessiontoken=${this.sessionToken}";
Expand Down
12 changes: 8 additions & 4 deletions lib/widgets/search_input.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'dart:async';

import 'package:flutter/material.dart';
import '../entities/localization_item.dart';

/// Custom Search input field, showing the search and clear icons.
class SearchInput extends StatefulWidget {
final ValueChanged<String> onSearchInput;
final LocalizationItem localizationItem;

SearchInput(this.onSearchInput);
SearchInput(this.onSearchInput, this.localizationItem);

@override
State<StatefulWidget> createState() => SearchInputState();
Expand Down Expand Up @@ -57,11 +58,14 @@ class SearchInputState extends State<SearchInput> {
padding: EdgeInsets.symmetric(horizontal: 8),
child: Row(
children: <Widget>[
Icon(Icons.search, color: Theme.of(context).textTheme.bodyText1?.color),
Icon(Icons.search,
color: Theme.of(context).textTheme.bodyText1?.color),
SizedBox(width: 8),
Expanded(
child: TextField(
decoration: InputDecoration(hintText: "Search place", border: InputBorder.none),
decoration: InputDecoration(
hintText: widget.localizationItem!.searchPlace,
border: InputBorder.none),
controller: this.editController,
onChanged: (value) {
setState(() {
Expand Down
24 changes: 12 additions & 12 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
charcode:
dependency: transitive
description:
Expand All @@ -35,7 +35,7 @@ packages:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
Expand All @@ -49,7 +49,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -169,28 +169,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
plugin_platform_interface:
dependency: transitive
description:
Expand All @@ -209,7 +209,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -237,21 +237,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
typed_data:
dependency: transitive
description:
Expand Down