amap_location_fluttify

This commit is contained in:
yangjie 2024-11-17 15:42:58 +08:00
commit 3ccab2c601
170 changed files with 40779 additions and 0 deletions

43
.gitignore vendored Normal file
View File

@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/
# Symbolication related
app.*.symbols
# Obfuscation related
app.*.map.json
# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

128
CHANGELOG.md Normal file
View File

@ -0,0 +1,128 @@
## 0.13.2
- fix: regecode空安全
- enhance: 添加监听定位的最小更新距离.
## 0.13.1
- enhance: 简化导出
## 0.13.0
- enhance: 提升依赖
## 0.12.0
- enhance: 更新底层依赖
- fix: android超时时间单位为毫秒
## 0.11.0
- enhance: [breaking change] timeout类型换为更直观的Duration类
- enhance: Location类增加speed字段 [#48]
## 0.10.0
- enhance: 更新底层依赖
## 0.9.0
- enhance: [breaking change] 使用原始值代替Future返回, 简化使用
- roll engine #939e12d7
## 0.8.11
- roll engine #481e45c1
## 0.8.10
- roll engine #dbad1c35 (#53)
- fix: 直接调用stopLocation时, 对client的空判断
## 0.8.9
- roll engine #0a5ab5f (#39)
## 0.8.8
- roll engine #b356b08
## 0.8.7
- roll engine #1053dca
## 0.8.6
- 提升依赖
## 0.8.5
- docs: apk下载链接修正
- docs: 去重重复的信息
## 0.8.4
- enhance: 加入打包的key
- docs: README加入apk下载二维码
- roll engine #107df19
## 0.8.3
- roll engine #4d92ce0. 主要解决type_op冲突的问题.
## 0.8.2
- roll engine #5c1b957
## 0.8.1
- feat: Location增加accuracy字段 (#38)
## 0.8.0
- enhance: 提升依赖
- roll engine #ea37ae9
## 0.7.0
- 提升依赖
## 0.6.0
- 提升依赖
## 0.5.1
- enhance: 增加bearing(设备移动方向属性), 此属性需要较长时间时间才能获取到数据, 建议在连续定位中使用.
- enhance: 提供仅在android端有效的DeviceSensor枚举
## 0.5.0
- enhance: 导出amap_core_fluttify
- roll engine #a918944
- 适配flutter 1.12.13
## 0.4.2
- fix: 连续定位空指针异常
## 0.4.1
- fix: 单次定位防止重复订阅
## 0.4.0
- enhance: [breaking change] 单次和连续定位单独实现并返回Future和Stream
## 0.3.2
- 解决依赖冲突
## 0.3.1
- 更新依赖
## 0.3.0
- 更新底层
## 0.2.7
- doc: 增加`await`的说明
- feat: 增加ios端requireAlwaysAuth的处理
## 0.2.6
- fix: dispose时置空_androidClient和_iosClient防止在页面级别的State中释放了client之后重新定位时client不为空而没有去重新创建原生client导致的原生client为空。
## 0.2.5
- enhancement: 经纬度统一使用LatLng
- enhancement: 调整设置回调的位置
## 0.2.4
- fix: 导出enums.dart; 删除utils.g.dart
## 0.2.3
- fix: 高德的key不应该放在library模块里
## 0.2.2
- fix: 释放原生对象时, 只释放当前插件创建的对象
## 0.2.1
- 更新README
- 更新引擎版本 38df15a
## 0.2.0
- setLocationListener -> startLocation
## 0.1.0
- 单次定位; 连续定位

13
LICENSE Normal file
View File

@ -0,0 +1,13 @@
Copyright 2020 yohom
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

56
README.md Normal file
View File

@ -0,0 +1,56 @@
![Logo](https://github.com/fluttify-project/fluttify-core-example/blob/develop/other/Logo-Landscape.png?raw=true)
# 高德 `定位`组件
[![pub package](https://img.shields.io/pub/v/amap_location_fluttify.svg)](https://pub.Flutter-io.cn/packages/amap_location_fluttify)
Dart接口基于[fluttify](https://github.com/yohom/fluttify-core-example)引擎生成. dartdoc[接口文档](https://pub.flutter-io.cn/documentation/amap_location_fluttify/latest/).
## DEMO 与 社区
安装:
```yaml
dependencies:
flutter:
sdk: flutter
amap_location_fluttify: ^x.x.x
```
导入:
```dart
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
```
使用:
```dart
/// !注意: 只要是返回Future的方法, 一律使用`await`修饰, 确保当前方法执行完成后再执行下一行, 在不能使用`await`修饰的环境下, 在`then`方法中执行下一步.
/// 初始化 iOS在init方法中设置, android需要去AndroidManifest.xml里去设置, 详见 https://lbs.amap.com/api/android-sdk/gettingstarted
await AmapCore.init('ios key');
// 单次定位
if (await requestPermission()) {
final location = await AmapLocation.fetchLocation();
setState(() => _location = location);
}
// 连续定位
if (await requestPermission()) {
AmapLocation.listenLocation()
.listen((location) => setState(() => _location = location));
}
```
## LICENSE
> Copyright 2020 yohom
>
> Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
>
> http://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing, software
> distributed under the License is distributed on an "AS IS" BASIS,
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> See the License for the specific language governing permissions and
> limitations under the License.

9
analysis_options.yaml Normal file
View File

@ -0,0 +1,9 @@
include: package:pedantic/analysis_options.yaml
linter:
rules:
camel_case_types: false
camel_case_extensions: false
omit_local_variable_types: false
prefer_single_quotes: false
unnecessary_this: false

70
android/build.gradle Normal file
View File

@ -0,0 +1,70 @@
group 'me.yohom.amap_location_fluttify'
version '1.0-SNAPSHOT'
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
apply plugin: 'com.android.library'
android {
if (project.android.hasProperty("namespace")) {
namespace = "me.yohom.amap_location_fluttify"
}
compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main.jniLibs.srcDir 'libs'
}
defaultConfig {
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
merge 'res/values/values.xml'
merge 'AndroidManifest.xml'
merge 'R.txt'
merge 'classes.jar'
merge 'proguard.txt'
}
buildTypes {
release {
consumerProguardFiles "proguard-rules.pro"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
compileOnly rootProject.findProject(":foundation_fluttify")
// flutter plugin dependency
// sdk dependency
api 'com.amap.api:location:6.1.0'
}

1
android/settings.gradle Normal file
View File

@ -0,0 +1 @@
rootProject.name = 'amap_location_fluttify'

View File

@ -0,0 +1,29 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.yohom.amap_location_fluttify">
<!--用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!--用于访问GPS定位-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!--用于获取运营商信息,用于支持提供运营商信息相关的接口-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--用于访问wifi网络信息wifi信息会用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!--用于获取wifi的获取权限wifi信息会用来进行网络定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!--用于访问网络,网络定位需要上网-->
<uses-permission android:name="android.permission.INTERNET"/>
<!--用于读取手机当前的状态-->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!--用于写入缓存数据到扩展存储卡-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--用于申请调用A-GPS模块-->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<!--用于申请获取蓝牙信息进行室内定位-->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application>
<service android:name="com.amap.api.location.APSService"/>
</application>
</manifest>

View File

@ -0,0 +1,154 @@
//////////////////////////////////////////////////////////
// GENERATED BY FLUTTIFY. DO NOT EDIT IT.
//////////////////////////////////////////////////////////
package me.yohom.amap_location_fluttify;
import android.os.Bundle;
import android.util.Log;
import android.app.Activity;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.StandardMethodCodec;
import io.flutter.plugin.platform.PlatformViewRegistry;
import me.yohom.amap_location_fluttify.sub_handler.*;
import me.yohom.amap_location_fluttify.sub_handler.custom.SubHandlerCustom;
import me.yohom.foundation_fluttify.core.FluttifyMessageCodec;
import static me.yohom.foundation_fluttify.FoundationFluttifyPluginKt.getEnableLog;
import static me.yohom.foundation_fluttify.FoundationFluttifyPluginKt.getHEAP;
@SuppressWarnings("ALL")
public class AmapLocationFluttifyPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
private static List<Map<String, Handler>> handlerMapList;
// v1 android embedding for compatible
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "me.yohom/amap_location_fluttify", new StandardMethodCodec(new FluttifyMessageCodec()));
AmapLocationFluttifyPlugin plugin = new AmapLocationFluttifyPlugin();
BinaryMessenger messenger = registrar.messenger();
PlatformViewRegistry platformViewRegistry = registrar.platformViewRegistry();
Activity activity = registrar.activity();
plugin.messenger = messenger;
plugin.platformViewRegistry = platformViewRegistry;
handlerMapList = new ArrayList<>();
handlerMapList.add(SubHandler0.getSubHandler(messenger));
handlerMapList.add(SubHandler1.getSubHandler(messenger));
handlerMapList.add(SubHandler2.getSubHandler(messenger));
handlerMapList.add(SubHandlerCustom.instance.getSubHandler(messenger, registrar.activity()));
channel.setMethodCallHandler(plugin);
// register platform view
}
private BinaryMessenger messenger;
private PlatformViewRegistry platformViewRegistry;
// v2 android embedding
@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
if (getEnableLog()) {
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onAttachedToEngine@" + binding);
}
final MethodChannel channel = new MethodChannel(binding.getBinaryMessenger(), "me.yohom/amap_location_fluttify", new StandardMethodCodec(new FluttifyMessageCodec()));
messenger = binding.getBinaryMessenger();
platformViewRegistry = binding.getPlatformViewRegistry();
handlerMapList = new ArrayList<>();
handlerMapList.add(SubHandler0.getSubHandler(messenger));
handlerMapList.add(SubHandler1.getSubHandler(messenger));
handlerMapList.add(SubHandler2.getSubHandler(messenger));
channel.setMethodCallHandler(this);
}
@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
if (getEnableLog()) {
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onDetachedFromEngine@" + binding);
}
}
@Override
public void onAttachedToActivity(ActivityPluginBinding binding) {
if (getEnableLog()) {
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onAttachedToActivity@" + binding);
}
Activity activity = binding.getActivity();
handlerMapList.add(SubHandlerCustom.instance.getSubHandler(messenger, activity));
// register platform view
}
@Override
public void onDetachedFromActivity() {
if (getEnableLog()) {
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onDetachedFromActivity");
}
}
@Override
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
if (getEnableLog()) {
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onReattachedToActivityForConfigChanges@" + binding);
}
}
@Override
public void onDetachedFromActivityForConfigChanges() {
if (getEnableLog()) {
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onDetachedFromActivityForConfigChanges");
}
}
@Override
public void onMethodCall(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result methodResult) {
Handler handler = null;
for (Map<String, Handler> handlerMap : handlerMapList) {
if (handlerMap.containsKey(methodCall.method)) {
handler = handlerMap.get(methodCall.method);
break;
}
}
if (handler != null) {
try {
handler.call(methodCall.arguments, methodResult);
} catch (Exception e) {
e.printStackTrace();
methodResult.error(e.getMessage(), null, null);
}
} else {
methodResult.notImplemented();
}
}
@FunctionalInterface
public static interface Handler {
void call(Object args, MethodChannel.Result methodResult) throws Exception;
}
}

View File

@ -0,0 +1,192 @@
//////////////////////////////////////////////////////////
// GENERATED BY FLUTTIFY. DO NOT EDIT IT.
//////////////////////////////////////////////////////////
package me.yohom.amap_location_fluttify.sub_handler.custom;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.util.Log;
import com.amap.api.fence.GeoFence;
import com.amap.api.fence.GeoFenceClient;
import com.amap.api.location.DPoint;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.StandardMethodCodec;
import me.yohom.amap_location_fluttify.AmapLocationFluttifyPlugin.Handler;
import me.yohom.foundation_fluttify.core.FluttifyMessageCodec;
import static me.yohom.foundation_fluttify.FoundationFluttifyPluginKt.getEnableLog;
import static me.yohom.foundation_fluttify.FoundationFluttifyPluginKt.getHEAP;
@SuppressWarnings("ALL")
public class SubHandlerCustom {
static final String GEOFENCE_BROADCAST_ACTION = "com.location.apis.geofencedemo.broadcast";
public static final SubHandlerCustom instance = new SubHandlerCustom();
private SubHandlerCustom() { }
public Map<String, Handler> getSubHandler(BinaryMessenger messenger, android.app.Activity activity) {
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
filter.addAction(GEOFENCE_BROADCAST_ACTION);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (GEOFENCE_BROADCAST_ACTION.equals(intent.getAction())) {
Bundle bundle = intent.getExtras();
Log.d(GEOFENCE_BROADCAST_ACTION, "收到围栏消息: " + bundle); //获取Bundle
//获取围栏行为
int status = bundle.getInt(GeoFence.BUNDLE_KEY_FENCESTATUS);
//获取自定义的围栏标识
String customId = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
//获取围栏ID:
String fenceId = bundle.getString(GeoFence.BUNDLE_KEY_FENCEID);
//获取当前有触发的围栏对象
GeoFence fence = bundle.getParcelable(GeoFence.BUNDLE_KEY_FENCE);
Map<String, Object> arguments = new HashMap<>();
arguments.put("status", status);
arguments.put("customId", customId);
arguments.put("fenceId", fenceId);
arguments.put("fence", fence);
new MethodChannel(messenger, "com.amap.api.fence.GeoFenceClient::addGeoFenceX::Callback", new StandardMethodCodec(new FluttifyMessageCodec()))
.invokeMethod("Callback::com.amap.api.fence.GeoFenceClient::addGeoFenceX", arguments);
}
}
};
activity.registerReceiver(receiver, filter);
return new HashMap<String, Handler>() {{
put("com.amap.api.fence.GeoFenceClient::addCircleGeoFenceX", (rawArgs, methodResult) -> {
// args
Map<String, Object> args = (Map<String, Object>) rawArgs;
GeoFenceClient __this__ = (GeoFenceClient) args.get("__this__");
int activeAction = (int) args.get("activeAction");
DPoint center = (DPoint) args.get("center");
Double radius = (Double) args.get("radius");
String customId = (String) args.get("customId");
// invoke native method
try {
__this__.setActivateAction(activeAction);
__this__.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
__this__.addGeoFence(center, radius.floatValue(), customId);
} catch (Throwable throwable) {
throwable.printStackTrace();
if (getEnableLog()) {
Log.d("Current HEAP: ", getHEAP().toString());
}
methodResult.error(throwable.getMessage(), null, null);
return;
}
methodResult.success("success");
});
put("com.amap.api.fence.GeoFenceClient::addPoiGeoFenceX", (rawArgs, methodResult) -> {
// args
Map<String, Object> args = (Map<String, Object>) rawArgs;
GeoFenceClient __this__ = (GeoFenceClient) args.get("__this__");
int activeAction = (int) args.get("activeAction");
String keyword = (String) args.get("keyword");
String poiType = (String) args.get("poiType");
String city = (String) args.get("city");
int size = (int) args.get("size");
String customId = (String) args.get("customId");
// invoke native method
try {
__this__.setActivateAction(activeAction);
__this__.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
__this__.addGeoFence(keyword, poiType, city, size, customId);
} catch (Throwable throwable) {
throwable.printStackTrace();
if (getEnableLog()) {
Log.d("Current HEAP: ", getHEAP().toString());
}
methodResult.error(throwable.getMessage(), null, null);
return;
}
methodResult.success("success");
});
put("com.amap.api.fence.GeoFenceClient::addPolygonGeoFenceX", (rawArgs, methodResult) -> {
// args
Map<String, Object> args = (Map<String, Object>) rawArgs;
GeoFenceClient __this__ = (GeoFenceClient) args.get("__this__");
int activeAction = (int) args.get("activeAction");
List<DPoint> polygon = (List<DPoint>) args.get("polygon");
String customId = (String) args.get("customId");
// invoke native method
try {
__this__.setActivateAction(activeAction);
__this__.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
__this__.addGeoFence(polygon, customId);
} catch (Throwable throwable) {
throwable.printStackTrace();
if (getEnableLog()) {
Log.d("Current HEAP: ", getHEAP().toString());
}
methodResult.error(throwable.getMessage(), null, null);
return;
}
methodResult.success("success");
});
put("com.amap.api.fence.GeoFenceClient::addDistrictGeoFenceX", (rawArgs, methodResult) -> {
// args
Map<String, Object> args = (Map<String, Object>) rawArgs;
GeoFenceClient __this__ = (GeoFenceClient) args.get("__this__");
int activeAction = (int) args.get("activeAction");
String keyword = (String) args.get("keyword");
String customId = (String) args.get("customId");
// invoke native method
try {
__this__.setActivateAction(activeAction);
__this__.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
__this__.addGeoFence(keyword, customId);
} catch (Throwable throwable) {
throwable.printStackTrace();
if (getEnableLog()) {
Log.d("Current HEAP: ", getHEAP().toString());
}
methodResult.error(throwable.getMessage(), null, null);
return;
}
methodResult.success("success");
});
put("com.amap.api.fence.GeoFenceClient::unregisterBroadcastReceiver", (rawArgs, methodResult) -> {
try {
activity.unregisterReceiver(receiver);
if (getEnableLog()) Log.d("GeoFenceClient", "取消注册围栏广播");
methodResult.success("success");
} catch (Exception e) {
e.printStackTrace();
methodResult.error(e.getMessage(), e.getMessage(), e.getMessage());
}
});
}};
}
}

