迁移amap到官方插件

hmxc
小赖 4 years ago
parent cc6fefb4a8
commit bd8a2afa07

@ -100,4 +100,6 @@ flutter {
dependencies {
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
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">
<service android:name="com.amap.api.location.APSService"></service>
<meta-data android:name="com.amap.api.v2.apikey"
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">

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

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
@ -32,7 +31,7 @@ class _SplashPageState extends State<SplashPage> {
await HiveStore.init();
//AMap
await AmapLocation.instance.init(iosKey: 'ios key');
// await AmapLocation.instance.init(iosKey: 'ios key');
await Permission.locationWhenInUse.request();
}
@ -42,7 +41,7 @@ class _SplashPageState extends State<SplashPage> {
final userProvider = Provider.of<UserProvider>(context, listen: false);
final appProvider = Provider.of<AppProvider>(context, listen: false);
appProvider.initApplications();
appProvider.getWeather();
appProvider.startLocation();
//app init delay 2 second
await Future.delayed(Duration(seconds: 2));
if (HiveStore.appBox.get('login') ?? false) {
@ -54,7 +53,7 @@ class _SplashPageState extends State<SplashPage> {
void initState() {
super.initState();
PowerLogger.start(context, debug: DeveloperUtil.dev);
_initOp().then((value) => Get.offAll(()=>TabNavigator()));
_initOp().then((value) => Get.offAll(() => TabNavigator()));
}
@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:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:dio/dio.dart';
import 'package:power_logger/power_logger.dart';
@ -132,12 +131,34 @@ class AppProvider extends ChangeNotifier {
}
}
Location _location;
Location get location => _location;
Map<String, Object> _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 {
_location = await AmapLocation.instance.fetchLocation();
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);
_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"
source: hosted
version: "14.0.0"
amap_core_fluttify:
dependency: transitive
description:
name: amap_core_fluttify
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.0"
amap_location_fluttify:
amap_flutter_base:
dependency: "direct main"
description:
name: amap_location_fluttify
name: amap_flutter_base
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.18.0"
amap_map_fluttify:
version: "1.0.2"
amap_flutter_location:
dependency: "direct main"
description:
name: amap_map_fluttify
name: amap_flutter_location
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.29.0"
amap_search_fluttify:
dependency: transitive
version: "1.0.1"
amap_flutter_map:
dependency: "direct main"
description:
name: amap_search_fluttify
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.14.0"
path: "."
ref: nullsafety
resolved-ref: "5c50cf60d2157cc2779a171ca65c327d571389a7"
url: "http://159.75.73.143:8080/third_packages/amap_flutter_map"
source: git
version: "2.0.2-nullsafety"
analyzer:
dependency: transitive
description:
@ -169,13 +164,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
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:
dependency: transitive
description:
@ -385,13 +373,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
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:
dependency: "direct main"
description:
@ -631,14 +612,14 @@ packages:
name: permission_handler
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.1.0+2"
version: "6.1.1"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.2"
version: "3.1.1"
petitparser:
dependency: transitive
description:
@ -666,7 +647,7 @@ packages:
name: plugin_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.3"
version: "2.0.0"
power_logger:
dependency: "direct main"
description:
@ -849,6 +830,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
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:
dependency: transitive
description:
@ -897,35 +885,42 @@ packages:
name: url_launcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.5.2"
version: "6.0.2"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.1+4"
version: "2.0.0"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.1+9"
version: "2.0.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.9"
version: "2.0.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.flutter-io.cn"
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:
dependency: transitive
description:

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

Loading…
Cancel
Save