Skip to content

Commit

Permalink
Replace permission handler package and fix auto complete search issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hareshgediya committed Jun 24, 2021
1 parent d79c3a3 commit 074fa91
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 65 deletions.
1 change: 1 addition & 0 deletions example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
41 changes: 41 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
45 changes: 26 additions & 19 deletions example/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.5.0"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -127,14 +127,14 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.0-nullsafety.2"
version: "2.0.0-nullsafety.3"
google_maps_webservice:
dependency: transitive
description:
name: google_maps_webservice
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.20-nullsafety.2"
version: "0.0.20-nullsafety.5"
http:
dependency: transitive
description:
Expand Down Expand Up @@ -163,6 +163,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
location:
dependency: transitive
description:
name: location
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.0"
location_platform_interface:
dependency: transitive
description:
name: location_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
location_web:
dependency: transitive
description:
name: location_web
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.1"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -205,20 +226,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.0"
permission_handler:
dependency: transitive
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.1+1"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0+1"
plugin_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -251,7 +258,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -293,7 +300,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.3.0"
tuple:
dependency: transitive
description:
Expand Down
18 changes: 15 additions & 3 deletions lib/providers/place_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:google_maps_place_picker/src/place_picker.dart';
import 'package:google_maps_webservice/geocoding.dart';
import 'package:google_maps_webservice/places.dart';
import 'package:http/http.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:location/location.dart' as loc;