43
example/.gitignore vendored Normal file
View File

@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/
# Symbolication related
app.*.symbols
# Obfuscation related
app.*.map.json
# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

0
example/README.md Normal file
View File

View File

@ -0,0 +1,29 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.
# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml
linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View File

@ -0,0 +1,2 @@
#Sat Nov 16 20:14:26 CST 2024
gradle.version=7.4

View File

@ -0,0 +1,66 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
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 flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "me.yohom.amap_location_fluttify_example"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias 'amap_location_test'
keyPassword 'amap_location_test'
storeFile file('../amap_location_test.jks')
storePassword 'amap_location_test'
}
}
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}

View File

View File

@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

View File

View File

@ -0,0 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

0
example/android/gradlew vendored Normal file
View File

0
example/android/gradlew.bat vendored Normal file
View File

View File

@ -0,0 +1,3 @@
sdk.dir=C:\\Users\\Administrator\\AppData\\Local\\Android\\sdk
flutter.sdk=D:\\futter\\flutter
flutter.buildMode=debug

View File

View File

View File

View File

0
example/ios/Podfile Normal file
View File

0
example/ios/Podfile.lock Normal file
View File

View File

View File

View File

View File

View File

192
example/lib/main.dart Normal file
View File

@ -0,0 +1,192 @@
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await AmapLocation.instance.updatePrivacyShow(true);
await AmapLocation.instance.updatePrivacyAgree(true);
await AmapLocation.instance.init(iosKey: 'f6422eadda731fb0d9ffb3260a5cf899');
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Location? _location;
String? _fenceStatus;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Plugin example app')),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () async {
if (await requestPermission()) {
final location =
await AmapLocation.instance.fetchLocation();
setState(() => _location = location);
}
},
child: Text('获取单次定位'),
),
ElevatedButton(
onPressed: () async {
if (await requestPermission()) {
await AmapLocation.instance.enableBackgroundLocation(
10,
BackgroundNotification(
contentTitle: 'contentTitle',
channelId: 'channelId',
contentText: 'contentText',
channelName: 'channelName',
),
);
AmapLocation.instance
.listenLocation()
.listen((event) => setState(() => _location = event));
}
},
child: Text('获取连续定位'),
),
ElevatedButton(
onPressed: () async {
if (await requestPermission()) {
await AmapLocation.instance.stopLocation();
setState(() => _location = null);
}
},
child: Text('停止定位'),
),
ElevatedButton(
onPressed: () async {
if (await requestPermission()) {
AmapLocation.instance
.addCircleGeoFence(
center: LatLng(29, 119),
radius: 1000,
customId: 'testid',
)
.listen((event) {
setState(() {
_fenceStatus =
'状态: ${event.status}, 围栏id: ${event.fenceId}, 自定义id: ${event.customId}';
});
});
}
},
child: Text('添加圆形围栏'),
),
ElevatedButton(
onPressed: () async {
if (await requestPermission()) {
AmapLocation.instance.addPolygonGeoFence(
pointList: <LatLng>[
LatLng(29.255201, 119.353437),
LatLng(28.974455, 119.508619),
LatLng(29.172496, 119.560804),
LatLng(29.306707, 119.422101),
],
customId: 'testid',
).listen((event) {
setState(() {
_fenceStatus =
'状态: ${event.status}, 围栏id: ${event.fenceId}, 自定义id: ${event.customId}';
});
});
}
},
child: Text('添加多边形围栏'),
),
ElevatedButton(
onPressed: () async {
if (await requestPermission()) {
AmapLocation.instance
.addPoiGeoFence(
keyword: '肯德基',
customId: 'testid',
city: '兰溪',
aroundRadius: 10000,
)
.listen((event) {
setState(() {
_fenceStatus =
'状态: ${event.status}, 围栏id: ${event.fenceId}, 自定义id: ${event.customId}';
});
});
}
},
child: Text('添加poi围栏'),
),
ElevatedButton(
onPressed: () async {
if (await requestPermission()) {
AmapLocation.instance
.addDistrictGeoFence(keyword: '兰溪')
.listen((event) {
setState(() {
_fenceStatus =
'状态: ${event.status}, 围栏id: ${event.fenceId}, 自定义id: ${event.customId}';
});
});
}
},
child: Text('添加行政区划围栏'),
),
ElevatedButton(
onPressed: () {
AmapLocation.instance.dispose();
},
child: Text('释放资源'),
),
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
if (_location != null)
Center(
child: Text(
_location.toString(),
textAlign: TextAlign.center,
),
),
if (_fenceStatus != null)
Center(
child: Text(
_fenceStatus.toString(),
textAlign: TextAlign.center,
),
),
],
),
),
),
],
),
),
),
);
}
}
Future<bool> requestPermission() async {
final permissions = await Permission.locationWhenInUse.request();
if (permissions.isGranted) {
return true;
} else {
debugPrint('需要定位权限!');
return false;
}
}

