迁移amap到官方插件

hmxc
小赖 4 years ago
parent cc6fefb4a8
commit bd8a2afa07

@ -100,4 +100,6 @@ flutter {
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.amap.api:3dmap:latest.integration'
implementation 'com.amap.api:location:latest.integration'
} }

@ -5,6 +5,7 @@
additional functionality it is fine to subclass or reimplement additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. --> FlutterApplication and put your custom class here. -->
<application android:name="io.flutter.app.FlutterApplication" android:label="小蜜蜂智慧社区" android:icon="@mipmap/ic_launcher" android:networkSecurityConfig="@xml/network_security_config"> <application android:name="io.flutter.app.FlutterApplication" android:label="小蜜蜂智慧社区" android:icon="@mipmap/ic_launcher" android:networkSecurityConfig="@xml/network_security_config">
<service android:name="com.amap.api.location.APSService"></service>
<meta-data android:name="com.amap.api.v2.apikey" <meta-data android:name="com.amap.api.v2.apikey"
android:value="ee697f99e8381b7efde08b9976052bd0"/> android:value="ee697f99e8381b7efde08b9976052bd0"/>
<activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">

@ -48,7 +48,7 @@ class _AnimateAppBarState extends State<AnimateAppBar> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
appProvider?.location?.city ?? '', appProvider?.location['city'] ?? '',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 24.sp, fontSize: 24.sp,

