You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter应用请求定位权限时崩溃问题求助

Flutter请求定位权限时崩溃(Reply already submitted)

问题分析

从崩溃日志的堆栈追踪可以明确:崩溃的核心原因是java.lang.IllegalStateException: Reply already submitted,且问题出在com.shounakmulay.telephony.sms.SmsMethodCallHandler类中——这是telephony Flutter插件在处理权限结果回调时的重复回复bug,和你编写的定位权限请求逻辑无关。

解决方法

1. 优先升级telephony插件

这个bug已经在telephony插件的后续版本中被修复,直接升级到最新稳定版即可解决问题:

  • 打开项目的pubspec.yaml文件,找到telephony依赖项,更新为最新版本号:
dependencies:
  telephony: ^最新版本号 # 替换为当前最新稳定版,比如0.2.0+1
  • 执行flutter pub get命令更新依赖,然后重新编译运行应用。

2. 临时规避方案(无法立即升级时)

如果暂时无法升级插件,可以通过添加短暂延迟来避免多个插件的权限回调冲突:

Future<Position> _determinePosition() async {
  LocationPermission permission;

  // 添加200ms延迟,错开其他插件的权限回调处理
  await Future.delayed(const Duration(milliseconds: 200));
  
  permission = await _geolocatorPlatform.checkPermission();
  if (permission == LocationPermission.denied) {
    permission = await _geolocatorPlatform.requestPermission();
  }

  if (permission == LocationPermission.deniedForever) {
    return Future.error(Exception(
        'Location permissions are permanently denied, we cannot request permissions.'));
  }

  return await _geolocatorPlatform.getCurrentPosition();
}

验证说明

完成上述操作后,重新启动应用并请求定位权限,崩溃问题应该会消失。

内容的提问来源于stack exchange,提问作者Hamid Salehi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 08:25:15