241
example/pubspec.lock Normal file
View File

@ -0,0 +1,241 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
amap_core_fluttify:
dependency: transitive
description:
path: "D:\\FlutterProjects\\amap_core_fluttify"
relative: false
source: path
version: "0.17.0"
amap_location_fluttify:
dependency: "direct dev"
description:
path: ".."
relative: true
source: path
version: "0.22.0"
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
clock:
dependency: transitive
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
source: hosted
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.18.0"
core_location_fluttify:
dependency: transitive
description:
path: "D:\\FlutterProjects\\core_location_fluttify"
relative: false
source: path
version: "0.7.1"
fake_async:
dependency: transitive
description:
name: fake_async
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
foundation_fluttify:
dependency: transitive
description:
path: "D:\\FlutterProjects\\foundation_fluttify"
relative: false
source: path
version: "0.13.0+1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.15.0"
path:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.9.0"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
sha256: e968207ce71d8b40d719aeca3e5a8b684494ecbe9a577dd67cc701216bcccf0a
url: "https://pub.dev"
source: hosted
version: "7.2.0"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: "6760eb5ef34589224771010805bea6054ad28453906936f843a8cc4d3a55c4a4"
url: "https://pub.dev"
source: hosted
version: "3.12.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.2"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.5"
sdks:
dart: ">=3.5.3 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"

