无法从 GetX 控制器获取最新值

Unable to get the latest value from GetX Controller

我正在使用 Agora 开发语音通话应用程序。我使用 FCM 在设备上显示呼叫。我使用来自 FCM 的静默通知发送图像和其他所需数据。因此,每当我收到后台通知时,这就是我处理数据并使用 this package:

显示来电通知的方式
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {

  callStateController.isIncoming.value=true;
  callStateController.callerName.value=message.data['callerName'];
  callStateController.callerID.value=message.data['callerID'];
  callStateController.callerImage.value=message.data['callerImage'];
  callStateController.callerUsername.value=message.data['callerUsername'];

  var incoming = <String, dynamic>{
    'id': message.data['callerID'],
    'nameCaller': message.data['callerName'],
    'appName': 'Callkit',
    'avatar': message.data['callerImage'],
    'handle': '',
    'type': 0,
    'duration': 30000,
    'extra': <String, dynamic>{'userId': '1a2b3c4d'},
    'headers': <String, dynamic>{'apiKey': 'Abc@123!', 'platform': 'flutter'},
    'android': <String, dynamic>{
      'isCustomNotification': true,
      'isShowLogo': false,
      'ringtonePath': 'ringtone_default',
      'backgroundColor': '#0955fa',
      //'backgroundUrl': 'https://i.pravatar.cc/500',
      'actionColor': '#4CAF50'
    }};
  await FlutterCallkitIncoming.showCallkitIncoming(incoming);

}

我使用呼叫监听器来获取呼叫的当前状态,例如:接受或拒绝,然后使用我从 FCM 收到的数据推送到设计屏幕:

Future<void> listenerEvent() async {
    String img = callStateController.callerImage.value;
    String name = callStateController.callerName.value;
    String id = callStateController.callerID.value;
    String usrnm = callStateController.callerUsername.value;
    print(callStateController.callerID.value);

    try {
      FlutterCallkitIncoming.onEvent.listen((event) {

        switch (event!.name) {
          case CallEvent.ACTION_CALL_INCOMING:
            print('INCOMING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
            break;
          case CallEvent.ACTION_CALL_START:
          // TODO: started an outgoing call
          // TODO: show screen calling in Flutter
            break;
          case CallEvent.ACTION_CALL_ACCEPT:
            print('accepted');
            print(callStateController.callerImage.value);
            Get.offAll(()=>Incoming(
                userName: name,
                userImage: img,
                userID: id,
                userUsername: usrnm));
            break;
          case CallEvent.ACTION_CALL_DECLINE:
            print('rejected');
            break;
          case CallEvent.ACTION_CALL_ENDED:
          // TODO: ended an incoming/outgoing call
            break;
          case CallEvent.ACTION_CALL_TIMEOUT:
          // TODO: missed an incoming call
            break;
          case CallEvent.ACTION_CALL_CALLBACK:
          // TODO: only Android - click action `Call back` from missed call notification
            break;
          case CallEvent.ACTION_CALL_TOGGLE_HOLD:
          // TODO: only iOS
            break;
          case CallEvent.ACTION_CALL_TOGGLE_MUTE:
          // TODO: only iOS
            break;
          case CallEvent.ACTION_CALL_TOGGLE_DMTF:
          // TODO: only iOS
            break;
          case CallEvent.ACTION_CALL_TOGGLE_GROUP:
          // TODO: only iOS
            break;
          case CallEvent.ACTION_CALL_TOGGLE_AUDIO_SESSION:
          // TODO: only iOS
            break;
        }
        print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
      });
    } on Exception {}
  }

侦听器方法在我的主页的 initState 上运行。这里的问题是监听器从应用程序开始,所以它总是获取控制器的初始值(为空),我稍后获取数据。因此,在这种情况下,如何在接受或拒绝呼叫后从 getx 获取最新值,然后将所需数据推送到 accepted/rejected 呼叫屏幕?

然后我将这个值存储在 GetX 控制器中:

class CallState extends GetxController{

  RxBool isIncoming = false.obs;
  RxString callerName = ''.obs;
  RxString callerID = ''.obs;
  RxString callerImage = ''.obs;
  RxString callerUsername = ''.obs;

}

在 Firebase 后台消息的 documentation 中找到了罪魁祸首::

Since the handler runs in its own isolate outside your applications context, it is not possible to update application state or execute any UI impacting logic. You can however perform logic such as HTTP requests, IO operations (updating local storage), communicate with other plugins etc.