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

如何检测Flutter Widget状态变化,监听phoneCall通话结束弹出评分弹窗

实现通话结束自动弹出评分弹窗的方案

修改_initCall方法

你使用的flutter_phone_state库返回的通话对象自带完成监听回调,只需要在发起通话时监听通话结束事件即可,修改后的代码如下:

_initCall(_number) async {
  final newCall = FlutterPhoneState.startPhoneCall(_number);
  setState(() {
    phoneCall = newCall;
  });
  // 等待通话结束
  await newCall.done;
  // 页面已销毁的情况下不执行弹窗逻辑,避免异常
  if (!mounted) return;

  // 弹出评分弹窗,你可以根据需求调整UI和交互逻辑
  CoolAlert.show(
    context: context,
    type: CoolAlertType.success,
    title: '通话已结束',
    text: '麻烦您对本次通话进行评分',
    confirmBtnText: '提交评分',
    confirmBtnColor: const Color(0xBF35126A),
    showCancelBtn: true,
    cancelBtnText: '稍后评价',
    // 可在此处插入星级评分等自定义控件
    widget: Padding(
      padding: const EdgeInsets.symmetric(vertical: 20),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: const [
          Icon(Icons.star, color: Colors.orange, size: 30),
          Icon(Icons.star, color: Colors.orange, size: 30),
          Icon(Icons.star, color: Colors.orange, size: 30),
          Icon(Icons.star_border, color: Colors.orange, size: 30),
          Icon(Icons.star_border, color: Colors.orange, size: 30),
        ],
      ),
    ),
    onConfirmBtnTap: () {
      // 此处编写评分提交逻辑
      Navigator.pop(context);
    },
  );
}

可选优化说明

  • 你可以根据newCall.status的返回值判断通话结束的类型,只在正常通话结束(status == 'disconnected')时弹出评分,过滤拨号错误、用户拒接等场景。
  • 如果需要更灵活的评分交互,可以引入flutter_rating_bar等第三方评分组件替换示例中的静态星级控件。
  • 你当前代码中build方法里判断phoneCall.isComplete展示通话结束提示的逻辑可以保留,不冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 20:48:03