26
example/pubspec.yaml Normal file
View File

@ -0,0 +1,26 @@
name: amap_location_fluttify_example
description: Demonstrates how to use the amap_location_fluttify plugin.
publish_to: 'none'
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
permission_handler: ^7.1.0
#dependency_overrides:
# foundation_fluttify:
# path: /Users/yohom/Github/Me/All/fluttify/fluttify_infra/foundation_fluttify
# core_location_fluttify:
# path: /Users/yohom/Github/Me/All/fluttify/fluttify_infra/core_location_fluttify
dev_dependencies:
flutter_test:
sdk: flutter
amap_location_fluttify:
path: ../
flutter:
uses-material-design: true

View File

View File

@ -0,0 +1,15 @@
//////////////////////////////////////////////////////////
// GENERATED BY FLUTTIFY. DO NOT EDIT IT.
//////////////////////////////////////////////////////////
#import <Flutter/Flutter.h>
typedef void (^Handler)(NSObject <FlutterPluginRegistrar> *, id, FlutterResult);
@interface AmapLocationFluttifyPlugin : NSObject<FlutterPlugin>
- (instancetype) initWithFlutterPluginRegistrar: (NSObject <FlutterPluginRegistrar> *) registrar;
@property(nonatomic) NSObject<FlutterPluginRegistrar>* registrar;
@end

