Browse Source

前后台切换监听混淆解决;

dev
huixiang_app 1 year ago
parent
commit
2b2dcd215b
  1. 4
      lib/union/location_map_page.dart
  2. 14
      lib/union/union_page.dart
  3. 9
      pubspec.lock
  4. 4
      pubspec.yaml

4
lib/union/location_map_page.dart

@ -138,7 +138,7 @@ class _LocationMap extends State<LocationMap> with WidgetsBindingObserver {
} }
void permissionSettings() async { void permissionSettings() async {
if (await Permission.location.isGranted) { if (_isShowLocalTips && await Permission.location.isGranted) {
_isShowLocalTips = false; _isShowLocalTips = false;
getLocation(); getLocation();
} }
@ -305,7 +305,7 @@ class _LocationMap extends State<LocationMap> with WidgetsBindingObserver {
GestureDetector( GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
if (myCity == null) { if (myLatLng == null) {
// onOpenBaiduMap(); // onOpenBaiduMap();
SmartDialog.showToast( SmartDialog.showToast(
"您定位服务未开启,请前往系统设置中开启定位服务", "您定位服务未开启,请前往系统设置中开启定位服务",

14
lib/union/union_page.dart

@ -20,6 +20,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.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/location_tips.dart';
import '../view_widget/no_data_view.dart'; import '../view_widget/no_data_view.dart';
@ -47,6 +48,7 @@ class UnionPageState extends State<UnionPage>
String areaName; String areaName;
List<GlobalKey> _allKey = []; List<GlobalKey> _allKey = [];
bool _isShowLocalTips = false; bool _isShowLocalTips = false;
double visiblePercentage;
jumpIndex(jpIndex) { jumpIndex(jpIndex) {
tabController.index = jpIndex; tabController.index = jpIndex;
@ -65,6 +67,7 @@ class UnionPageState extends State<UnionPage>
void didChangeAppLifecycleState(AppLifecycleState state) { void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) { if (state == AppLifecycleState.resumed) {
// //
if(visiblePercentage == 1)
permissionSettings(); permissionSettings();
} else if (state == AppLifecycleState.paused) { } else if (state == AppLifecycleState.paused) {
// //
@ -203,7 +206,14 @@ class UnionPageState extends State<UnionPage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(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, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); FocusScope.of(context).requestFocus(FocusNode());
@ -337,7 +347,7 @@ class UnionPageState extends State<UnionPage>
) )
], ],
), ),
); ));
} }
Widget buildSearchItem() { Widget buildSearchItem() {

9
pubspec.lock

@ -781,7 +781,7 @@ packages:
name: tobias name: tobias
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.4.2" version: "2.4.1"
tpns_flutter_plugin: tpns_flutter_plugin:
dependency: "direct main" dependency: "direct main"
description: description:
@ -903,6 +903,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.15" 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: wakelock:
dependency: transitive dependency: transitive
description: description:

4
pubspec.yaml

@ -15,7 +15,7 @@ dependencies:
sdk: flutter sdk: flutter
fluwx: 3.9.0+2 fluwx: 3.9.0+2
tobias: ^2.4.1 tobias: 2.4.1
gradient_widgets: ^0.6.0 gradient_widgets: ^0.6.0
@ -58,6 +58,8 @@ dependencies:
gbk2utf8: ^1.0.1 gbk2utf8: ^1.0.1
visibility_detector: ^0.3.3
event_bus: ^2.0.0 event_bus: ^2.0.0
intl: ^0.17.0 intl: ^0.17.0
shared_preferences: ^2.0.6 shared_preferences: ^2.0.6

Loading…
Cancel
Save