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

close keyboard when choosing a location , add marker color , fix animate to… #122

Open
wants to merge 20 commits 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
15 changes: 15 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/henno/development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/henno/Desktop/edit_packages/google_location_picker_v4/google_map_location_picker/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/henno/development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1.0.0"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
14 changes: 8 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:google_map_location_picker/generated/l10n.dart'
as location_picker;
import 'package:google_map_location_picker/google_map_location_picker.dart';
import 'package:google_map_location_picker_example/keys.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

import 'generated/i18n.dart';
Expand Down Expand Up @@ -51,17 +50,20 @@ class _MyAppState extends State<MyApp> {
RaisedButton(
onPressed: () async {
LocationResult result = await showLocationPicker(
context, apiKey,
initialCenter: LatLng(31.1975844, 29.9598339),
// automaticallyAnimateToCurrentLocation: true,
context,
api_key,
initialCenter: null,
automaticallyImplyLeading: true, // by default true
automaticallyAnimateToCurrentLocation: true,
// mapStylePath: 'assets/mapStyle.json',
myLocationButtonEnabled: true,
// requiredGPS: true,
layersButtonEnabled: true,
// countries: ['AE', 'NG']
//markerColor: Colors.green,
// countries: ['SA'],

// resultCardAlignment: Alignment.bottomCenter,
desiredAccuracy: LocationAccuracy.best,
desiredAccuracy: LocationAccuracy.low,
);
print("result = $result");
setState(() => _pickedLocation = result);
Expand Down
129 changes: 73 additions & 56 deletions lib/src/google_map_location_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ import 'model/nearby_place.dart';
import 'utils/location_utils.dart';

class LocationPicker extends StatefulWidget {
LocationPicker(
this.apiKey, {
Key key,
this.initialCenter,
this.initialZoom,
this.requiredGPS,
this.myLocationButtonEnabled,
this.layersButtonEnabled,
this.automaticallyAnimateToCurrentLocation,
this.mapStylePath,
this.appBarColor,
this.searchBarBoxDecoration,
this.hintText,
this.resultCardConfirmIcon,
this.resultCardAlignment,
this.resultCardDecoration,
this.resultCardPadding,
this.countries,
this.language,
this.desiredAccuracy,
});
LocationPicker(this.apiKey,
{Key key,
this.initialCenter,
this.initialZoom,
this.requiredGPS,
this.myLocationButtonEnabled,
this.layersButtonEnabled,
this.automaticallyAnimateToCurrentLocation,
this.mapStylePath,
this.appBarColor,
this.searchBarBoxDecoration,
this.hintText,
this.resultCardConfirmIcon,
this.resultCardAlignment,
this.resultCardDecoration,
this.resultCardPadding,
this.countries,
this.language,
this.desiredAccuracy,
this.markerColor,
this.automaticallyImplyLeading});

final String apiKey;

Expand All @@ -52,9 +52,9 @@ class LocationPicker extends StatefulWidget {
final bool myLocationButtonEnabled;
final bool layersButtonEnabled;
final bool automaticallyAnimateToCurrentLocation;

final bool automaticallyImplyLeading;
final String mapStylePath;

final Color markerColor;
final Color appBarColor;
final BoxDecoration searchBarBoxDecoration;
final String hintText;
Expand Down Expand Up @@ -90,6 +90,7 @@ class LocationPickerState extends State<LocationPicker> {
var searchInputKey = GlobalKey<SearchInputState>();

bool hasSearchTerm = false;
bool showSugesstion = true;

/// Hides the autocomplete overlay
void clearOverlay() {
Expand Down Expand Up @@ -130,7 +131,7 @@ class LocationPickerState extends State<LocationPicker> {
SizedBox(
height: 24,
width: 24,
child: CircularProgressIndicator(strokeWidth: 3),
child: CircularProgressIndicator(strokeWidth: 3,backgroundColor:widget.markerColor??Colors.blue),
),
SizedBox(width: 24),
Expanded(
Expand Down Expand Up @@ -200,6 +201,8 @@ class LocationPickerState extends State<LocationPicker> {

suggestions.add(RichSuggestion(aci, () {
decodeAndSelectPlace(aci.id);
FocusScope.of(context).unfocus();
showSugesstion = false;
}));
}
}
Expand Down Expand Up @@ -352,6 +355,7 @@ class LocationPickerState extends State<LocationPicker> {
locationResult.address = road;
locationResult.latLng = latLng;
locationResult.placeId = placeId;
showSugesstion = true;
});
}
}
Expand Down Expand Up @@ -388,41 +392,50 @@ class LocationPickerState extends State<LocationPicker> {
ChangeNotifierProvider(create: (_) => LocationProvider()),
],
child: Builder(builder: (context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
iconTheme: Theme.of(context).iconTheme,
elevation: 0,
backgroundColor: widget.appBarColor,
key: appBarKey,
title: SearchInput(
(input) => searchPlace(input),
key: searchInputKey,
boxDecoration: widget.searchBarBoxDecoration,
return WillPopScope(
onWillPop: () async => widget.automaticallyImplyLeading,
child: Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
iconTheme: Theme.of(context).iconTheme,
elevation: 0,
backgroundColor: widget.appBarColor,
automaticallyImplyLeading: widget.automaticallyImplyLeading,
key: appBarKey,
title: SearchInput(
(input) {
print("input : $input");
if (showSugesstion) searchPlace(input.trim());
},
key: searchInputKey,
boxDecoration: widget.searchBarBoxDecoration,
hintText: widget.hintText,
),
),
body: MapPicker(
widget.apiKey,
initialCenter: widget.initialCenter,
initialZoom: widget.initialZoom,
requiredGPS: widget.requiredGPS,
myLocationButtonEnabled: widget.myLocationButtonEnabled,
layersButtonEnabled: widget.layersButtonEnabled,
automaticallyAnimateToCurrentLocation:
widget.automaticallyAnimateToCurrentLocation,
mapStylePath: widget.mapStylePath,
appBarColor: widget.appBarColor,
automaticallyImplyLeading: widget.automaticallyImplyLeading,
searchBarBoxDecoration: widget.searchBarBoxDecoration,
hintText: widget.hintText,
resultCardConfirmIcon: widget.resultCardConfirmIcon,
resultCardAlignment: widget.resultCardAlignment,
resultCardDecoration: widget.resultCardDecoration,
resultCardPadding: widget.resultCardPadding,
key: mapKey,
language: widget.language,
desiredAccuracy: widget.desiredAccuracy,
markerColor: widget.markerColor,
),
),
body: MapPicker(
widget.apiKey,
initialCenter: widget.initialCenter,
initialZoom: widget.initialZoom,
requiredGPS: widget.requiredGPS,
myLocationButtonEnabled: widget.myLocationButtonEnabled,
layersButtonEnabled: widget.layersButtonEnabled,
automaticallyAnimateToCurrentLocation:
widget.automaticallyAnimateToCurrentLocation,
mapStylePath: widget.mapStylePath,
appBarColor: widget.appBarColor,
searchBarBoxDecoration: widget.searchBarBoxDecoration,
hintText: widget.hintText,
resultCardConfirmIcon: widget.resultCardConfirmIcon,
resultCardAlignment: widget.resultCardAlignment,
resultCardDecoration: widget.resultCardDecoration,
resultCardPadding: widget.resultCardPadding,
key: mapKey,
language: widget.language,
desiredAccuracy: widget.desiredAccuracy,
),
);
}),
);
Expand All @@ -449,6 +462,7 @@ Future<LocationResult> showLocationPicker(
bool myLocationButtonEnabled = false,
bool layersButtonEnabled = false,
bool automaticallyAnimateToCurrentLocation = true,
bool automaticallyImplyLeading = true,
String mapStylePath,
Color appBarColor = Colors.transparent,
BoxDecoration searchBarBoxDecoration,
Expand All @@ -459,6 +473,7 @@ Future<LocationResult> showLocationPicker(
Decoration resultCardDecoration,
String language = 'en',
LocationAccuracy desiredAccuracy = LocationAccuracy.best,
Color markerColor,
}) async {
final results = await Navigator.of(context).push(
MaterialPageRoute<dynamic>(
Expand All @@ -475,6 +490,7 @@ Future<LocationResult> showLocationPicker(
automaticallyAnimateToCurrentLocation,
mapStylePath: mapStylePath,
appBarColor: appBarColor,
automaticallyImplyLeading: automaticallyImplyLeading,
hintText: hintText,
searchBarBoxDecoration: searchBarBoxDecoration,
resultCardConfirmIcon: resultCardConfirmIcon,
Expand All @@ -484,6 +500,7 @@ Future<LocationResult> showLocationPicker(
countries: countries,
language: language,
desiredAccuracy: desiredAccuracy,
markerColor: markerColor,
);
},
),
Expand Down
29 changes: 21 additions & 8 deletions lib/src/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MapPicker extends StatefulWidget {
this.resultCardPadding,
this.language,
this.desiredAccuracy,
this.markerColor,
this.automaticallyImplyLeading
}) : super(key: key);

final String apiKey;
Expand All @@ -49,8 +51,10 @@ class MapPicker extends StatefulWidget {
final bool myLocationButtonEnabled;
final bool layersButtonEnabled;
final bool automaticallyAnimateToCurrentLocation;
final bool automaticallyImplyLeading;

final String mapStylePath;


final Color appBarColor;
final BoxDecoration searchBarBoxDecoration;
Expand All @@ -59,7 +63,7 @@ class MapPicker extends StatefulWidget {
final Alignment resultCardAlignment;
final Decoration resultCardDecoration;
final EdgeInsets resultCardPadding;

final Color markerColor;
final String language;

final LocationAccuracy desiredAccuracy;
Expand Down Expand Up @@ -150,10 +154,12 @@ class MapPickerState extends State<MapPicker> {
if (_currentPosition == null &&
widget.automaticallyAnimateToCurrentLocation &&
widget.requiredGPS) {
return const Center(child: CircularProgressIndicator());
return Center(child: CircularProgressIndicator(strokeWidth: 3,backgroundColor:widget.markerColor??Colors.blue),);
}

return buildMap();
return _currentPosition == null
? Center(child: CircularProgressIndicator(strokeWidth: 3,backgroundColor:widget.markerColor??Colors.blue),)
: buildMap();
},
),
);
Expand All @@ -166,7 +172,8 @@ class MapPickerState extends State<MapPicker> {
GoogleMap(
myLocationButtonEnabled: false,
initialCameraPosition: CameraPosition(
target: widget.initialCenter,
target: widget.initialCenter ??
LatLng(_currentPosition.latitude, _currentPosition.longitude),
zoom: widget.initialZoom,
),
onMapCreated: (GoogleMapController controller) {
Expand All @@ -176,7 +183,8 @@ class MapPickerState extends State<MapPicker> {
controller.setMapStyle(_mapStyle);
}

_lastMapPosition = widget.initialCenter;
_lastMapPosition =
LatLng(_currentPosition.latitude, _currentPosition.longitude);
LocationProvider.of(context, listen: false)
.setLastIdleLocation(_lastMapPosition);
},
Expand Down Expand Up @@ -232,7 +240,7 @@ class MapPickerState extends State<MapPicker> {
loadingIndicator: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
CircularProgressIndicator(strokeWidth: 3,backgroundColor:widget.markerColor??Colors.blue),
],
),
builder: (context, data) {
Expand Down Expand Up @@ -292,12 +300,17 @@ class MapPickerState extends State<MapPicker> {
}

Widget pin() {
print("markerColor : ${widget.markerColor}");
return IgnorePointer(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.place, size: 56),
Icon(
Icons.place,
size: 56,
color: widget.markerColor ?? Colors.black,
),
Container(
decoration: ShapeDecoration(
shadows: [
Expand Down Expand Up @@ -465,7 +478,7 @@ class _MapFabs extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
alignment: Alignment.topRight,
margin: const EdgeInsets.only(top: kToolbarHeight + 24, right: 8),
margin: const EdgeInsets.only(top: kToolbarHeight + 50, right: 8),
child: Column(
children: <Widget>[
if (layersButtonEnabled)
Expand Down
1 change: 1 addition & 0 deletions lib/src/search_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SearchInputState extends State<SearchInput> {
Expanded(
child: TextField(
controller: editController,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
hintText: widget.hintText ??
S.of(context)?.search_place ??
Expand Down
Loading