View File

@ -0,0 +1,61 @@
//////////////////////////////////////////////////////////
// GENERATED BY FLUTTIFY. DO NOT EDIT IT.
//////////////////////////////////////////////////////////
#import "AmapLocationFluttifyPlugin.h"
#import <objc/runtime.h>
#import "SubHandler/SubHandler0.h"
#import "SubHandler/SubHandler1.h"
#import "SubHandler/Custom/SubHandlerCustom.h"
#import "FluttifyMessageCodec.h"
#import <AMapLocationKit/AMapLocationKit.h>
// Dart, MethodChannel,
extern NSMutableDictionary<NSString*, NSObject*>* STACK;
// Dart
extern NSMutableDictionary<NSString*, NSObject*>* HEAP;
//
extern BOOL enableLog;
@implementation AmapLocationFluttifyPlugin {
NSMutableDictionary<NSString*, Handler>* _handlerMap;
}
- (instancetype) initWithFlutterPluginRegistrar: (NSObject <FlutterPluginRegistrar> *) registrar {
self = [super init];
if (self) {
_registrar = registrar;
//
_handlerMap = @{}.mutableCopy;
[_handlerMap addEntriesFromDictionary: [self getSubHandler0]];
[_handlerMap addEntriesFromDictionary: [self getSubHandler1]];
[_handlerMap addEntriesFromDictionary: [self getSubHandlerCustom]];
}
return self;
}
+ (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:@"me.yohom/amap_location_fluttify"
binaryMessenger:[registrar messenger]
codec:[FlutterStandardMethodCodec codecWithReaderWriter:[[FluttifyReaderWriter alloc] init]]];
[registrar addMethodCallDelegate:[[AmapLocationFluttifyPlugin alloc] initWithFlutterPluginRegistrar:registrar]
channel:channel];
// View
}
// Method Handlers
- (void)handleMethodCall:(FlutterMethodCall *)methodCall result:(FlutterResult)methodResult {
if (_handlerMap[methodCall.method] != nil) {
_handlerMap[methodCall.method](_registrar, [methodCall arguments], methodResult);
} else {
methodResult(FlutterMethodNotImplemented);
}
}
@end

