diff --git a/example/ios/Flutter/Debug.xcconfig b/example/ios/Flutter/Debug.xcconfig index 592ceee8..ec97fc6f 100644 --- a/example/ios/Flutter/Debug.xcconfig +++ b/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Flutter/Release.xcconfig b/example/ios/Flutter/Release.xcconfig index 592ceee8..c4855bfe 100644 --- a/example/ios/Flutter/Release.xcconfig +++ b/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Podfile b/example/ios/Podfile new file mode 100644 index 00000000..1e8c3c90 --- /dev/null +++ b/example/ios/Podfile @@ -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 diff --git a/example/pubspec.lock b/example/pubspec.lock index e2d891c1..03efc3a3 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/lib/providers/place_provider.dart b/lib/providers/place_provider.dart index 4c364709..e38dd24b 100644 --- a/lib/providers/place_provider.dart +++ b/lib/providers/place_provider.dart @@ -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( @@ -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 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 { diff --git a/lib/src/google_map_place_picker.dart b/lib/src/google_map_place_picker.dart index 561a3bef..fceb52b2 100644 --- a/lib/src/google_map_place_picker.dart +++ b/lib/src/google_map_place_picker.dart @@ -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; @@ -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, ); @@ -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); @@ -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())), + gestureRecognizers: Set() + ..add(Factory(() => EagerGestureRecognizer())), ); }); } @@ -284,15 +290,20 @@ class GoogleMapPlacePicker extends StatelessWidget { Widget _buildFloatingCard() { return Selector>( - 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)); } } }, @@ -300,6 +311,13 @@ class GoogleMapPlacePicker extends StatelessWidget { } 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, @@ -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!), ); } @@ -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); - }, ), ], ), @@ -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), @@ -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), diff --git a/pubspec.lock b/pubspec.lock index 253df8c7..61e1d02a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -120,7 +120,7 @@ packages: 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: "direct main" description: @@ -149,6 +149,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" + location: + dependency: "direct main" + 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: @@ -191,20 +212,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.11.0" - permission_handler: - dependency: "direct main" - 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: @@ -237,7 +244,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: @@ -279,7 +286,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" tuple: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 29c30924..b28908aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,18 +9,17 @@ environment: dependencies: flutter: sdk: flutter - - google_maps_flutter: ^2.0.1 geolocator: ^7.0.1 - permission_handler: ^6.0.1+1 - provider: ^5.0.0 - google_maps_webservice: ^0.0.20-nullsafety.2 google_api_headers: ^1.0.0 - tuple: ^2.0.0-nullsafety.0 + google_maps_flutter: ^2.0.1 + google_maps_webservice: ^0.0.20-nullsafety.5 http: ^0.13.0 + location: ^4.3.0 + provider: ^5.0.0 + tuple: ^2.0.0-nullsafety.0 dev_dependencies: flutter_test: sdk: flutter -flutter: +flutter: null