@ -1,11 +1,14 @@
import 'package:akuCommunity/provider/app_provider.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:amap_flutter_location/amap_flutter_location.dart';
import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:flutter_icons/flutter_icons.dart'; import 'package:flutter_icons/flutter_icons.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
@ -27,34 +30,27 @@ class AlarmPage extends StatefulWidget {
} }
class _AlarmPageState extends State<AlarmPage> { class _AlarmPageState extends State<AlarmPage> {
final _option = MyLocationOption( AMapController _mapController;
show: true,
myLocationType: MyLocationType.Locate,
);
Future<void> _makephonenum(String url) async { Future<void> _makephonenum(String url) async {
(await canLaunch(url)) ? await launch(url) : throw 'Could not launch $url'; (await canLaunch(url)) ? await launch(url) : throw 'Could not launch $url';
} }
AmapController _amapController;
Location _location;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
AmapLocation.instance.fetchLocation().then((location) {
_location = location;
setState(() {});
});
PermissionUtil.getLocationPermission(); PermissionUtil.getLocationPermission();
} }
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
_mapController?.disponse();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final appProvider = Provider.of<AppProvider>(context);
return BeeScaffold( return BeeScaffold(
title: '一键报警', title: '一键报警',
actions: [ actions: [
@ -66,14 +62,26 @@ class _AlarmPageState extends State<AlarmPage> {
body: Stack( body: Stack(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
children: [ children: [
AmapView( AMapWidget(
onMapCreated: (controller) async { onMapCreated: (controller) {
_amapController = controller; final appProvider =
await _amapController.showMyLocation(_option); Provider.of<AppProvider>(context, listen: false);
LatLng _target = LatLng(
appProvider.location['latitude'],
appProvider.location['longitude'],
);
_mapController = controller;
_mapController.moveCamera(
CameraUpdate.newCameraPosition(
CameraPosition(target: _target, zoom: 18),
),
);
}, },
mapType: MapType.Standard, myLocationStyleOptions: MyLocationStyleOptions(
showZoomControl: false, true,
zoomLevel: 16, circleFillColor: Theme.of(context).primaryColor.withOpacity(0.2),
circleStrokeColor: Theme.of(context).primaryColor,
),
), ),
Column( Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
@ -114,17 +122,17 @@ class _AlarmPageState extends State<AlarmPage> {
size: 29.sp, size: 29.sp,
), ),
Container( Container(
margin: EdgeInsets.only(left: 5.w), margin: EdgeInsets.symmetric(horizontal: 5.w),
child: Text( child: Text(
(_location == null) (appProvider.location == null)
? '加载中……' ? '加载中……'
: _location.aoiName, : appProvider.location['address'],
style: TextStyle( style: TextStyle(
color: Color(0xff666666), color: Color(0xff666666),
fontSize: 28.sp, fontSize: 28.sp,
), ),
), ),
), ).expand(),
], ],
), ),
), ),
@ -154,12 +162,7 @@ class _AlarmPageState extends State<AlarmPage> {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(66.w)), borderRadius: BorderRadius.circular(66.w)),
color: Color(0xFFFFFFFF), color: Color(0xFFFFFFFF),
onPressed: () { onPressed: () {},
_amapController?.setCenterCoordinate(_location.latLng);
Future.delayed(Duration(milliseconds: 500), () {
if (mounted) _amapController.setZoomLevel(16);
});
},
child: Icon( child: Icon(
Icons.location_searching, Icons.location_searching,
size: 44.w, size: 44.w,

@ -1,6 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
@ -32,7 +31,7 @@ class _SplashPageState extends State<SplashPage> {
await HiveStore.init(); await HiveStore.init();
//AMap //AMap
await AmapLocation.instance.init(iosKey: 'ios key'); // await AmapLocation.instance.init(iosKey: 'ios key');
await Permission.locationWhenInUse.request(); await Permission.locationWhenInUse.request();
} }
@ -42,7 +41,7 @@ class _SplashPageState extends State<SplashPage> {
final userProvider = Provider.of<UserProvider>(context, listen: false); final userProvider = Provider.of<UserProvider>(context, listen: false);
final appProvider = Provider.of<AppProvider>(context, listen: false); final appProvider = Provider.of<AppProvider>(context, listen: false);
appProvider.initApplications(); appProvider.initApplications();
appProvider.getWeather(); appProvider.startLocation();
//app init delay 2 second //app init delay 2 second
await Future.delayed(Duration(seconds: 2)); await Future.delayed(Duration(seconds: 2));
if (HiveStore.appBox.get('login') ?? false) { if (HiveStore.appBox.get('login') ?? false) {
@ -54,7 +53,7 @@ class _SplashPageState extends State<SplashPage> {
void initState() { void initState() {
super.initState(); super.initState();
PowerLogger.start(context, debug: DeveloperUtil.dev); PowerLogger.start(context, debug: DeveloperUtil.dev);
_initOp().then((value) => Get.offAll(()=>TabNavigator())); _initOp().then((value) => Get.offAll(() => TabNavigator()));
} }
@override @override

@ -1,8 +1,7 @@
import 'dart:io'; import 'package:amap_flutter_location/amap_flutter_location.dart';
import 'package:amap_flutter_location/amap_location_option.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
@ -132,12 +131,34 @@ class AppProvider extends ChangeNotifier {
} }
} }
Location _location; Map<String, Object> _location;
Location get location => _location; Map<String, Object> get location => _location;
AMapFlutterLocation _aMapFlutterLocation;
startLocation() {
_aMapFlutterLocation = AMapFlutterLocation();
_aMapFlutterLocation.onLocationChanged().listen((event) {
_location = event;
if (_location != null) {
getWeather();
stopLocation();
}
});
_aMapFlutterLocation
.setLocationOption(AMapLocationOption(onceLocation: true));
_aMapFlutterLocation.startLocation();
}
stopLocation() {
_aMapFlutterLocation.stopLocation();
_aMapFlutterLocation.destroy();
}
// Location _location;
// Location get location => _location;
getWeather() async { getWeather() async {
_location = await AmapLocation.instance.fetchLocation();
Response response = await Dio().get( Response response = await Dio().get(
'https://api.caiyunapp.com/v2.5/Rl2lmppO9q15q8W6/${_location.latLng.longitude},${_location.latLng.latitude}/realtime.json', 'https://api.caiyunapp.com/v2.5/Rl2lmppO9q15q8W6/${_location['longitude']},${_location['latitude']}/realtime.json',
); );
LoggerData.addData(response); LoggerData.addData(response);
_weatherModel = RealTimeWeatherModel.fromJson(response.data); _weatherModel = RealTimeWeatherModel.fromJson(response.data);

@ -1,20 +0,0 @@
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:dio/dio.dart';
import 'package:akuCommunity/model/common/real_time_weather_model.dart';
class WeatherUtil {
static Location _location;
static String baseURL = 'https://api.caiyunapp.com/v2.5/Rl2lmppO9q15q8W6';
static Future<RealTimeWeatherModel> getWeather() async {
_location = await AmapLocation.instance.fetchLocation();
Response response = await Dio().get(
'$baseURL/${_location.latLng.latitude},${_location.latLng.longitude}/realtime.json');
if (response.data == null)
return null;
else
return RealTimeWeatherModel.fromJson(response.data);
}
}

@ -8,34 +8,29 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "14.0.0" version: "14.0.0"
amap_core_fluttify: amap_flutter_base:
dependency: transitive
description:
name: amap_core_fluttify
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.0"
amap_location_fluttify:
dependency: "direct main" dependency: "direct main"
description: description:
name: amap_location_fluttify name: amap_flutter_base
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.18.0" version: "1.0.2"
amap_map_fluttify: amap_flutter_location:
dependency: "direct main" dependency: "direct main"
description: description:
name: amap_map_fluttify name: amap_flutter_location
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.29.0" version: "1.0.1"
amap_search_fluttify: amap_flutter_map:
dependency: transitive dependency: "direct main"
description: description:
name: amap_search_fluttify path: "."
url: "https://pub.flutter-io.cn" ref: nullsafety
source: hosted resolved-ref: "5c50cf60d2157cc2779a171ca65c327d571389a7"
version: "0.14.0" url: "http://159.75.73.143:8080/third_packages/amap_flutter_map"
source: git
version: "2.0.2-nullsafety"
analyzer: analyzer:
dependency: transitive dependency: transitive
description: description:
@ -169,13 +164,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "3.0.0" version: "3.0.0"
core_location_fluttify:
dependency: transitive
description:
name: core_location_fluttify
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.1"
crypto: crypto:
dependency: transitive dependency: transitive
description: description:
@ -385,13 +373,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "3.3.0" version: "3.3.0"
foundation_fluttify:
dependency: transitive
description:
name: foundation_fluttify
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.10+1"
get: get:
dependency: "direct main" dependency: "direct main"
description: description:
@ -631,14 +612,14 @@ packages:
name: permission_handler name: permission_handler
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "5.1.0+2" version: "6.1.1"
permission_handler_platform_interface: permission_handler_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: permission_handler_platform_interface name: permission_handler_platform_interface
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.2" version: "3.1.1"
petitparser: petitparser:
dependency: transitive dependency: transitive
description: description:
@ -666,7 +647,7 @@ packages:
name: plugin_platform_interface name: plugin_platform_interface
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.3" version: "2.0.0"
power_logger: power_logger:
dependency: "direct main" dependency: "direct main"
description: description:
@ -849,6 +830,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
stream_transform:
dependency: transitive
description:
name: stream_transform
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
@ -897,35 +885,42 @@ packages:
name: url_launcher name: url_launcher
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "5.5.2" version: "6.0.2"
url_launcher_linux: url_launcher_linux:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_linux name: url_launcher_linux
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.0.1+4" version: "2.0.0"
url_launcher_macos: url_launcher_macos:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_macos name: url_launcher_macos
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.0.1+9" version: "2.0.0"
url_launcher_platform_interface: url_launcher_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_platform_interface name: url_launcher_platform_interface
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.9" version: "2.0.2"
url_launcher_web: url_launcher_web:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_web name: url_launcher_web
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.1.5+3" version: "2.0.0"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
uuid: uuid:
dependency: transitive dependency: transitive
description: description:

@ -13,7 +13,7 @@ dependencies:
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter
# 权限组件 # 权限组件
permission_handler: ^5.0.1+1 permission_handler: ^6.1.1
# 版本信息 # 版本信息
package_info: ^2.0.0 package_info: ^2.0.0
#上拉加载 #上拉加载
@ -23,7 +23,7 @@ dependencies:
flutter_screenutil: ^5.0.0-nullsafety.11 flutter_screenutil: ^5.0.0-nullsafety.11
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
# 打电话等各种功能 # 打电话等各种功能
url_launcher: 5.5.2 url_launcher: ^6.0.2
# 工具类 # 工具类
flustars: ^2.0.1 flustars: ^2.0.1
# icons # icons
@ -51,13 +51,11 @@ dependencies:
flutter_datetime_picker: ^1.4.0 flutter_datetime_picker: ^1.4.0
#随机二维码 #随机二维码
qr_flutter: ^4.0.0 qr_flutter: ^4.0.0
#高德地图
amap_map_fluttify: 0.29.0
amap_location_fluttify: 0.18.0
#用户存储路径 #用户存储路径
path_provider: ^2.0.1 path_provider: ^2.0.1
fluwx: ^3.3.0 fluwx: ^3.3.0
get: ^4.0.0-nullsafety.2 get: ^4.0.0-nullsafety.2
velocity_x: ^2.6.0 velocity_x: ^2.6.0
@ -78,6 +76,12 @@ dependencies:
url: http://159.75.73.143:8080/third_packages/jpush_flutter url: http://159.75.73.143:8080/third_packages/jpush_flutter
badges: ^2.0.0-nullsafety.1 badges: ^2.0.0-nullsafety.1
amap_flutter_map:
git:
url: http://159.75.73.143:8080/third_packages/amap_flutter_map
ref: nullsafety
amap_flutter_location: ^1.0.1
amap_flutter_base: ^1.0.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save