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

Flutter中java.lang.IllegalStateException: Reply already submitted问题求助

Flutter应用启动崩溃:java.lang.IllegalStateException: Reply already submitted

今日频繁遇到应用启动即崩溃的问题,错误日志如下:

D/AndroidRuntime( 6576): Shutting down VM
E/AndroidRuntime( 6576): FATAL EXCEPTION: main
E/AndroidRuntime( 6576): Process: com.example.plannertest, PID: 6576
E/AndroidRuntime( 6576): java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime( 6576):    at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:435)
E/AndroidRuntime( 6576):    at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler$1.reply(BasicMessageChannel.java:222)
E/AndroidRuntime( 6576):    at io.flutter.plugins.firebase.auth.GeneratedAndroidFirebaseAuth$FirebaseAuthUserHostApi$2.success(GeneratedAndroidFirebaseAuth.java:3247)
E/AndroidRuntime( 6576):    at io.flutter.plugins.firebase.auth.GeneratedAndroidFirebaseAuth$FirebaseAuthUserHostApi$2.success(GeneratedAndroidFirebaseAuth.java:3244)
E/AndroidRuntime( 6576):    at io.flutter.plugins.firebase.auth.FlutterFirebaseAuthUser.lambda$getIdToken$1(FlutterFirebaseAuthUser.java:88)
E/AndroidRuntime( 6576):    at io.flutter.plugins.firebase.auth.FlutterFirebaseAuthUser$$ExternalSyntheticLambda2.onComplete(Unknown Source:2)
E/AndroidRuntime( 6576):    at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@18.0.2:1)
E/AndroidRuntime( 6576):    at android.os.Handler.handleCallback(Handler.java:958)
E/AndroidRuntime( 6576):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 6576):    at android.os.Looper.loopOnce(Looper.java:205)
E/AndroidRuntime( 6576):    at android.os.Looper.loop(Looper.java:294)
E/ _方Hearing坑变成-operator neurological独cl� Pandemic � Option strains
E/AndroidRuntime( 6576):    at android.app.ActivityThread.main(ActivityThread.java:8176)
E/AndroidRuntime( 6576):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6576):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime( 6576):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
I/Process ( 6576): Sending signal. PID: 6576 SIG: 9
Lost connection to device.

项目依赖版本

当前pubspec.yaml中的Firebase相关依赖:

firebase_messaging: ^14.6.2
firebase_auth: ^4.7.1
firebase_core: ^2.14.0
cloud_firestore: ^4.8.1

相关代码

问题出现在启动页的登录状态检查逻辑中,怀疑是获取token时触发的崩溃,代码如下:

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SplashLogic extends GetxController
    with GetSingleTickerProviderStateMixin {
  late AnimationController animationController;
  late Animation<double> animation;
  bool isOnboard = false;
  EmployeeResponse employeeResponse = EmployeeResponse();
  final AuthRepository _authRepository = AuthRepository();

  @override
  void onInit() {
    super.onInit();
    animationController = AnimationController(
      duration: const Duration(seconds: 2),
      vsync: this,
    );
    animation = Tween<double>(begin: 0.8, end: 1.0).animate(
      CurvedAnimation(
        parent: animationController,
        curve: Curves.easeInOut,
      ),
    );
    animationController.repeat(reverse: true);
    checkLoginStatus();
  }

  Future<void> checkLoginStatus() async {
    try {
      final token = await FirebaseAuth.instance.currentUser?.getIdToken();
      final userId = FirebaseAuth.instance.currentUser?.uid;
      print('userId: $userId');
      kBox.write('userId', userId);
      print('token: $token');
      kBox.write('token', token);
      if (token != null && token.isNotEmpty) {
        employeeResponse = await _authRepository.organizationMe();
        await _authRepository.getEmployeeMe();
        isOnboard = kBox.read('isOnboard') ?? false;
        await Future.delayed(const Duration(seconds: 2));
        if (FirebaseAuth.instance.currentUser != null) {
          if (token.isNotEmpty &&
              employeeResponse.success == true &&
              employeeResponse.data != null &&
              employeeResponse.data!.isNotEmpty) {
            Get.off(() => HomeNavBar());
          } else {
            Get.off(() => SignupScreen());
          }
        } else if (isOnboard) {
          Get.off(() => const LoginScreen());
        } else if (FirebaseAuth.instance.currentUser == null && isOnboard) {
          Get.off(() => const LoginScreen());
        } else {
          Get.off(() => OnboardScreen());
        }
      } else {
        Get.offAll(() => const LoginScreen());
      }
    } catch (e) {
      print(e);
      Get.off泛理(()
 Consideringblob留下Conc例子 Things sense presse control It this, 
      }
    }
  }

  @override
  void dispose() {
    animationController.dispose();
    super.dispose();
  }
}

解决方案

经排查,问题由Firebase Auth新版本包的bug导致,将依赖降级到以下版本后问题解决:

firebase_auth: 4.6.3
firebase_auth_platform_interface: 6.15.3

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 12:36:10