class PlaceProvider extends ChangeNotifier {
PlaceProvider(
Expand Down Expand Up @@ -43,10 +43,22 @@ class PlaceProvider extends ChangeNotifier {
LocationAccuracy? desiredAccuracy;
bool isAutoCompleteSearching = false;

loc.Location _location = loc.Location();
loc.PermissionStatus? _permissionStatus;
bool _isLocationServiceEnabled = false;

Future<void> updateCurrentLocation(bool forceAndroidLocationManager) async {
_isLocationServiceEnabled = await _location.serviceEnabled();
if (!_isLocationServiceEnabled) {
_isLocationServiceEnabled = await _location.requestService();
if (!_isLocationServiceEnabled) return;
}

_permissionStatus = await _location.hasPermission();

try {
await Permission.location.request();
if (await Permission.location.request().isGranted) {
_permissionStatus = await _location.requestPermission();
if (_permissionStatus != null && _permissionStatus == loc.PermissionStatus.granted) {
currentPosition = await Geolocator.getCurrentPosition(
desiredAccuracy: desiredAccuracy ?? LocationAccuracy.best);
} else {
Expand Down
61 changes: 43 additions & 18 deletions lib/src/google_map_place_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class GoogleMapPlacePicker extends StatelessWidget {

_searchByCameraLocation(PlaceProvider provider) async {
// We don't want to search location again if camera location is changed by zooming in/out.
bool hasZoomChanged = provider.cameraPosition != null && provider.prevCameraPosition != null && provider.cameraPosition!.zoom != provider.prevCameraPosition!.zoom;
bool hasZoomChanged = provider.cameraPosition != null &&
provider.prevCameraPosition != null &&
provider.cameraPosition!.zoom != provider.prevCameraPosition!.zoom;

if (forceSearchOnZoomChanged == false && hasZoomChanged) {
provider.placeSearchingState = SearchingState.Idle;
Expand All @@ -91,7 +93,9 @@ class GoogleMapPlacePicker extends StatelessWidget {
provider.placeSearchingState = SearchingState.Searching;

final GeocodingResponse response = await provider.geocoding.searchByLocation(
Location(lat: provider.cameraPosition!.target.latitude, lng: provider.cameraPosition!.target.longitude),
Location(
lat: provider.cameraPosition!.target.latitude,
lng: provider.cameraPosition!.target.longitude),
language: language,
);

Expand All @@ -110,7 +114,8 @@ class GoogleMapPlacePicker extends StatelessWidget {
language: language,
);

if (detailResponse.errorMessage?.isNotEmpty == true || detailResponse.status == "REQUEST_DENIED") {
if (detailResponse.errorMessage?.isNotEmpty == true ||
detailResponse.status == "REQUEST_DENIED") {
print("Fetching details by placeId Error: " + detailResponse.errorMessage!);
if (onSearchFailed != null) {
onSearchFailed!(detailResponse.status);
Expand Down Expand Up @@ -208,7 +213,8 @@ class GoogleMapPlacePicker extends StatelessWidget {
},
// gestureRecognizers make it possible to navigate the map when it's a
// child in a scroll view e.g ListView, SingleChildScrollView...
gestureRecognizers: Set()..add(Factory<EagerGestureRecognizer>(() => EagerGestureRecognizer())),
gestureRecognizers: Set()
..add(Factory<EagerGestureRecognizer>(() => EagerGestureRecognizer())),
);
});
}
Expand Down Expand Up @@ -284,22 +290,34 @@ class GoogleMapPlacePicker extends StatelessWidget {

Widget _buildFloatingCard() {
return Selector<PlaceProvider, Tuple4<PickResult?, SearchingState, bool, PinState>>(
selector: (_, provider) => Tuple4(provider.selectedPlace, provider.placeSearchingState, provider.isSearchBarFocused, provider.pinState),
selector: (_, provider) => Tuple4(provider.selectedPlace, provider.placeSearchingState,
provider.isSearchBarFocused, provider.pinState),
builder: (context, data, __) {
if ((data.item1 == null && data.item2 == SearchingState.Idle) || data.item3 == true || data.item4 == PinState.Dragging && this.hidePlaceDetailsWhenDraggingPin!) {
if ((data.item1 == null && data.item2 == SearchingState.Idle) ||
data.item3 == true ||
data.item4 == PinState.Dragging && this.hidePlaceDetailsWhenDraggingPin!) {
return Container();
} else {
if (selectedPlaceWidgetBuilder == null) {
return _defaultPlaceWidgetBuilder(context, data.item1, data.item2);
} else {
return Builder(builder: (builderContext) => selectedPlaceWidgetBuilder!(builderContext, data.item1, data.item2, data.item3));
return Builder(
builder: (builderContext) => selectedPlaceWidgetBuilder!(
builderContext, data.item1, data.item2, data.item3));
}
}
},
);
}

Widget _defaultPlaceWidgetBuilder(BuildContext context, PickResult? data, SearchingState state) {
bool changeStateManually = false;
if (data != null) {
changeStateManually = true;
} else {
changeStateManually = false;
}

return FloatingCard(
bottomPosition: MediaQuery.of(context).size.height * 0.05,
leftPosition: MediaQuery.of(context).size.width * 0.025,
Expand All @@ -308,7 +326,9 @@ class GoogleMapPlacePicker extends StatelessWidget {
borderRadius: BorderRadius.circular(12.0),
elevation: 4.0,
color: Theme.of(context).cardColor,
child: state == SearchingState.Searching ? _buildLoadingIndicator() : _buildSelectionDetails(context, data!),
child: state == SearchingState.Searching && changeStateManually == false
? _buildLoadingIndicator()
: _buildSelectionDetails(context, data!),
);
}

Expand Down Expand Up @@ -336,18 +356,19 @@ class GoogleMapPlacePicker extends StatelessWidget {
textAlign: TextAlign.center,
),
SizedBox(height: 10),
RaisedButton(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
ElevatedButton(
onPressed: () {
onPlacePicked!(result);
},
child: Text(
"Select here",
'Select here',
style: TextStyle(fontSize: 16),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
),
),
onPressed: () {
onPlacePicked!(result);
},
),
],
),
Expand All @@ -368,7 +389,9 @@ class GoogleMapPlacePicker extends StatelessWidget {
height: 35,
child: RawMaterialButton(
shape: CircleBorder(),
fillColor: Theme.of(context).brightness == Brightness.dark ? Colors.black54 : Colors.white,
fillColor: Theme.of(context).brightness == Brightness.dark
? Colors.black54
: Colors.white,
elevation: 8.0,
onPressed: onToggleMapType,
child: Icon(Icons.layers),
Expand All @@ -382,7 +405,9 @@ class GoogleMapPlacePicker extends StatelessWidget {
height: 35,
child: RawMaterialButton(
shape: CircleBorder(),
fillColor: Theme.of(context).brightness == Brightness.dark ? Colors.black54 : Colors.white,
fillColor: Theme.of(context).brightness == Brightness.dark
? Colors.black54
: Colors.white,
elevation: 8.0,
onPressed: onMyLocation,
child: Icon(Icons.my_location),
Expand Down
Loading

1 comment on commit 074fa91

@martin-braun
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this different to fysoul17#76 and fysoul17#88, please? To much reformatting as well.

Please sign in to comment.