View File

@ -0,0 +1,21 @@
//////////////////////////////////////////////////////////
// GENERATED BY FLUTTIFY. DO NOT EDIT IT.
//////////////////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <AMapLocationKit/AMapLocationKit.h>
@protocol FlutterPluginRegistrar;
NS_ASSUME_NONNULL_BEGIN
@interface AMapGeoFenceManagerDelegate_Anonymous : NSObject<AMapGeoFenceManagerDelegate>
- (instancetype) initWithFlutterPluginRegistrar: (NSObject <FlutterPluginRegistrar> *) registrar;
@property(nonatomic) NSObject<FlutterPluginRegistrar>* registrar;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,106 @@
//////////////////////////////////////////////////////////
// GENERATED BY FLUTTIFY. DO NOT EDIT IT.
//////////////////////////////////////////////////////////
#import "AMapGeoFenceManagerDelegate_Anonymous.h"
#import <Flutter/Flutter.h>
#import "FluttifyMessageCodec.h"
#import <objc/runtime.h>
// Dart, MethodChannel,
extern NSMutableDictionary<NSString*, NSObject*>* STACK;
// Dart
extern NSMutableDictionary<NSString*, NSObject*>* HEAP;
//
extern BOOL enableLog;
@implementation AMapGeoFenceManagerDelegate_Anonymous
- (instancetype) initWithFlutterPluginRegistrar: (NSObject <FlutterPluginRegistrar> *) registrar {
self = [super init];
if (self) {
_registrar = registrar;
}
return self;
}
- (void)amapGeoFenceManager : (AMapGeoFenceManager*)manager doRequireLocationAuth: (CLLocationManager*)locationManager
{
FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:[NSString stringWithFormat:@"AMapGeoFenceManagerDelegate::Callback@%@:%@", NSStringFromClass([self class]), @(self.hash)]
binaryMessenger:[_registrar messenger]
codec:[FlutterStandardMethodCodec codecWithReaderWriter:[[FluttifyReaderWriter alloc] init]]];
// print log
if (enableLog) {
NSLog(@"AMapGeoFenceManagerDelegate::amapGeoFenceManager_doRequireLocationAuth");
}
// convert to jsonable arg
// ref callback arg
AMapGeoFenceManager* argmanager = manager;
// ref callback arg
CLLocationManager* arglocationManager = locationManager;
dispatch_async(dispatch_get_main_queue(), ^{
[channel invokeMethod:@"amapGeoFenceManager_doRequireLocationAuth" arguments:@{@"manager": argmanager == nil ? [NSNull null] : argmanager, @"locationManager": arglocationManager == nil ? [NSNull null] : arglocationManager}];
});
}
- (void)amapGeoFenceManager : (AMapGeoFenceManager*)manager didAddRegionForMonitoringFinished: (NSArray<AMapGeoFenceRegion*>*)regions customID: (NSString*)customID error: (NSError*)error
{
FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:[NSString stringWithFormat:@"AMapGeoFenceManagerDelegate::Callback@%@:%@", NSStringFromClass([self class]), @(self.hash)]
binaryMessenger:[_registrar messenger]
codec:[FlutterStandardMethodCodec codecWithReaderWriter:[[FluttifyReaderWriter alloc] init]]];
// print log
if (enableLog) {
NSLog(@"AMapGeoFenceManagerDelegate::amapGeoFenceManager_didAddRegionForMonitoringFinished_customID_error");
}
// convert to jsonable arg
// ref callback arg
AMapGeoFenceManager* argmanager = manager;
// ref callback arg
NSArray<AMapGeoFenceRegion*>* argregions = regions;
// ref callback arg
NSString* argcustomID = customID;
// ref callback arg
NSError* argerror = error;
dispatch_async(dispatch_get_main_queue(), ^{
[channel invokeMethod:@"amapGeoFenceManager_didAddRegionForMonitoringFinished_customID_error" arguments:@{@"manager": argmanager == nil ? [NSNull null] : argmanager, @"regions": argregions == nil ? [NSNull null] : argregions, @"customID": argcustomID == nil ? [NSNull null] : argcustomID, @"error": argerror == nil ? [NSNull null] : argerror}];
});
}
- (void)amapGeoFenceManager : (AMapGeoFenceManager*)manager didGeoFencesStatusChangedForRegion: (AMapGeoFenceRegion*)region customID: (NSString*)customID error: (NSError*)error
{
FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:[NSString stringWithFormat:@"AMapGeoFenceManagerDelegate::Callback@%@:%@", NSStringFromClass([self class]), @(self.hash)]
binaryMessenger:[_registrar messenger]
codec:[FlutterStandardMethodCodec codecWithReaderWriter:[[FluttifyReaderWriter alloc] init]]];
// print log
if (enableLog) {
NSLog(@"AMapGeoFenceManagerDelegate::amapGeoFenceManager_didGeoFencesStatusChangedForRegion_customID_error");
}
// convert to jsonable arg
// ref callback arg
AMapGeoFenceManager* argmanager = manager;
// ref callback arg
AMapGeoFenceRegion* argregion = region;
// ref callback arg
NSString* argcustomID = customID;
// ref callback arg
NSError* argerror = error;
dispatch_async(dispatch_get_main_queue(), ^{
[channel invokeMethod:@"amapGeoFenceManager_didGeoFencesStatusChangedForRegion_customID_error" arguments:@{@"manager": argmanager == nil ? [NSNull null] : argmanager, @"region": argregion == nil ? [NSNull null] : argregion, @"customID": argcustomID == nil ? [NSNull null] : argcustomID, @"error": argerror == nil ? [NSNull null] : argerror}];
});
}
@end

Some files were not shown because too many files have changed in this diff Show More