diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 00000000..8005dae4 --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/athul/AIN/Softwares/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/athul/AIN/Code/Packages/google_map_location_picker/example" +export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build/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" diff --git a/example/lib/generated/i18n.dart b/example/lib/generated/i18n.dart index b5e27a19..655e0659 100644 --- a/example/lib/generated/i18n.dart +++ b/example/lib/generated/i18n.dart @@ -11,12 +11,12 @@ import 'package:flutter/material.dart'; class S implements WidgetsLocalizations { const S(); - static S current; + static S? current; static const GeneratedLocalizationsDelegate delegate = GeneratedLocalizationsDelegate(); - static S of(BuildContext context) => Localizations.of(context, S); + static S? of(BuildContext context) => Localizations.of(context, S); @override TextDirection get textDirection => TextDirection.ltr; @@ -33,7 +33,7 @@ class $en extends S { const $en(); } -class GeneratedLocalizationsDelegate extends LocalizationsDelegate { +class GeneratedLocalizationsDelegate extends LocalizationsDelegate { const GeneratedLocalizationsDelegate(); List get supportedLocales { @@ -44,8 +44,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { } LocaleListResolutionCallback listResolution( - {Locale fallback, bool withCountry = true}) { - return (List locales, Iterable supported) { + {Locale? fallback, bool withCountry = true}) { + return (List? locales, Iterable supported) { if (locales == null || locales.isEmpty) { return fallback ?? supported.first; } else { @@ -55,29 +55,29 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { } LocaleResolutionCallback resolution( - {Locale fallback, bool withCountry = true}) { - return (Locale locale, Iterable supported) { + {Locale? fallback, bool withCountry = true}) { + return (Locale? locale, Iterable supported) { return _resolve(locale, fallback, supported, withCountry); }; } @override - Future load(Locale locale) { + Future load(Locale locale) { final String lang = getLang(locale); if (lang != null) { switch (lang) { case "ar": S.current = const $ar(); - return SynchronousFuture(S.current); + return SynchronousFuture(S.current); case "en": S.current = const $en(); - return SynchronousFuture(S.current); + return SynchronousFuture(S.current); default: // NO-OP. } } S.current = const S(); - return SynchronousFuture(S.current); + return SynchronousFuture(S.current); } @override @@ -89,7 +89,7 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { /// /// Internal method to resolve a locale from a list of locales. /// - Locale _resolve(Locale locale, Locale fallback, Iterable supported, + Locale _resolve(Locale? locale, Locale? fallback, Iterable supported, bool withCountry) { if (locale == null || !_isSupported(locale, withCountry)) { return fallback ?? supported.first; @@ -125,7 +125,7 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { // If no country requirement is requested, check if this locale has no country. if (true != withCountry && (supportedLocale.countryCode == null || - supportedLocale.countryCode.isEmpty)) { + supportedLocale.countryCode!.isEmpty)) { return true; } } @@ -136,6 +136,6 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { String getLang(Locale l) => l == null ? null - : l.countryCode != null && l.countryCode.isEmpty + : l.countryCode != null && l.countryCode!.isEmpty ? l.languageCode : l.toString(); diff --git a/example/lib/main.dart b/example/lib/main.dart index 4b345412..4d77eda9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,7 +3,7 @@ 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 './keys.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'generated/i18n.dart'; @@ -16,7 +16,7 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - LocationResult _pickedLocation; + LocationResult? _pickedLocation; @override Widget build(BuildContext context) { @@ -48,9 +48,9 @@ class _MyAppState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - RaisedButton( + ElevatedButton( onPressed: () async { - LocationResult result = await showLocationPicker( + LocationResult? result = await showLocationPicker( context, apiKey, initialCenter: LatLng(31.1975844, 29.9598339), diff --git a/example/pubspec.lock b/example/pubspec.lock index b1713335..3ecee911 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -56,7 +56,7 @@ packages: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.0.2" fake_async: dependency: transitive description: @@ -80,7 +80,7 @@ packages: name: flutter_plugin_android_lifecycle url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -97,49 +97,49 @@ packages: name: geolocator url: "https://pub.dartlang.org" source: hosted - version: "6.2.1" + version: "7.0.1" geolocator_platform_interface: dependency: transitive description: name: geolocator_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.9" + version: "2.0.0" geolocator_web: dependency: transitive description: name: geolocator_web url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "2.0.3" google_map_location_picker: dependency: "direct dev" description: path: ".." relative: true source: path - version: "4.1.6" + version: "4.1.7" google_maps_flutter: dependency: transitive description: name: google_maps_flutter url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.2" google_maps_flutter_platform_interface: dependency: transitive description: name: google_maps_flutter_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.4" http: dependency: transitive description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.0" + version: "0.13.1" http_parser: dependency: transitive description: @@ -216,7 +216,7 @@ packages: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.0" provider: dependency: transitive description: @@ -293,5 +293,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0-259.9.beta <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=2.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 862594e4..7ae11d02 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' version: 1.0.0 environment: - sdk: ">=2.2.2 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: diff --git a/lib/generated/intl/messages_all.dart b/lib/generated/intl/messages_all.dart index f633e6ff..b22af192 100644 --- a/lib/generated/intl/messages_all.dart +++ b/lib/generated/intl/messages_all.dart @@ -40,7 +40,7 @@ Map _deferredLibraries = { 'tr': () => new Future.value(null), }; -MessageLookupByLibrary _findExact(String localeName) { +MessageLookupByLibrary? _findExact(String localeName) { switch (localeName) { case 'ar': return messages_ar.messages; @@ -91,7 +91,7 @@ bool _messagesExistFor(String locale) { } } -MessageLookupByLibrary _findGeneratedMessagesFor(String locale) { +MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) { var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null); if (actualLocale == null) return null; diff --git a/lib/generated/intl/messages_ar.dart b/lib/generated/intl/messages_ar.dart index be032a5c..be4ccfb8 100644 --- a/lib/generated/intl/messages_ar.dart +++ b/lib/generated/intl/messages_ar.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'ar'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("تم رفض إذن الوصل الي الموقع الجغرافي"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("تم رفض إذن الوصل الي الموقع الجغرافي بشكل نهائي"), diff --git a/lib/generated/intl/messages_de.dart b/lib/generated/intl/messages_de.dart index 2b6ee3f8..b8df1d3f 100644 --- a/lib/generated/intl/messages_de.dart +++ b/lib/generated/intl/messages_de.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'de'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Zugriff auf Standort verweigert"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("Zugriff auf Standort permanent verweigert"), diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 5bd6290e..dba6fb53 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'en'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Access to location denied"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("Access to location permanently denied"), diff --git a/lib/generated/intl/messages_es.dart b/lib/generated/intl/messages_es.dart index 0a301e0c..858ed892 100644 --- a/lib/generated/intl/messages_es.dart +++ b/lib/generated/intl/messages_es.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'es'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Acceso a la ubicación denegado"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("Acceso a la ubicación denegado permanentemente"), diff --git a/lib/generated/intl/messages_fr.dart b/lib/generated/intl/messages_fr.dart index c3924468..fdd2d342 100644 --- a/lib/generated/intl/messages_fr.dart +++ b/lib/generated/intl/messages_fr.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'fr'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Accès à l\'emplacement refusé"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("Accès à l\'emplacement refusé définitivement"), diff --git a/lib/generated/intl/messages_it.dart b/lib/generated/intl/messages_it.dart index 969dbf5a..f22c4622 100644 --- a/lib/generated/intl/messages_it.dart +++ b/lib/generated/intl/messages_it.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'it'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Accesso alla posizione rifiutato"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("Accesso alla posizione rifiutato permanentemente"), diff --git a/lib/generated/intl/messages_pt.dart b/lib/generated/intl/messages_pt.dart index 869c0e3c..1b178bf0 100644 --- a/lib/generated/intl/messages_pt.dart +++ b/lib/generated/intl/messages_pt.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'pt'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Acesso ao local negado"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("Acesso ao local negado permanentemente"), diff --git a/lib/generated/intl/messages_ru.dart b/lib/generated/intl/messages_ru.dart index ad0dd019..a4e5c343 100644 --- a/lib/generated/intl/messages_ru.dart +++ b/lib/generated/intl/messages_ru.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'ru'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Доступ к местоположению запрещен"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("Доступ к местоположению запрещен навсегда"), diff --git a/lib/generated/intl/messages_sr.dart b/lib/generated/intl/messages_sr.dart index f7120d17..d2f40758 100644 --- a/lib/generated/intl/messages_sr.dart +++ b/lib/generated/intl/messages_sr.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'sr'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Onemogućen pristup lokaciji"), "allow_access_to_the_location_services" : MessageLookupByLibrary.simpleMessage("Omogućite pristup Vašoj lokaciji"), diff --git a/lib/generated/intl/messages_tr.dart b/lib/generated/intl/messages_tr.dart index 690a4d2a..87db67f6 100644 --- a/lib/generated/intl/messages_tr.dart +++ b/lib/generated/intl/messages_tr.dart @@ -19,7 +19,7 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'tr'; - final messages = _notInlinedMessages(_notInlinedMessages); + final Map messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "access_to_location_denied" : MessageLookupByLibrary.simpleMessage("Konum erişimi reddedildi"), "access_to_location_permanently_denied" : MessageLookupByLibrary.simpleMessage("Konuma erişim kalıcı olarak reddedildi"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 5591ce10..3558b672 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -15,7 +15,7 @@ import 'intl/messages_all.dart'; class S { S(); - static S current; + static late S current; static const AppLocalizationDelegate delegate = AppLocalizationDelegate(); @@ -31,7 +31,7 @@ class S { }); } - static S of(BuildContext context) { + static S? of(BuildContext context) { return Localizations.of(context, S); } diff --git a/lib/src/google_map_location_picker.dart b/lib/src/google_map_location_picker.dart index b06dfda0..30d1511d 100644 --- a/lib/src/google_map_location_picker.dart +++ b/lib/src/google_map_location_picker.dart @@ -22,7 +22,7 @@ import 'utils/location_utils.dart'; class LocationPicker extends StatefulWidget { LocationPicker( this.apiKey, { - Key key, + Key? key, this.initialCenter, this.initialZoom, this.requiredGPS, @@ -44,28 +44,28 @@ class LocationPicker extends StatefulWidget { final String apiKey; - final LatLng initialCenter; - final double initialZoom; - final List countries; + final LatLng? initialCenter; + final double? initialZoom; + final List? countries; - final bool requiredGPS; - final bool myLocationButtonEnabled; - final bool layersButtonEnabled; - final bool automaticallyAnimateToCurrentLocation; + final bool? requiredGPS; + final bool? myLocationButtonEnabled; + final bool? layersButtonEnabled; + final bool? automaticallyAnimateToCurrentLocation; - final String mapStylePath; + final String? mapStylePath; - final Color appBarColor; - final BoxDecoration searchBarBoxDecoration; - final String hintText; - final Widget resultCardConfirmIcon; - final Alignment resultCardAlignment; - final Decoration resultCardDecoration; - final EdgeInsets resultCardPadding; + final Color? appBarColor; + final BoxDecoration? searchBarBoxDecoration; + final String? hintText; + final Widget? resultCardConfirmIcon; + final Alignment? resultCardAlignment; + final Decoration? resultCardDecoration; + final EdgeInsets? resultCardPadding; - final String language; + final String? language; - final LocationAccuracy desiredAccuracy; + final LocationAccuracy? desiredAccuracy; @override LocationPickerState createState() => LocationPickerState(); @@ -73,12 +73,12 @@ class LocationPicker extends StatefulWidget { class LocationPickerState extends State { /// Result returned after user completes selection - LocationResult locationResult; + LocationResult? locationResult; /// Overlay to display autocomplete suggestions - OverlayEntry overlayEntry; + OverlayEntry? overlayEntry; - List nearbyPlaces = List(); + List nearbyPlaces = []; /// Session token required for autocomplete API call String sessionToken = Uuid().generateV4(); @@ -94,7 +94,7 @@ class LocationPickerState extends State { /// Hides the autocomplete overlay void clearOverlay() { if (overlayEntry != null) { - overlayEntry.remove(); + overlayEntry!.remove(); overlayEntry = null; } } @@ -112,14 +112,14 @@ class LocationPickerState extends State { if (place.length < 1) return; - final RenderBox renderBox = context.findRenderObject(); + final RenderBox renderBox = context.findRenderObject() as RenderBox; Size size = renderBox.size; - final RenderBox appBarBox = appBarKey.currentContext.findRenderObject(); + final RenderBox? appBarBox = appBarKey.currentContext!.findRenderObject() as RenderBox?; overlayEntry = OverlayEntry( builder: (context) => Positioned( - top: appBarBox.size.height, + top: appBarBox!.size.height, width: size.width, child: Material( elevation: 1, @@ -146,7 +146,7 @@ class LocationPickerState extends State { ), ); - Overlay.of(context).insert(overlayEntry); + Overlay.of(context)!.insert(overlayEntry!); autoCompleteSearch(place); } @@ -159,7 +159,7 @@ class LocationPickerState extends State { // Currently, you can use components to filter by up to 5 countries. from https://developers.google.com/places/web-service/autocomplete String regionParam = countries?.isNotEmpty == true - ? "&components=country:${countries.sublist(0, min(countries.length, 5)).join('|country:')}" + ? "&components=country:${countries!.sublist(0, min(countries.length, 5)).join('|country:')}" : ""; var endpoint = @@ -169,12 +169,12 @@ class LocationPickerState extends State { "language=${widget.language}"; if (locationResult != null) { - endpoint += "&location=${locationResult.latLng.latitude}," + - "${locationResult.latLng.longitude}"; + endpoint += "&location=${locationResult!.latLng!.latitude}," + + "${locationResult!.latLng!.longitude}"; } LocationUtils.getAppHeaders() - .then((headers) => http.get(Uri.parse(endpoint), headers: headers)) + .then((headers) => http.get(Uri.parse(endpoint), headers: headers as Map?)) .then((response) { if (response.statusCode == 200) { Map data = jsonDecode(response.body); @@ -214,7 +214,7 @@ class LocationPickerState extends State { /// To navigate to the selected place from the autocomplete list to the map, /// the lat,lng is required. This method fetches the lat,lng of the place and /// proceeds to moving the map to that location. - void decodeAndSelectPlace(String placeId) { + void decodeAndSelectPlace(String? placeId) { clearOverlay(); final endpoint = @@ -223,7 +223,7 @@ class LocationPickerState extends State { '&language=${widget.language}'; LocationUtils.getAppHeaders() - .then((headers) => http.get(Uri.parse(endpoint), headers: headers)) + .then((headers) => http.get(Uri.parse(endpoint), headers: headers as Map?)) .then((response) { if (response.statusCode == 200) { Map location = @@ -240,17 +240,17 @@ class LocationPickerState extends State { /// Display autocomplete suggestions with the overlay. void displayAutoCompleteSuggestions(List suggestions) { - final RenderBox renderBox = context.findRenderObject(); + final RenderBox renderBox = context.findRenderObject() as RenderBox; Size size = renderBox.size; - final RenderBox appBarBox = appBarKey.currentContext.findRenderObject(); + final RenderBox? appBarBox = appBarKey.currentContext!.findRenderObject() as RenderBox?; clearOverlay(); overlayEntry = OverlayEntry( builder: (context) => Positioned( width: size.width, - top: appBarBox.size.height, + top: appBarBox!.size.height, child: Material( elevation: 1, child: Column( @@ -260,7 +260,7 @@ class LocationPickerState extends State { ), ); - Overlay.of(context).insert(overlayEntry); + Overlay.of(context)!.insert(overlayEntry!); } /// Utility function to get clean readable name of a location. First checks @@ -292,7 +292,7 @@ class LocationPickerState extends State { "location=${latLng.latitude},${latLng.longitude}&radius=150" + "&language=${widget.language}"; - return http.get(Uri.parse(endpoint), headers: headers); + return http.get(Uri.parse(endpoint), headers: headers as Map?); }).then((response) { if (response.statusCode == 200) { nearbyPlaces.clear(); @@ -330,14 +330,14 @@ class LocationPickerState extends State { "&language=${widget.language}"; final response = await http.get(Uri.parse(endpoint), - headers: await LocationUtils.getAppHeaders()); + headers: await (LocationUtils.getAppHeaders() as FutureOr?>)); if (response.statusCode == 200) { Map responseJson = jsonDecode(response.body); - String road; + String? road; - String placeId = responseJson['results'][0]['place_id']; + String? placeId = responseJson['results'][0]['place_id']; if (responseJson['status'] == 'REQUEST_DENIED') { road = 'REQUEST DENIED = please see log for more details'; @@ -352,9 +352,9 @@ class LocationPickerState extends State { setState(() { locationResult = LocationResult(); - locationResult.address = road; - locationResult.latLng = latLng; - locationResult.placeId = placeId; + locationResult!.address = road; + locationResult!.latLng = latLng; + locationResult!.placeId = placeId; }); } } @@ -362,7 +362,7 @@ class LocationPickerState extends State { /// Moves the camera to the provided location and updates other UI features to /// match the location. void moveToLocation(LatLng latLng) { - mapKey.currentState.mapController.future.then((controller) { + mapKey.currentState!.mapController.future.then((controller) { controller.animateCamera( CameraUpdate.newCameraPosition( CameraPosition( @@ -442,24 +442,24 @@ class LocationPickerState extends State { /// set [automaticallyAnimateToCurrentLocation] to false. /// /// -Future showLocationPicker( +Future showLocationPicker( BuildContext context, String apiKey, { LatLng initialCenter = const LatLng(45.521563, -122.677433), double initialZoom = 16, bool requiredGPS = false, - List countries, + List? countries, bool myLocationButtonEnabled = false, bool layersButtonEnabled = false, bool automaticallyAnimateToCurrentLocation = true, - String mapStylePath, + String? mapStylePath, Color appBarColor = Colors.transparent, - BoxDecoration searchBarBoxDecoration, - String hintText, - Widget resultCardConfirmIcon, - AlignmentGeometry resultCardAlignment, - EdgeInsetsGeometry resultCardPadding, - Decoration resultCardDecoration, + BoxDecoration? searchBarBoxDecoration, + String? hintText, + Widget? resultCardConfirmIcon, + AlignmentGeometry? resultCardAlignment, + EdgeInsetsGeometry? resultCardPadding, + Decoration? resultCardDecoration, String language = 'en', LocationAccuracy desiredAccuracy = LocationAccuracy.best, }) async { @@ -481,8 +481,8 @@ Future showLocationPicker( hintText: hintText, searchBarBoxDecoration: searchBarBoxDecoration, resultCardConfirmIcon: resultCardConfirmIcon, - resultCardAlignment: resultCardAlignment, - resultCardPadding: resultCardPadding, + resultCardAlignment: resultCardAlignment as Alignment?, + resultCardPadding: resultCardPadding as EdgeInsets?, resultCardDecoration: resultCardDecoration, countries: countries, language: language, diff --git a/lib/src/map.dart b/lib/src/map.dart index eca20b2c..7e886a96 100644 --- a/lib/src/map.dart +++ b/lib/src/map.dart @@ -21,7 +21,7 @@ import 'utils/location_utils.dart'; class MapPicker extends StatefulWidget { const MapPicker( this.apiKey, { - Key key, + Key? key, this.initialCenter, this.initialZoom, this.requiredGPS, @@ -42,27 +42,27 @@ class MapPicker extends StatefulWidget { final String apiKey; - final LatLng initialCenter; - final double initialZoom; + final LatLng? initialCenter; + final double? initialZoom; - final bool requiredGPS; - final bool myLocationButtonEnabled; - final bool layersButtonEnabled; - final bool automaticallyAnimateToCurrentLocation; + final bool? requiredGPS; + final bool? myLocationButtonEnabled; + final bool? layersButtonEnabled; + final bool? automaticallyAnimateToCurrentLocation; - final String mapStylePath; + final String? mapStylePath; - final Color appBarColor; - final BoxDecoration searchBarBoxDecoration; - final String hintText; - final Widget resultCardConfirmIcon; - final Alignment resultCardAlignment; - final Decoration resultCardDecoration; - final EdgeInsets resultCardPadding; + final Color? appBarColor; + final BoxDecoration? searchBarBoxDecoration; + final String? hintText; + final Widget? resultCardConfirmIcon; + final Alignment? resultCardAlignment; + final Decoration? resultCardDecoration; + final EdgeInsets? resultCardPadding; - final String language; + final String? language; - final LocationAccuracy desiredAccuracy; + final LocationAccuracy? desiredAccuracy; @override MapPickerState createState() => MapPickerState(); @@ -73,15 +73,15 @@ class MapPickerState extends State { MapType _currentMapType = MapType.normal; - String _mapStyle; + String? _mapStyle; - LatLng _lastMapPosition; + LatLng? _lastMapPosition; - Position _currentPosition; + Position? _currentPosition; - String _address; + String? _address; - String _placeId; + String? _placeId; void _onToggleMapTypePressed() { final MapType nextType = @@ -92,11 +92,10 @@ class MapPickerState extends State { // this also checks for location permission. Future _initCurrentLocation() async { - Position currentPosition; + Position? currentPosition; try { - currentPosition = - await getCurrentPosition(desiredAccuracy: widget.desiredAccuracy); - d("position = $currentPosition"); + currentPosition = await Geolocator.getCurrentPosition( + desiredAccuracy: widget.desiredAccuracy!); setState(() => _currentPosition = currentPosition); } catch (e) { @@ -124,11 +123,11 @@ class MapPickerState extends State { @override void initState() { super.initState(); - if (widget.automaticallyAnimateToCurrentLocation && !widget.requiredGPS) + if (widget.automaticallyAnimateToCurrentLocation! && !widget.requiredGPS!) _initCurrentLocation(); if (widget.mapStylePath != null) { - rootBundle.loadString(widget.mapStylePath).then((string) { + rootBundle.loadString(widget.mapStylePath!).then((string) { _mapStyle = string; }); } @@ -136,7 +135,7 @@ class MapPickerState extends State { @override Widget build(BuildContext context) { - if (widget.requiredGPS) { + if (widget.requiredGPS!) { _checkGeolocationPermission(); if (_currentPosition == null) _initCurrentLocation(); } @@ -148,8 +147,8 @@ class MapPickerState extends State { body: Builder( builder: (context) { if (_currentPosition == null && - widget.automaticallyAnimateToCurrentLocation && - widget.requiredGPS) { + widget.automaticallyAnimateToCurrentLocation! && + widget.requiredGPS!) { return const Center(child: CircularProgressIndicator()); } @@ -164,10 +163,11 @@ class MapPickerState extends State { child: Stack( children: [ GoogleMap( + zoomControlsEnabled: false, myLocationButtonEnabled: false, initialCameraPosition: CameraPosition( - target: widget.initialCenter, - zoom: widget.initialZoom, + target: widget.initialCenter!, + zoom: widget.initialZoom!, ), onMapCreated: (GoogleMapController controller) { mapController.complete(controller); @@ -226,7 +226,7 @@ class MapPickerState extends State { children: [ Flexible( flex: 20, - child: FutureLoadingBuilder>( + child: FutureLoadingBuilder>( future: getAddress(locationProvider.lastIdleLocation), mutable: true, loadingIndicator: Row( @@ -270,14 +270,14 @@ class MapPickerState extends State { ); } - Future> getAddress(LatLng location) async { + Future> getAddress(LatLng? location) async { try { final endpoint = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=${location?.latitude},${location?.longitude}' '&key=${widget.apiKey}&language=${widget.language}'; final response = jsonDecode((await http.get(Uri.parse(endpoint), - headers: await LocationUtils.getAppHeaders())) + headers: await (LocationUtils.getAppHeaders() as FutureOr?>))) .body); return { @@ -324,7 +324,7 @@ class MapPickerState extends State { var dialogOpen; Future _checkGeolocationPermission() async { - final geolocationStatus = await checkPermission(); + final geolocationStatus = await Geolocator.checkPermission(); d("geolocationStatus = $geolocationStatus"); if (geolocationStatus == LocationPermission.denied && dialogOpen == null) { @@ -361,7 +361,7 @@ class MapPickerState extends State { S.of(context)?.allow_access_to_the_location_services ?? 'Allow access to the location services.'), actions: [ - FlatButton( + TextButton( child: Text(S.of(context)?.ok ?? 'Ok'), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); @@ -395,11 +395,11 @@ class MapPickerState extends State { ?.allow_access_to_the_location_services_from_settings ?? 'Allow access to the location services for this App using the device settings.'), actions: [ - FlatButton( + TextButton( child: Text(S.of(context)?.ok ?? 'Ok'), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); - openAppSettings(); + Geolocator.openAppSettings(); dialogOpen = null; }, ), @@ -412,7 +412,7 @@ class MapPickerState extends State { // TODO: 9/12/2020 this is no longer needed, remove in the next release Future _checkGps() async { - if (!(await isLocationServiceEnabled())) { + if (!(await Geolocator.isLocationServiceEnabled())) { if (Theme.of(context).platform == TargetPlatform.android) { showDialog( context: context, @@ -426,7 +426,7 @@ class MapPickerState extends State { ?.please_make_sure_you_enable_gps_and_try_again ?? 'Please make sure you enable GPS and try again'), actions: [ - FlatButton( + TextButton( child: Text('Ok'), onPressed: () { final AndroidIntent intent = AndroidIntent( @@ -447,16 +447,16 @@ class MapPickerState extends State { class _MapFabs extends StatelessWidget { const _MapFabs({ - Key key, - @required this.myLocationButtonEnabled, - @required this.layersButtonEnabled, - @required this.onToggleMapTypePressed, - @required this.onMyLocationPressed, + Key? key, + required this.myLocationButtonEnabled, + required this.layersButtonEnabled, + required this.onToggleMapTypePressed, + required this.onMyLocationPressed, }) : assert(onToggleMapTypePressed != null), super(key: key); - final bool myLocationButtonEnabled; - final bool layersButtonEnabled; + final bool? myLocationButtonEnabled; + final bool? layersButtonEnabled; final VoidCallback onToggleMapTypePressed; final VoidCallback onMyLocationPressed; @@ -465,10 +465,10 @@ 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 + 35, right: 8), //24 child: Column( children: [ - if (layersButtonEnabled) + if (layersButtonEnabled!) FloatingActionButton( onPressed: onToggleMapTypePressed, materialTapTargetSize: MaterialTapTargetSize.padded, @@ -476,7 +476,7 @@ class _MapFabs extends StatelessWidget { child: const Icon(Icons.layers), heroTag: "layers", ), - if (myLocationButtonEnabled) + if (myLocationButtonEnabled!) FloatingActionButton( onPressed: onMyLocationPressed, materialTapTargetSize: MaterialTapTargetSize.padded, diff --git a/lib/src/model/auto_comp_iete_item.dart b/lib/src/model/auto_comp_iete_item.dart index 6d5d840f..7ce61b80 100644 --- a/lib/src/model/auto_comp_iete_item.dart +++ b/lib/src/model/auto_comp_iete_item.dart @@ -2,17 +2,17 @@ /// into this model. class AutoCompleteItem { /// The id of the place. This helps to fetch the lat,lng of the place. - String id; + String? id; /// The text (name of place) displayed in the autocomplete suggestions list. - String text; + String? text; /// Assistive index to begin highlight of matched part of the [text] with /// the original query - int offset; + int? offset; /// Length of matched part of the [text] - int length; + int? length; @override String toString() { diff --git a/lib/src/model/location_result.dart b/lib/src/model/location_result.dart index b8c3248f..b35f30e9 100644 --- a/lib/src/model/location_result.dart +++ b/lib/src/model/location_result.dart @@ -5,13 +5,13 @@ class LocationResult { /// The human readable name of the location. This is primarily the /// name of the road. But in cases where the place was selected from Nearby /// places list, we use the name provided on the list item. - String address; // or road + String? address; // or road /// Google Maps place ID - String placeId; + String? placeId; /// Latitude/Longitude of the selected location. - LatLng latLng; + LatLng? latLng; LocationResult({this.latLng, this.address, this.placeId}); diff --git a/lib/src/model/nearby_place.dart b/lib/src/model/nearby_place.dart index 6a18f216..11bfbf1e 100644 --- a/lib/src/model/nearby_place.dart +++ b/lib/src/model/nearby_place.dart @@ -4,14 +4,14 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; class NearbyPlace { /// The human-readable name of the location provided. This value is provided /// for [LocationResult.address] when the user selects this nearby place. - String name; + String? name; /// The icon identifying the kind of place provided. Eg. lodging, chapel, /// hospital, etc. - String icon; + String? icon; // Latitude/Longitude of the provided location. - LatLng latLng; + LatLng? latLng; @override String toString() { diff --git a/lib/src/providers/location_provider.dart b/lib/src/providers/location_provider.dart index df4b2aef..0ef16d33 100644 --- a/lib/src/providers/location_provider.dart +++ b/lib/src/providers/location_provider.dart @@ -6,11 +6,11 @@ class LocationProvider extends ChangeNotifier { static LocationProvider of(BuildContext context, {bool listen = true}) => Provider.of(context, listen: listen); - LatLng _lastIdleLocation; + LatLng? _lastIdleLocation; - LatLng get lastIdleLocation => _lastIdleLocation; + LatLng? get lastIdleLocation => _lastIdleLocation; - void setLastIdleLocation(LatLng lastIdleLocation) { + void setLastIdleLocation(LatLng? lastIdleLocation) { if (_lastIdleLocation != lastIdleLocation) { _lastIdleLocation = lastIdleLocation; notifyListeners(); diff --git a/lib/src/rich_suggestion.dart b/lib/src/rich_suggestion.dart index a7472641..bc4d33c0 100644 --- a/lib/src/rich_suggestion.dart +++ b/lib/src/rich_suggestion.dart @@ -33,7 +33,7 @@ class RichSuggestion extends StatelessWidget { final List result = []; String startText = - autoCompleteItem.text.substring(0, autoCompleteItem.offset); + autoCompleteItem.text!.substring(0, autoCompleteItem.offset); if (startText.isNotEmpty) { result.add( TextSpan( @@ -47,8 +47,8 @@ class RichSuggestion extends StatelessWidget { ); } - String boldText = autoCompleteItem.text.substring(autoCompleteItem.offset, - autoCompleteItem.offset + autoCompleteItem.length); + String boldText = autoCompleteItem.text!.substring(autoCompleteItem.offset!, + autoCompleteItem.offset! + autoCompleteItem.length!); result.add( TextSpan( @@ -63,8 +63,8 @@ class RichSuggestion extends StatelessWidget { String remainingText = this .autoCompleteItem - .text - .substring(autoCompleteItem.offset + autoCompleteItem.length); + .text! + .substring(autoCompleteItem.offset! + autoCompleteItem.length!); result.add( TextSpan( text: remainingText, diff --git a/lib/src/search_input.dart b/lib/src/search_input.dart index 9d7ba047..00041dea 100644 --- a/lib/src/search_input.dart +++ b/lib/src/search_input.dart @@ -7,16 +7,16 @@ import 'package:google_map_location_picker/generated/l10n.dart'; class SearchInput extends StatefulWidget { SearchInput( this.onSearchInput, { - Key key, + Key? key, this.searchInputKey, this.boxDecoration, this.hintText, }) : super(key: key); final ValueChanged onSearchInput; - final Key searchInputKey; - final BoxDecoration boxDecoration; - final String hintText; + final Key? searchInputKey; + final BoxDecoration? boxDecoration; + final String? hintText; @override State createState() => SearchInputState(); @@ -25,7 +25,7 @@ class SearchInput extends StatefulWidget { class SearchInputState extends State { TextEditingController editController = TextEditingController(); - Timer debouncer; + Timer? debouncer; bool hasSearchEntry = false; @@ -51,7 +51,7 @@ class SearchInputState extends State { } if (debouncer?.isActive ?? false) { - debouncer.cancel(); + debouncer!.cancel(); } debouncer = Timer(Duration(milliseconds: 500), () { diff --git a/lib/src/utils/loading_builder.dart b/lib/src/utils/loading_builder.dart index ec1d09ce..4ca7c5bb 100644 --- a/lib/src/utils/loading_builder.dart +++ b/lib/src/utils/loading_builder.dart @@ -10,10 +10,10 @@ typedef WidgetBuilder = Widget Function(BuildContext context, T snapshot); class FutureLoadingBuilder extends StatefulWidget { const FutureLoadingBuilder({ - Key key, - @required this.future, + Key? key, + required this.future, this.initialData, - @required this.builder, + required this.builder, this.mutable = false, this.loadingIndicator, }) : assert(builder != null), @@ -35,22 +35,22 @@ class FutureLoadingBuilder extends StatefulWidget { /// provided to the [builder] will become null, regardless of [initialData]. /// (The error itself will be available in [AsyncSnapshot.error], and /// [AsyncSnapshot.hasError] will be true.) - final T initialData; + final T? initialData; /// default is true /// /// set to false if the future will change. final bool mutable; - final Widget loadingIndicator; + final Widget? loadingIndicator; @override _FutureLoadingBuilderState createState() => _FutureLoadingBuilderState(); } -class _FutureLoadingBuilderState extends State> { - Future future; +class _FutureLoadingBuilderState extends State> { + Future? future; @override void initState() { @@ -60,7 +60,7 @@ class _FutureLoadingBuilderState extends State> { @override Widget build(BuildContext context) { - return FutureBuilder( + return FutureBuilder( future: widget.mutable ? widget.future : future, initialData: widget.initialData, builder: (BuildContext context, AsyncSnapshot snapshot) { diff --git a/lib/src/utils/location_utils.dart b/lib/src/utils/location_utils.dart index f5209277..68451f12 100644 --- a/lib/src/utils/location_utils.dart +++ b/lib/src/utils/location_utils.dart @@ -5,9 +5,9 @@ import 'package:flutter/services.dart'; class LocationUtils { static const _platform = const MethodChannel('google_map_location_picker'); - static Map _appHeaderCache = {}; + static Map _appHeaderCache = {}; - static Future> getAppHeaders() async { + static Future> getAppHeaders() async { if (_appHeaderCache.isEmpty) { PackageInfo packageInfo = await PackageInfo.fromPlatform(); @@ -16,7 +16,7 @@ class LocationUtils { "X-Ios-Bundle-Identifier": packageInfo.packageName, }; } else if (Platform.isAndroid) { - String sha1; + String? sha1; try { sha1 = await _platform.invokeMethod( 'getSigningCertSha1', packageInfo.packageName); diff --git a/pubspec.lock b/pubspec.lock index ae3630e2..5aa9fcc8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -90,21 +90,21 @@ packages: name: geolocator url: "https://pub.dartlang.org" source: hosted - version: "6.2.1" + version: "7.0.1" geolocator_platform_interface: dependency: transitive description: name: geolocator_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.9" + version: "2.0.0" geolocator_web: dependency: transitive description: name: geolocator_web url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "2.0.1" google_maps_flutter: dependency: "direct main" description: @@ -125,7 +125,7 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.0" + version: "0.13.1" http_parser: dependency: transitive description: @@ -202,7 +202,7 @@ packages: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.0" provider: dependency: "direct main" description: @@ -279,5 +279,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0-259.9.beta <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index e281a9a7..20996c23 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/humazed/google_map_location_picker # flutter pub pub publish --dry-run environment: - sdk: ">=2.2.2 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=2.0.0" dependencies: @@ -17,10 +17,10 @@ dependencies: intl: ^0.17.0 google_maps_flutter: ^2.0.1 - geolocator: ^6.1.14 + geolocator: ^7.0.1 android_intent: ^2.0.0 provider: ^5.0.0 - http: ^0.13.0 + http: ^0.13.1 stack_trace: ^1.10.0 package_info: ^2.0.0