From 911f7ec2dc8d732c645519e5e0925c2b4a1cd39e Mon Sep 17 00:00:00 2001 From: Elnur Akhundov Date: Sun, 5 Feb 2023 21:51:27 +0400 Subject: [PATCH] missing translation and country code --- example/example.dart | 4 ++-- lib/entities/localization_item.dart | 3 ++- lib/widgets/place_picker.dart | 13 ++++++++----- lib/widgets/search_input.dart | 12 ++++++++---- pubspec.lock | 24 ++++++++++++------------ 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/example/example.dart b/example/example.dart index 768db3f..bc93be1 100644 --- a/example/example.dart +++ b/example/example.dart @@ -23,8 +23,8 @@ class PickerDemoState extends State { } 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); diff --git a/lib/entities/localization_item.dart b/lib/entities/localization_item.dart index 985416f..5d16857 100644 --- a/lib/entities/localization_item.dart +++ b/lib/entities/localization_item.dart @@ -5,7 +5,7 @@ class LocalizationItem { String noResultsFound; String unnamedLocation; String tapToSelectLocation; - + String searchPlace; LocalizationItem({ this.languageCode = 'en_us', @@ -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', }); } diff --git a/lib/widgets/place_picker.dart b/lib/widgets/place_picker.dart index dc2aec1..71c5ac8 100644 --- a/lib/widgets/place_picker.dart +++ b/lib/widgets/place_picker.dart @@ -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(); @@ -137,14 +138,14 @@ class PlacePickerState extends State { 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, ), @@ -193,7 +194,8 @@ class PlacePickerState extends State { 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( @@ -293,6 +295,7 @@ class PlacePickerState extends State { 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}"; diff --git a/lib/widgets/search_input.dart b/lib/widgets/search_input.dart index 299c917..855ac6a 100644 --- a/lib/widgets/search_input.dart +++ b/lib/widgets/search_input.dart @@ -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 onSearchInput; + final LocalizationItem localizationItem; - SearchInput(this.onSearchInput); + SearchInput(this.onSearchInput, this.localizationItem); @override State createState() => SearchInputState(); @@ -57,11 +58,14 @@ class SearchInputState extends State { padding: EdgeInsets.symmetric(horizontal: 8), child: Row( children: [ - 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(() { diff --git a/pubspec.lock b/pubspec.lock index 56e97de..5acc00b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: @@ -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 @@ -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: @@ -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: @@ -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: