当我试图多一次打电话给服务时,轻松地进行地理涂料的问题

发布于 2025-01-18 07:48:50 字数 13018 浏览 3 评论 0原文

我正在尝试使用Easy Geipencing软件包检查特定地理审慎区的用户是否在调用easygeefencing.startgeofenceservice()和easygeofencing.getgeofencewing.getgeofenceStream()具有新位置(尖端的位置,尖端,pointedlongity,radiusmeter),服务不起作用,不起作用和工作。控制台打印“解析值===> false”如果有人知道我如何解决此问题,请帮助我,从一周起就被卡住了。

这是我

import 'dart:async';
import 'package:easy_geofencing/easy_geofencing.dart';

import 'package:geolocator/geolocator.dart';
import 'package:easy_geofencing/enums/geofence_status.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/domain/models/shop_model.dart';
import 'package:flutter_application_1/presentation/resources/assets_manager.dart';
import 'package:flutter_application_1/presentation/resources/color_manager.dart';
import 'package:flutter_application_1/presentation/resources/values_manager.dart';
import 'package:flutter_application_1/presentation/sidebars/cardWidget.dart';
import 'package:flutter_application_1/presentation/sidebars/profileSideBar.dart';
import 'package:flutter_application_1/services/shop_services.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';

class ShopsDownBar extends StatefulWidget with ChangeNotifier {
  ShopsDownBar({Key? key}) : super(key: key);

  @override
  State<ShopsDownBar> createState() => _ShopsDownBarState();
}

class _ShopsDownBarState extends State<ShopsDownBar>
    with SingleTickerProviderStateMixin<ShopsDownBar> {
  StreamSubscription<GeofenceStatus>? geofenceStatusStream;
  StreamSubscription<EasyGeofencing>? easyGeofencingStream;
  Geolocator geolocator = Geolocator();
  String geofenceStatus = '';
  bool isReady = false;
  int raduis = 25;
  double? longitude;
  double? latitude;
  Position? position;
  late StreamController<bool> isOpenStreamController;
  late Stream<bool> isOpenNStream;
  late StreamSink<bool> isOpenNSink;
  late AnimationController _animationControler;
  List<Shops> shops = [];

  getCurrentPosition() async {
    position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.high);
    print("LOCATION => ${position?.toJson()}");
    isReady = (position != null) ? true : false;
  }

  setLocation() async {
    await getCurrentPosition();
    print("POSITION => ${position!.toJson()}");
  }

  final _animationDuration = const Duration(milliseconds: 500);
  setShops() {
    ShopServices().fetchShops().then((value) {
      setState(() {
        if (value != null) {
          for (int i = 0; i < value.length; i++) {
            shops.add(Shops(
              type: value[i].type,
              shopStatus: value[i].shopStatus,
              rewards: value[i].rewards,
              id: value[i].id,
              shopName: value[i].shopName,
              shopAddress: value[i].shopAddress,
              markerShop: value[i].markerShop,
              createdAt: value[i].createdAt,
              updatedAt: value[i].updatedAt,
            ));
          }
        }
      });
    });
  }

  void onIconPressed() {
    final animationStatus = _animationControler.status;
    final isAnimationDone = animationStatus == AnimationStatus.completed;
    if (isAnimationDone) {
      isOpenNSink.add(false);
      _animationControler.reverse();
    } else if (Provider.of<ProfileSideBar>(context, listen: false).isOpen ==
        false) {
      isOpenNSink.add(true);
      _animationControler.forward();
    }
  }

  @override
  void initState() {
    setShops();
    getCurrentPosition();
    if (isReady) {
      print('jawna behi');
      setState(() {
        setLocation();
      });
    }

    _animationControler =
        AnimationController(vsync: this, duration: _animationDuration);
    isOpenStreamController = PublishSubject<bool>();

    isOpenNStream = isOpenStreamController.stream;
    isOpenNSink = isOpenStreamController.sink;
    super.initState();
  }

  @override
  void dispose() {
    _animationControler.dispose();
    isOpenStreamController.close();
    isOpenNSink.close();
    EasyGeofencing.stopGeofenceService();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    var height = size.height;
    var width = size.width;

    return StreamBuilder<bool>(
        initialData: false,
        stream: isOpenNStream,
        builder: (context, isOpenAsync) {
          return AnimatedPositioned(
            duration: _animationDuration,
            top: isOpenAsync.data == false ? height * 0.91 : height * 0.24,
            bottom: AppSize.s1_5,
            right: AppSize.s1_5,
            left: AppSize.s1_5,
            child: Column(
              children: [
                Align(
                  child: GestureDetector(
                    onTap: () {
                      onIconPressed();
                    },
                    child: Container(
                      //  alignment: Alignment.cen,
                      padding: const EdgeInsets.only(
                        left: AppMargin.m60,
                        right: AppMargin.m60,
                        top: AppMargin.m8,
                      ),
                      child: Icon(
                        isOpenAsync.data == true
                            ? Icons.close
                            : Icons.wallet_giftcard,
                        size: AppSize.s28,
                        color: ColorManager.primary,
                      ),
                      decoration: const BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(AppSize.s40),
                            topRight: Radius.circular(AppSize.s40)),
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: Container(
                      margin: const EdgeInsets.only(
                          left: AppMargin.m16, right: AppMargin.m16),
                      height: height / 1.4,
                      width: width,
                      decoration: BoxDecoration(
                        color: ColorManager.white,
                        borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(AppSize.s28),
                            topRight: Radius.circular(AppSize.s28)),
                      ),
                      child: shops.isNotEmpty
                          ? ListView.builder(
                              itemBuilder: (context, index) {
                                return Padding(
                                  padding: const EdgeInsets.only(
                                      bottom: AppPadding.p8,
                                      top: AppPadding.p18),
                                  child: Giftcart(
                                    ontap: () {
                                      // print("starting geoFencing Service");
                                      EasyGeofencing.startGeofenceService(
                                          pointedLatitude: shops[index]
                                              .markerShop
                                              .locations
                                              .latitude
                                              .toString(),
                                          pointedLongitude: shops[index]
                                              .markerShop
                                              .locations
                                              .longitude
                                              .toString(),
                                          radiusMeter: raduis.toString(),
                                          eventPeriodInSeconds: 5);

                                      geofenceStatusStream ??=
                                          EasyGeofencing.getGeofenceStream()!
                                              .listen((GeofenceStatus? status) {
                                        print(status.toString());
                                        setState(() {
                                          geofenceStatus = status.toString();
                                        });
                                        if (status.toString() ==
                                            'GeofenceStatus.enter') {
                                          print("entered");
                                         
                                        } else {
                                          print("not entered");
                                        }
                                      });
                                    },
                                    shopName: shops[index].shopName,
                                    details: shops[index].shopAddress,
                                    imagePath: ImageAssets.logo1,
                                  ),
                                );
                              },
                              itemCount: shops.length)
                          : Padding(
                              padding: const EdgeInsets.fromLTRB(
                                  AppPadding.p100,
                                  AppPadding.p100,
                                  AppPadding.p100,
                                  AppPadding.p200),
                              child: CircularProgressIndicator(
                                valueColor: AlwaysStoppedAnimation<Color>(
                                    ColorManager.primary),
                              ),
                            )),
                ),
              ],
            ),
          );
        });
  }
}

import 'package:flutter/material.dart';
import 'package:flutter_application_1/presentation/resources/color_manager.dart';
import 'package:flutter_application_1/presentation/resources/values_manager.dart';
//import 'package:flutter_application_1/presentation/resources/font_manager.dart';

class Giftcart extends StatelessWidget {
  final String shopName;
  final String details;
  final String imagePath;

  final void Function() ontap;

  const Giftcart({
    Key? key,
    required this.ontap,
    required this.shopName,
    required this.details,
    required this.imagePath,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    var height = size.height;
    var width = size.width;
    return Center(
      child: Container(
        decoration: BoxDecoration(
          color: ColorManager.white,
          borderRadius: BorderRadius.circular(10),
          boxShadow: [
            BoxShadow(
              color: ColorManager.grey,
              offset: const Offset(0, 0),
              blurRadius: 10,
            ),
          ],
        ),
        height: height * 0.1,
        width: width * 0.8,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
                height: height * 0.15,
                width: width * 0.15,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(40),
                ),
                child: Image.asset(imagePath)),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  height: height * 0.02,
                ),
                Text(
                  shopName,
                  style: Theme.of(context).textTheme.subtitle2,
                  textAlign: TextAlign.end,
                ),
                SizedBox(
                  height: height * 0.01,
                ),
                Text(
                  details,
                  style: Theme.of(context).textTheme.bodyText1,
                  textAlign: TextAlign.start,
                ),
              ],
            ),
            Padding(
              padding: const EdgeInsets.only(right: 10.0),
              child: SizedBox(
                height: height * 0.12,
                width: width * 0.12,
                child: FloatingActionButton(
                    backgroundColor: ColorManager.primary,
                    onPressed: ontap,
                    child: Icon(
                      Icons.card_giftcard,
                      size: AppSize.s18,
                      color: ColorManager.white,
                    )),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

的 左侧的按钮是用于检查地理杂质

”

这是软件包doc

i am trying to check if the user in specific geofencing zone using the Easy geofencing package but every time i call the EasyGeofencing.startGeofenceService() and EasyGeofencing.getGeofenceStream() with new position ( pointedLatitude, pointedLongitude, radiusMeter) the service do not work and the console print "Parse value===> false" if any one know how i solve this problem please help me, i am stuck since a week.

this is my code

import 'dart:async';
import 'package:easy_geofencing/easy_geofencing.dart';

import 'package:geolocator/geolocator.dart';
import 'package:easy_geofencing/enums/geofence_status.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/domain/models/shop_model.dart';
import 'package:flutter_application_1/presentation/resources/assets_manager.dart';
import 'package:flutter_application_1/presentation/resources/color_manager.dart';
import 'package:flutter_application_1/presentation/resources/values_manager.dart';
import 'package:flutter_application_1/presentation/sidebars/cardWidget.dart';
import 'package:flutter_application_1/presentation/sidebars/profileSideBar.dart';
import 'package:flutter_application_1/services/shop_services.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';

class ShopsDownBar extends StatefulWidget with ChangeNotifier {
  ShopsDownBar({Key? key}) : super(key: key);

  @override
  State<ShopsDownBar> createState() => _ShopsDownBarState();
}

class _ShopsDownBarState extends State<ShopsDownBar>
    with SingleTickerProviderStateMixin<ShopsDownBar> {
  StreamSubscription<GeofenceStatus>? geofenceStatusStream;
  StreamSubscription<EasyGeofencing>? easyGeofencingStream;
  Geolocator geolocator = Geolocator();
  String geofenceStatus = '';
  bool isReady = false;
  int raduis = 25;
  double? longitude;
  double? latitude;
  Position? position;
  late StreamController<bool> isOpenStreamController;
  late Stream<bool> isOpenNStream;
  late StreamSink<bool> isOpenNSink;
  late AnimationController _animationControler;
  List<Shops> shops = [];

  getCurrentPosition() async {
    position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.high);
    print("LOCATION => ${position?.toJson()}");
    isReady = (position != null) ? true : false;
  }

  setLocation() async {
    await getCurrentPosition();
    print("POSITION => ${position!.toJson()}");
  }

  final _animationDuration = const Duration(milliseconds: 500);
  setShops() {
    ShopServices().fetchShops().then((value) {
      setState(() {
        if (value != null) {
          for (int i = 0; i < value.length; i++) {
            shops.add(Shops(
              type: value[i].type,
              shopStatus: value[i].shopStatus,
              rewards: value[i].rewards,
              id: value[i].id,
              shopName: value[i].shopName,
              shopAddress: value[i].shopAddress,
              markerShop: value[i].markerShop,
              createdAt: value[i].createdAt,
              updatedAt: value[i].updatedAt,
            ));
          }
        }
      });
    });
  }

  void onIconPressed() {
    final animationStatus = _animationControler.status;
    final isAnimationDone = animationStatus == AnimationStatus.completed;
    if (isAnimationDone) {
      isOpenNSink.add(false);
      _animationControler.reverse();
    } else if (Provider.of<ProfileSideBar>(context, listen: false).isOpen ==
        false) {
      isOpenNSink.add(true);
      _animationControler.forward();
    }
  }

  @override
  void initState() {
    setShops();
    getCurrentPosition();
    if (isReady) {
      print('jawna behi');
      setState(() {
        setLocation();
      });
    }

    _animationControler =
        AnimationController(vsync: this, duration: _animationDuration);
    isOpenStreamController = PublishSubject<bool>();

    isOpenNStream = isOpenStreamController.stream;
    isOpenNSink = isOpenStreamController.sink;
    super.initState();
  }

  @override
  void dispose() {
    _animationControler.dispose();
    isOpenStreamController.close();
    isOpenNSink.close();
    EasyGeofencing.stopGeofenceService();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    var height = size.height;
    var width = size.width;

    return StreamBuilder<bool>(
        initialData: false,
        stream: isOpenNStream,
        builder: (context, isOpenAsync) {
          return AnimatedPositioned(
            duration: _animationDuration,
            top: isOpenAsync.data == false ? height * 0.91 : height * 0.24,
            bottom: AppSize.s1_5,
            right: AppSize.s1_5,
            left: AppSize.s1_5,
            child: Column(
              children: [
                Align(
                  child: GestureDetector(
                    onTap: () {
                      onIconPressed();
                    },
                    child: Container(
                      //  alignment: Alignment.cen,
                      padding: const EdgeInsets.only(
                        left: AppMargin.m60,
                        right: AppMargin.m60,
                        top: AppMargin.m8,
                      ),
                      child: Icon(
                        isOpenAsync.data == true
                            ? Icons.close
                            : Icons.wallet_giftcard,
                        size: AppSize.s28,
                        color: ColorManager.primary,
                      ),
                      decoration: const BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(AppSize.s40),
                            topRight: Radius.circular(AppSize.s40)),
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: Container(
                      margin: const EdgeInsets.only(
                          left: AppMargin.m16, right: AppMargin.m16),
                      height: height / 1.4,
                      width: width,
                      decoration: BoxDecoration(
                        color: ColorManager.white,
                        borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(AppSize.s28),
                            topRight: Radius.circular(AppSize.s28)),
                      ),
                      child: shops.isNotEmpty
                          ? ListView.builder(
                              itemBuilder: (context, index) {
                                return Padding(
                                  padding: const EdgeInsets.only(
                                      bottom: AppPadding.p8,
                                      top: AppPadding.p18),
                                  child: Giftcart(
                                    ontap: () {
                                      // print("starting geoFencing Service");
                                      EasyGeofencing.startGeofenceService(
                                          pointedLatitude: shops[index]
                                              .markerShop
                                              .locations
                                              .latitude
                                              .toString(),
                                          pointedLongitude: shops[index]
                                              .markerShop
                                              .locations
                                              .longitude
                                              .toString(),
                                          radiusMeter: raduis.toString(),
                                          eventPeriodInSeconds: 5);

                                      geofenceStatusStream ??=
                                          EasyGeofencing.getGeofenceStream()!
                                              .listen((GeofenceStatus? status) {
                                        print(status.toString());
                                        setState(() {
                                          geofenceStatus = status.toString();
                                        });
                                        if (status.toString() ==
                                            'GeofenceStatus.enter') {
                                          print("entered");
                                         
                                        } else {
                                          print("not entered");
                                        }
                                      });
                                    },
                                    shopName: shops[index].shopName,
                                    details: shops[index].shopAddress,
                                    imagePath: ImageAssets.logo1,
                                  ),
                                );
                              },
                              itemCount: shops.length)
                          : Padding(
                              padding: const EdgeInsets.fromLTRB(
                                  AppPadding.p100,
                                  AppPadding.p100,
                                  AppPadding.p100,
                                  AppPadding.p200),
                              child: CircularProgressIndicator(
                                valueColor: AlwaysStoppedAnimation<Color>(
                                    ColorManager.primary),
                              ),
                            )),
                ),
              ],
            ),
          );
        });
  }
}

giftCart widget

import 'package:flutter/material.dart';
import 'package:flutter_application_1/presentation/resources/color_manager.dart';
import 'package:flutter_application_1/presentation/resources/values_manager.dart';
//import 'package:flutter_application_1/presentation/resources/font_manager.dart';

class Giftcart extends StatelessWidget {
  final String shopName;
  final String details;
  final String imagePath;

  final void Function() ontap;

  const Giftcart({
    Key? key,
    required this.ontap,
    required this.shopName,
    required this.details,
    required this.imagePath,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    var height = size.height;
    var width = size.width;
    return Center(
      child: Container(
        decoration: BoxDecoration(
          color: ColorManager.white,
          borderRadius: BorderRadius.circular(10),
          boxShadow: [
            BoxShadow(
              color: ColorManager.grey,
              offset: const Offset(0, 0),
              blurRadius: 10,
            ),
          ],
        ),
        height: height * 0.1,
        width: width * 0.8,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
                height: height * 0.15,
                width: width * 0.15,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(40),
                ),
                child: Image.asset(imagePath)),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  height: height * 0.02,
                ),
                Text(
                  shopName,
                  style: Theme.of(context).textTheme.subtitle2,
                  textAlign: TextAlign.end,
                ),
                SizedBox(
                  height: height * 0.01,
                ),
                Text(
                  details,
                  style: Theme.of(context).textTheme.bodyText1,
                  textAlign: TextAlign.start,
                ),
              ],
            ),
            Padding(
              padding: const EdgeInsets.only(right: 10.0),
              child: SizedBox(
                height: height * 0.12,
                width: width * 0.12,
                child: FloatingActionButton(
                    backgroundColor: ColorManager.primary,
                    onPressed: ontap,
                    child: Icon(
                      Icons.card_giftcard,
                      size: AppSize.s18,
                      color: ColorManager.white,
                    )),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

the Screen
the button on the left is for checking the geofenceStatus

enter image description here

this is the package doc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

上课铃就是安魂曲 2025-01-25 07:48:50

添加“ GeoFencesTatusStream = null;” SupgeoFencesService之后如下:

setState(() {
              EasyGeofencing.stopGeofenceService();
              geofenceStatusStream!.cancel();
              geofenceStatusStream = null;
            });

Add "geofenceStatusStream = null;" after stopGeofenceService as below:

setState(() {
              EasyGeofencing.stopGeofenceService();
              geofenceStatusStream!.cancel();
              geofenceStatusStream = null;
            });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文