Skip to content

Commit

Permalink
Add V2 embedding PR changes from humazed#179
Browse files Browse the repository at this point in the history
  • Loading branch information
vahurh committed Dec 2, 2021
1 parent 84a716c commit 669c985
Show file tree
Hide file tree
Showing 40 changed files with 296 additions and 344 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# google_map_location_picker [![Pub](https://img.shields.io/pub/v/google_map_location_picker.svg)](https://pub.dev/packages/google_map_location_picker)

Update by MG :
- Compatibility with Geolocator
- Use of Google map geolocator Api json field address_component

Location picker using the official [google_maps_flutter](https://pub.dev/packages/google_maps_flutter).

I made This plugin because google deprecated [Place Picker](https://developers.google.com/places/android-sdk/placepicker).
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'com.humazed.google_map_location_picker'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.5.31'
ext.kotlin_version = '1.5.0'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "com.android.tools.build:gradle:7.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -25,13 +25,13 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
minSdkVersion 23
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down
Binary file modified android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package com.humazed.google_map_location_picker

import android.app.Activity
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import androidx.annotation.UiThread
import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import android.content.pm.PackageManager
import java.math.BigInteger
import java.security.MessageDigest
import android.content.pm.PackageInfo

class GoogleMapLocationPickerPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private lateinit var channel : MethodChannel
private var activityBinding: ActivityPluginBinding? = null

class GoogleMapLocationPickerPlugin(act: Activity) : MethodCallHandler {
var activity: Activity = act

companion object {
@JvmStatic
fun registerWith(registrar: Registrar) {
val channel = MethodChannel(registrar.messenger(), "google_map_location_picker")
channel.setMethodCallHandler(GoogleMapLocationPickerPlugin(registrar.activity()))
}
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "google_map_location_picker")
channel.setMethodCallHandler(this)
}

@UiThread
override fun onMethodCall(call: MethodCall, result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if(activityBinding == null) {
result.notImplemented()
return
}
if (call.method == "getSigningCertSha1") {
try {
val info: PackageInfo = activity.packageManager.getPackageInfo(call.arguments<String>(), PackageManager.GET_SIGNATURES)
val info: PackageInfo = activityBinding!!.activity.packageManager.getPackageInfo(call.arguments<String>(), PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
val md: MessageDigest = MessageDigest.getInstance("SHA1")
md.update(signature.toByteArray())
Expand All @@ -49,4 +48,22 @@ class GoogleMapLocationPickerPlugin(act: Activity) : MethodCallHandler {
result.notImplemented()
}
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activityBinding = binding
}

override fun onDetachedFromActivity() {
activityBinding = null
}

override fun onDetachedFromActivityForConfigChanges() {
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
}
}
15 changes: 10 additions & 5 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id("com.android.application")
id("kotlin-android")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -21,12 +27,11 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 29

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -39,8 +44,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.humazed.google_map_location_picker_example"
minSdkVersion 16
targetSdkVersion 28
minSdkVersion 23
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
11 changes: 7 additions & 4 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
</intent-filter>
</activity>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- <meta-data-->
<!-- android:name="com.google.android.gms.version"-->
<!-- android:value="1" />-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/GOOGLE_MAPS_API_KEY" />
android:value="${MAPS_API_KEY}" />
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.humazed.google_map_location_picker_example

import android.os.Bundle

import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
/* override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
}
}*/
}
18 changes: 18 additions & 0 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item>
</style>
</resources>
5 changes: 3 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.5.0'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "com.android.tools.build:gradle:7.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0"
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
5 changes: 3 additions & 2 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/admin/dev/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/admin/dev/google_map_location_picker/example"
export "FLUTTER_ROOT=/Users/blb/Development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/blb/Development/google_map_location_picker/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
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"
Expand Down
32 changes: 16 additions & 16 deletions example/lib/generated/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(context, S);
static S? of(BuildContext context) => Localizations.of<S>(context, S);

@override
TextDirection get textDirection => TextDirection.ltr;
Expand All @@ -33,7 +33,7 @@ class $en extends S {
const $en();
}

class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S?> {
const GeneratedLocalizationsDelegate();

List<Locale> get supportedLocales {
Expand All @@ -44,8 +44,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
}

LocaleListResolutionCallback listResolution(
{Locale fallback, bool withCountry = true}) {
return (List<Locale> locales, Iterable<Locale> supported) {
{Locale? fallback, bool withCountry = true}) {
return (List<Locale>? locales, Iterable<Locale> supported) {
if (locales == null || locales.isEmpty) {
return fallback ?? supported.first;
} else {
Expand All @@ -55,29 +55,29 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
}

LocaleResolutionCallback resolution(
{Locale fallback, bool withCountry = true}) {
return (Locale locale, Iterable<Locale> supported) {
{Locale? fallback, bool withCountry = true}) {
return (Locale? locale, Iterable<Locale> supported) {
return _resolve(locale, fallback, supported, withCountry);
};
}

@override
Future<S> load(Locale locale) {
final String lang = getLang(locale);
Future<S?> load(Locale locale) {
final String? lang = getLang(locale);
if (lang != null) {
switch (lang) {
case "ar":
S.current = const $ar();
return SynchronousFuture<S>(S.current);
return SynchronousFuture<S?>(S.current);
case "en":
S.current = const $en();
return SynchronousFuture<S>(S.current);
return SynchronousFuture<S?>(S.current);
default:
// NO-OP.
}
}
S.current = const S();
return SynchronousFuture<S>(S.current);
return SynchronousFuture<S?>(S.current);
}

@override
Expand All @@ -89,7 +89,7 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
///
/// Internal method to resolve a locale from a list of locales.
///
Locale _resolve(Locale locale, Locale fallback, Iterable<Locale> supported,
Locale _resolve(Locale? locale, Locale? fallback, Iterable<Locale> supported,
bool withCountry) {
if (locale == null || !_isSupported(locale, withCountry)) {
return fallback ?? supported.first;
Expand Down Expand Up @@ -125,7 +125,7 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
// 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;
}
}
Expand All @@ -134,8 +134,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
}
}

String getLang(Locale l) => l == null
String? getLang(Locale l) => l == null
? null
: l.countryCode != null && l.countryCode.isEmpty
: l.countryCode != null && l.countryCode!.isEmpty
? l.languageCode
: l.toString();
8 changes: 4 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 'package:google_map_location_picker_example/api_key.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

import 'generated/i18n.dart';
Expand All @@ -16,7 +16,7 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
LocationResult _pickedLocation;
LocationResult? _pickedLocation;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -50,9 +50,9 @@ class _MyAppState extends State<MyApp> {
children: <Widget>[
RaisedButton(
onPressed: () async {
LocationResult result = await showLocationPicker(
LocationResult? result = await showLocationPicker(
context,
'apiKey',
googleMapsApiKeyAndroid,
initialCenter: LatLng(31.1975844, 29.9598339),
// automaticallyAnimateToCurrentLocation: true,
// mapStylePath: 'assets/mapStyle.json',
Expand Down
Loading

0 comments on commit 669c985

Please sign in to comment.