diff --git a/lib/union/location_map_page.dart b/lib/union/location_map_page.dart index 819eda41..311fb466 100644 --- a/lib/union/location_map_page.dart +++ b/lib/union/location_map_page.dart @@ -138,7 +138,7 @@ class _LocationMap extends State with WidgetsBindingObserver { } void permissionSettings() async { - if (await Permission.location.isGranted) { + if (_isShowLocalTips && await Permission.location.isGranted) { _isShowLocalTips = false; getLocation(); } @@ -305,7 +305,7 @@ class _LocationMap extends State with WidgetsBindingObserver { GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - if (myCity == null) { + if (myLatLng == null) { // onOpenBaiduMap(); SmartDialog.showToast( "您定位服务未开启,请前往系统设置中开启定位服务", diff --git a/lib/union/union_page.dart b/lib/union/union_page.dart index 0a1de5a6..c8158739 100644 --- a/lib/union/union_page.dart +++ b/lib/union/union_page.dart @@ -20,6 +20,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; +import 'package:visibility_detector/visibility_detector.dart'; import '../view_widget/location_tips.dart'; import '../view_widget/no_data_view.dart'; @@ -47,6 +48,7 @@ class UnionPageState extends State String areaName; List _allKey = []; bool _isShowLocalTips = false; + double visiblePercentage; jumpIndex(jpIndex) { tabController.index = jpIndex; @@ -65,6 +67,7 @@ class UnionPageState extends State void didChangeAppLifecycleState(AppLifecycleState state) { if (state == AppLifecycleState.resumed) { // 处理应用程序切换回前台的逻辑 + if(visiblePercentage == 1) permissionSettings(); } else if (state == AppLifecycleState.paused) { // 处理应用程序切换到后台的逻辑 @@ -203,7 +206,14 @@ class UnionPageState extends State @override Widget build(BuildContext context) { super.build(context); - return GestureDetector( + return VisibilityDetector( + key: Key('my-widget-key'), + onVisibilityChanged: (visibilityInfo) { + visiblePercentage = visibilityInfo.visibleFraction; + if(visiblePercentage == 1) + permissionSettings(); + }, + child: GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { FocusScope.of(context).requestFocus(FocusNode()); @@ -337,7 +347,7 @@ class UnionPageState extends State ) ], ), - ); + )); } Widget buildSearchItem() { diff --git a/pubspec.lock b/pubspec.lock index 2da24db9..be43806d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -781,7 +781,7 @@ packages: name: tobias url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.2" + version: "2.4.1" tpns_flutter_plugin: dependency: "direct main" description: @@ -903,6 +903,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.15" + visibility_detector: + dependency: "direct main" + description: + name: visibility_detector + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.3.3" wakelock: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index a5850713..d654b60b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: sdk: flutter fluwx: 3.9.0+2 - tobias: ^2.4.1 + tobias: 2.4.1 gradient_widgets: ^0.6.0 @@ -58,6 +58,8 @@ dependencies: gbk2utf8: ^1.0.1 + visibility_detector: ^0.3.3 + event_bus: ^2.0.0 intl: ^0.17.0 shared_preferences: ^2.0.6