From 06154c382cf7ad64d70ec4413478030fbb26d0f6 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Tue, 1 Jun 2021 16:30:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=A6=96=E9=A1=B5=E5=A4=A9?= =?UTF-8?q?=E6=B0=94=E5=AE=9A=E4=BD=8D=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/home/home_page.dart | 38 +++++++++++---- pubspec.lock | 88 ++++++++++++++++++++++++++++++++++- pubspec.yaml | 4 +- 3 files changed, 116 insertions(+), 14 deletions(-) diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 62ce8d7..ef78425 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -22,6 +22,7 @@ import 'package:extended_image/extended_image.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart' hide Response; import 'package:permission_handler/permission_handler.dart'; +import 'package:power_logger/power_logger.dart'; import 'package:sharesdk_plugin/sharesdk_plugin.dart'; import 'package:recook/base/base_store_state.dart'; @@ -117,6 +118,9 @@ class _HomePageState extends BaseStoreState // 天气数据 HomeWeatherModel _homeWeatherModel; WeatherCityModel _weatherCityModel; + +//定位 + AMapFlutterLocation _amapFlutterLocation; //高度 double screenWidth = 0; double weatherHeight = 0; @@ -154,13 +158,26 @@ class _HomePageState extends BaseStoreState @override void initState() { super.initState(); + //已在native配置 + // AMapFlutterLocation.setApiKey( + // '7225bca14fe7493f9f469315a933f99c', 'e8a8057cfedcdcadcf4e8f2c7f8de982'); + _amapFlutterLocation = AMapFlutterLocation(); + requestPermission().then((value) { if (value) { - AMapFlutterLocation().setLocationOption(AMapLocationOption()); - AMapFlutterLocation().startLocation(); - AMapFlutterLocation().onLocationChanged().listen((event) { - _weatherLocation = event; - }); + //监听要在设置参数之前 否则无法获取定位 + _amapFlutterLocation.onLocationChanged().listen( + (event) { + _weatherLocation = event; + _getWeather(); + }, + ); + + _amapFlutterLocation + .setLocationOption(AMapLocationOption(onceLocation: true)); + _amapFlutterLocation.startLocation(); + } else { + ReToast.err(text: '未获取到定位权限,请先在设置中打开定位权限'); } }); @@ -241,7 +258,6 @@ class _HomePageState extends BaseStoreState // 获取当前页面需要刷新的数据 _updateSource() { - _getWeather(); _getActiviteList(); _getBannerList(); _getPromotionList(); @@ -265,8 +281,8 @@ class _HomePageState extends BaseStoreState @override void dispose() { _tabController.dispose(); - AMapFlutterLocation().stopLocation(); - AMapFlutterLocation().destroy(); + _amapFlutterLocation?.stopLocation(); + _amapFlutterLocation?.destroy(); WidgetsBinding.instance.removeObserver(this); super.dispose(); } @@ -1369,8 +1385,9 @@ class _HomePageState extends BaseStoreState _getWeather() async { // if (_weatherLocation==null) + //cityid、city和ip参数3选一提交,如果不传,默认返回当前ip城市天气,cityid优先级最高。 String url = - "https://tianqiapi.com/api?version=v61&appid=81622428&appsecret=AxKzYWq3"; + "https://v0.yiketianqi.com/api?version=v61&appid=81622428&appsecret=AxKzYWq3"; if (_weatherCityModel != null && !TextUtils.isEmpty(_weatherCityModel.id)) { url = "$url&cityid=${_weatherCityModel.id}"; } else if (_weatherCityModel != null && @@ -1387,7 +1404,8 @@ class _HomePageState extends BaseStoreState if (res == null) { return; } - Map map = json.decode(res.toString()); + LoggerData.addData(res); + Map map = json.decode(res.data.toString()); _homeWeatherModel = HomeWeatherModel.fromJson(map); UserManager.instance.homeWeatherModel = _homeWeatherModel; if (mounted) setState(() {}); diff --git a/pubspec.lock b/pubspec.lock index 55976f2..7b10596 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -14,7 +14,7 @@ packages: name: amap_flutter_location url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1" + version: "2.0.0" analyzer: dependency: transitive description: @@ -295,6 +295,48 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.1" + device_info_plus: + dependency: transitive + description: + name: device_info_plus + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + device_info_plus_linux: + dependency: transitive + description: + name: device_info_plus_linux + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + device_info_plus_macos: + dependency: transitive + description: + name: device_info_plus_macos + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + device_info_plus_platform_interface: + dependency: transitive + description: + name: device_info_plus_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.2" + device_info_plus_web: + dependency: transitive + description: + name: device_info_plus_web + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + device_info_plus_windows: + dependency: transitive + description: + name: device_info_plus_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" dio: dependency: "direct main" description: @@ -818,6 +860,48 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" + package_info_plus: + dependency: transitive + description: + name: package_info_plus + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + package_info_plus_linux: + dependency: transitive + description: + name: package_info_plus_linux + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.2" + package_info_plus_macos: + dependency: transitive + description: + name: package_info_plus_macos + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.1" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + package_info_plus_web: + dependency: transitive + description: + name: package_info_plus_web + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" + package_info_plus_windows: + dependency: transitive + description: + name: package_info_plus_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" package_signature: dependency: "direct main" description: @@ -966,7 +1050,7 @@ packages: name: power_logger url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.1-nullsafety.1" + version: "1.2.1" process: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 0967b67..098b485 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: timeline_tile: 0.1.2 # 高德定位 # amap_location_fluttify: ^0.18.0 - amap_flutter_location: ^1.0.1 + amap_flutter_location: ^2.0.0 # icons flutter_icons: 1.1.0 # 拼音 @@ -231,7 +231,7 @@ dependencies: animations: device_info: ^2.0.0 clipboard_listener: ^1.0.0 - power_logger: ^1.0.1-nullsafety.1 + power_logger: ^1.2.1 bot_toast: ^3.0.5 get: ^3.26.0