Hibok
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

799 wiersze
29 KiB

  1. import 'dart:async';
  2. import 'dart:ui';
  3. import 'package:agora_rtc_engine/agora_rtc_engine.dart';
  4. import 'package:cached_network_image/cached_network_image.dart';
  5. import 'package:chat/chat/gift_page.dart';
  6. import 'package:chat/data/UserData.dart';
  7. import 'package:chat/data/WebData.dart';
  8. import 'package:chat/data/constants.dart';
  9. import 'package:chat/generated/i18n.dart';
  10. import 'package:chat/models/UserInfo.dart';
  11. import 'package:chat/models/gift_item_model.dart';
  12. import 'package:chat/models/gift_select_provider.dart';
  13. import 'package:chat/models/money_change.dart';
  14. import 'package:chat/models/ref_name_provider.dart';
  15. import 'package:chat/r.dart';
  16. import 'package:chat/utils/ChargeMoney.dart';
  17. import 'package:chat/utils/CustomUI.dart';
  18. import 'package:chat/utils/HttpUtil.dart';
  19. import 'package:chat/utils/MessageMgr.dart';
  20. import 'package:chat/utils/TokenMgr.dart';
  21. import 'package:chat/utils/anim_effect_overlay.dart';
  22. import 'package:chat/utils/counter_overlay.dart';
  23. import 'package:chat/utils/msgHandler.dart';
  24. import 'package:chat/utils/screen.dart';
  25. import 'package:chat/utils/sound_util.dart';
  26. import 'package:chat/utils/sp_utils.dart';
  27. import 'package:dio/dio.dart';
  28. import 'package:flutter/material.dart';
  29. import 'package:oktoast/oktoast.dart';
  30. import 'package:provider/provider.dart';
  31. class AudioChatPage extends StatefulWidget {
  32. final UserInfo userInfo;
  33. final bool isReplay;
  34. final bool isTranslateButler;
  35. final Function translateButlerCloseCallBack;
  36. AudioChatPage({@required this.userInfo, this.isReplay = false, this.isTranslateButler=false,this.translateButlerCloseCallBack});
  37. @override
  38. _AudioChatPageState createState() => _AudioChatPageState();
  39. }
  40. class _AudioChatPageState extends State<AudioChatPage> {
  41. //是否启用扬声器
  42. bool speakPhone = false;
  43. int friendId;
  44. bool isReply; //是否应答模式
  45. bool isChating = false; //是否通话中
  46. //超时挂断
  47. Timer offTimer;
  48. Timer callingTimer;
  49. String channelName;
  50. //打赏礼物信息
  51. List<GiftItemModel> giftList;
  52. final _controller = new PageController();
  53. //礼物数量
  54. int curGiftValue = 1;
  55. bool isQuit = false;
  56. @override
  57. void initState() {
  58. super.initState();
  59. friendId = widget.userInfo.userId;
  60. isReply = widget.isReplay;
  61. MsgHandler.isAudioConnect = true;
  62. getGiftList();
  63. initAgoreSdk();
  64. getDefaultSetting();
  65. //事件监听回调
  66. setAgoreEventListener();
  67. //礼物打赏
  68. MessageMgr().on('Receive Gift', receiveGift);
  69. MessageMgr().on('AudioChat Failed', closeChat);
  70. MessageMgr().on('AudioChat State', refuseAnswer);
  71. }
  72. void getDefaultSetting() async {
  73. bool soundPlayMode =
  74. (await SPUtils.getBool(Constants.SOUND_PLAY_MODE)) ?? false;
  75. setState(() {
  76. speakPhone = soundPlayMode;
  77. });
  78. AgoraRtcEngine.setEnableSpeakerphone(speakPhone);
  79. }
  80. closeChat(args) {
  81. showToast(I18n.of(context).not_online);
  82. _onExit(context);
  83. }
  84. @override
  85. void didChangeDependencies() {
  86. super.didChangeDependencies();
  87. print('test didChangeDependencies');
  88. }
  89. refuseAnswer(args) {
  90. var fdId = args['fdId'];
  91. var isAnswer = args['isAnswer'];
  92. if (fdId == friendId && !isAnswer) {
  93. // showToast('对方暂时无法接听');
  94. _onExit(context);
  95. }
  96. }
  97. receiveGift(gift) {
  98. int giftId = gift.giftId;
  99. int amount = gift.giftAmount;
  100. int total = gift.money;
  101. print(DateTime.now());
  102. var giftModel = giftList[giftId - 1];
  103. print('收到礼物金额:$total');
  104. UserData().incomeMoney += total;
  105. //Provider.of<MoneyChangeProvider>(context, listen: false).addMoney(total);
  106. AnimEffect.showEffect(context, giftId);
  107. AnimEffect.showDashangEffect(context, false, amount, giftModel.name);
  108. }
  109. //本页面即将销毁
  110. @override
  111. void dispose() {
  112. _controller.dispose();
  113. MessageMgr().off('AudioChat State', refuseAnswer);
  114. MessageMgr().off('AudioChat Failed', closeChat);
  115. MessageMgr().off('Receive Gift', receiveGift);
  116. MsgHandler.isAudioConnect = false;
  117. offTimer?.cancel();
  118. callingTimer?.cancel();
  119. SoundUtils().stop();
  120. AgoraRtcEngine.leaveChannel();
  121. //sdk资源释放
  122. AgoraRtcEngine.destroy();
  123. super.dispose();
  124. }
  125. void initAgoreSdk() {
  126. //初始化引擎
  127. AgoraRtcEngine.create(Constants.Agore_appId);
  128. //设置视频为可用 启用音频模块
  129. AgoraRtcEngine.enableAudio();
  130. //每次需要原生视频都要调用_createRendererView
  131. if (!isReply) {
  132. int myId = UserData().basicInfo.userId;
  133. _createRendererView(myId);
  134. }
  135. }
  136. void getGiftList() async {
  137. Map data = {
  138. "userId": UserData().basicInfo.userId,
  139. };
  140. data['sign'] = TokenMgr().getSign(data);
  141. Response res = await HttpUtil().post('prop/get/list', data: data);
  142. if (res == null) {
  143. return;
  144. }
  145. print(res);
  146. Map resData = res.data;
  147. if (resData['code'] == 0) {
  148. //领取成功
  149. giftList = resData['data']
  150. .map<GiftItemModel>((v) => GiftItemModel.fromJson(v))
  151. .toList();
  152. print('giftList length : ${giftList.length}');
  153. }
  154. }
  155. @override
  156. Widget build(BuildContext context) {
  157. return Scaffold(
  158. body: SafeArea(
  159. child: Stack(
  160. children: <Widget>[
  161. ConstrainedBox(
  162. constraints: BoxConstraints.expand(),
  163. child: CachedNetworkImage(
  164. imageUrl: widget.userInfo.headimgurl,
  165. fit: BoxFit.fill,
  166. placeholder: CustomUI.buildImgLoding)),
  167. BackdropFilter(
  168. filter: new ImageFilter.blur(
  169. sigmaX: Screen.width / 8, sigmaY: Screen.width / 8),
  170. child: Container(
  171. color: Colors.black.withOpacity(0.5),
  172. ),
  173. ),
  174. SafeArea(
  175. child: Padding(
  176. padding: EdgeInsets.symmetric(vertical: 40),
  177. child: Column(
  178. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  179. children: <Widget>[
  180. _viewAudio(),
  181. isReply ? _replayToolBar() : _bottomToolBar(),
  182. ],
  183. ))),
  184. widget.isTranslateButler?InkWell(child: Container( width: 60,height: 60,child: Align(child: Icon(
  185. IconData(0xe67f, fontFamily: Constants.IconFontFamily),
  186. color: Colors.white,
  187. size: 35.0,
  188. ),alignment: Alignment.center,),),onTap: (){
  189. widget.translateButlerCloseCallBack(1);
  190. print('内页内页');
  191. },):Container()
  192. ],
  193. )));
  194. }
  195. _viewAudio() {
  196. var url = widget.userInfo.headimgurl;
  197. print('url : $url');
  198. print(url.length);
  199. var userName = Provider.of<RefNameProvider>(context)
  200. .getRefName(widget.userInfo.userId, widget.userInfo.nickName);
  201. var local = WebData().getCity(widget.userInfo.city);
  202. var profession = WebData().getProffesionName(widget.userInfo.occupation);
  203. var birth = widget.userInfo.birthday;
  204. print('birth : $birth');
  205. var birthDay = DateTime.parse(birth);
  206. print(birthDay);
  207. var today = DateTime.now();
  208. var testAge = today.difference(birthDay);
  209. print(testAge.inDays);
  210. var age = testAge.inDays ~/ 365;
  211. var connectTip;
  212. if (isChating) {
  213. connectTip = I18n.of(context).chatting;
  214. } else {
  215. if (isReply) {
  216. connectTip = I18n.of(context).voice_msg.replaceFirst('/s1', userName);
  217. } else {
  218. connectTip = I18n.of(context).waitting_answer;
  219. }
  220. }
  221. return Container(
  222. child: Column(
  223. children: <Widget>[
  224. ClipRRect(
  225. borderRadius: BorderRadius.circular(0),
  226. child: url.length == 0
  227. ? SizedBox(
  228. height: 100,
  229. width: 100,
  230. child: Image.asset(R.assetsImagesDefaultNorAvatar))
  231. : CachedNetworkImage(
  232. width: 100,
  233. height: 100,
  234. imageUrl: url,
  235. placeholder: (context, url) => Padding(
  236. padding: EdgeInsets.all(5),
  237. child: CircularProgressIndicator(
  238. valueColor:
  239. AlwaysStoppedAnimation(Constants.BlueTextColor)),
  240. ),
  241. fit: BoxFit.cover,
  242. ),
  243. ),
  244. SizedBox(height: 5),
  245. Row(
  246. mainAxisAlignment: MainAxisAlignment.center,
  247. children: <Widget>[
  248. Container(
  249. constraints: BoxConstraints(maxWidth: Screen.width - 50),
  250. child: Text(
  251. userName,
  252. style: TextStyle(fontSize: 20, color: Colors.white70),
  253. textScaleFactor: 1.0,
  254. overflow: TextOverflow.ellipsis,
  255. textAlign: TextAlign.center,
  256. )),
  257. fixedText(' $age', fontSize: 20, color: Colors.white70)
  258. ],
  259. ),
  260. SizedBox(height: 5),
  261. Text(
  262. '$local',
  263. style: TextStyle(fontSize: 16, color: Colors.white70),
  264. textScaleFactor: 1.0,
  265. textAlign: TextAlign.center,
  266. ),
  267. SizedBox(height: 5),
  268. Text(
  269. '$profession',
  270. style: TextStyle(fontSize: 16, color: Colors.white70),
  271. textScaleFactor: 1.0,
  272. textAlign: TextAlign.center,
  273. ),
  274. SizedBox(height: 20),
  275. Container(
  276. width: Screen.width - 50,
  277. child: Text(
  278. connectTip,
  279. //maxLines: 2,
  280. style: TextStyle(fontSize: 20, color: Colors.white70),
  281. textScaleFactor: 1.0,
  282. textAlign: TextAlign.center,
  283. )),
  284. ],
  285. ),
  286. );
  287. }
  288. _replayToolBar() {
  289. return Container(
  290. child: Row(
  291. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  292. children: <Widget>[
  293. //接听按钮
  294. RawMaterialButton(
  295. onPressed: () {
  296. MsgHandler.stopAudioRing();
  297. int myId = UserData().basicInfo.userId;
  298. MsgHandler.sendReplyAudioChatReq(friendId, true);
  299. _createRendererView(myId);
  300. },
  301. child: Icon(
  302. Icons.call,
  303. color: Colors.white,
  304. size: 35.0,
  305. ),
  306. shape: CircleBorder(),
  307. elevation: 2.0,
  308. fillColor: Colors.greenAccent,
  309. padding: const EdgeInsets.all(15.0),
  310. ),
  311. //挂断按钮
  312. RawMaterialButton(
  313. onPressed: () {
  314. _onExit(context);
  315. MsgHandler.stopAudioRing();
  316. MsgHandler.sendReplyAudioChatReq(friendId, false);
  317. },
  318. child: Icon(
  319. Icons.call_end,
  320. color: Colors.white,
  321. size: 35.0,
  322. ),
  323. shape: CircleBorder(),
  324. elevation: 2.0,
  325. fillColor: Colors.redAccent,
  326. padding: const EdgeInsets.all(15.0),
  327. )
  328. ]));
  329. }
  330. _bottomToolBar() {
  331. List<Widget> showWidgets = [
  332. Text(I18n.of(context).voicing,
  333. textScaleFactor: 1.0,
  334. style: TextStyle(fontSize: 11, color: Colors.white24),
  335. textAlign: TextAlign.center),
  336. SizedBox(height: 10),
  337. Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[
  338. Offstage(
  339. offstage: !isChating,
  340. child: UserData().giftSwitch > 0
  341. ? RawMaterialButton(
  342. onPressed: _showGiftSheet,
  343. child: Icon(
  344. IconData(0xe64e, fontFamily: Constants.IconFontFamily),
  345. color: Colors.blueAccent,
  346. size: 20.0,
  347. ),
  348. shape: CircleBorder(),
  349. elevation: 2.0,
  350. fillColor: Colors.white,
  351. padding: const EdgeInsets.all(12.0),
  352. )
  353. : SizedBox(width: 36, height: 36)),
  354. //挂断按钮
  355. RawMaterialButton(
  356. onPressed: () {
  357. MsgHandler.sendReplyAudioChatReq(friendId, false);
  358. _onExit(context);
  359. },
  360. child: Icon(
  361. Icons.call_end,
  362. color: Colors.white,
  363. size: 35.0,
  364. ),
  365. shape: CircleBorder(),
  366. elevation: 2.0,
  367. fillColor: Colors.redAccent,
  368. padding: const EdgeInsets.all(15.0),
  369. ),
  370. //是否外放
  371. Offstage(
  372. offstage: !isChating,
  373. child: RawMaterialButton(
  374. onPressed: _isSpeakPhone,
  375. child: new Icon(
  376. speakPhone ? Icons.volume_up : Icons.volume_down,
  377. color: Colors.blueAccent,
  378. size: 20.0,
  379. ),
  380. shape: new CircleBorder(),
  381. elevation: 2.0,
  382. fillColor: Colors.white,
  383. padding: const EdgeInsets.all(12.0),
  384. ))
  385. ])
  386. ];
  387. if (isChating) {
  388. showWidgets.insert(
  389. 0,
  390. Container(
  391. alignment: Alignment.center,
  392. height: 80,
  393. width: 200,
  394. child: CounterOverlay(),
  395. ));
  396. }
  397. return Container(
  398. child: Column(children: showWidgets),
  399. );
  400. }
  401. //创建渲染视图
  402. void _createRendererView(int uId) {
  403. //增加音频会话对象 为了音频布局需要(通过uid和容器信息)
  404. //加入频道 第一个参数是 token 第二个是频道id 第三个参数 频道信息 一般为空 第四个 用户id
  405. int myId = UserData().basicInfo.userId;
  406. setState(() {
  407. print('加入聊天房间');
  408. var channelName = UserData().getSessionId(friendId).toString();
  409. AgoraRtcEngine.joinChannel(null, channelName, null, myId);
  410. });
  411. }
  412. //设置事件监听
  413. void setAgoreEventListener() {
  414. //成功加入房间
  415. AgoraRtcEngine.onJoinChannelSuccess =
  416. (String channel, int uid, int elapsed) {
  417. print("加入成功id为:$uid elapsed:$elapsed");
  418. if (isReply) {
  419. //回应
  420. setState(() {
  421. isReply = false;
  422. isChating = true;
  423. });
  424. } else {
  425. MsgHandler.sendAudioChatReq(widget.userInfo.userId);
  426. callingTimer = Timer.periodic(Duration(milliseconds: 2200), (timer) {
  427. SoundUtils().play(
  428. 'http://testcyhd.chengyouhd.com/Upload/Audio/even_wheat_sound.mp3',
  429. isLocal: false);
  430. });
  431. //30没人接就自动挂断
  432. offTimer = Timer(Duration(seconds: 30), () {
  433. MsgHandler.sendReplyAudioChatReq(friendId, false);
  434. _onExit(context);
  435. });
  436. }
  437. };
  438. //监听是否有新用户加入
  439. AgoraRtcEngine.onUserJoined = (int uid, int elapsed) {
  440. print("新用户所加入的id为:$uid elapsed:$elapsed");
  441. setState(() {
  442. //更新UI布局
  443. SoundUtils().stop();
  444. callingTimer?.cancel();
  445. isChating = true;
  446. offTimer?.cancel();
  447. });
  448. };
  449. //监听用户是否离开这个房间
  450. AgoraRtcEngine.onUserOffline = (int uid, int reason) {
  451. print("用户离开的id为:$uid");
  452. _onExit(context);
  453. };
  454. AgoraRtcEngine.onError = (dynamic errCode) {
  455. print('通话异常');
  456. // _onExit(context);
  457. };
  458. //监听用户是否离开这个频道
  459. AgoraRtcEngine.onLeaveChannel = () {
  460. print("用户离开");
  461. };
  462. }
  463. void _showGiftSheet() {
  464. showModalBottomSheet(
  465. context: context,
  466. elevation: 2.0,
  467. shape: RoundedRectangleBorder(
  468. borderRadius: BorderRadius.only(
  469. topLeft: Radius.circular(20), topRight: Radius.circular(20))),
  470. backgroundColor: Colors.transparent,
  471. builder: (BuildContext context) {
  472. return StatefulBuilder(
  473. builder: (BuildContext context, setBottomSheetState) {
  474. return Container(
  475. height: 400,
  476. width: Screen.width,
  477. decoration: BoxDecoration(
  478. color: Colors.white,
  479. ),
  480. child: giftList == null
  481. ? Center(
  482. child: Text(
  483. I18n.of(context).no_gift,
  484. textScaleFactor: 1.0,
  485. ))
  486. : Column(
  487. children: <Widget>[
  488. Container(
  489. // decoration: BoxDecoration(
  490. // color: Colors.orangeAccent,
  491. // borderRadius: borderRadius
  492. // ),
  493. padding: EdgeInsets.symmetric(
  494. vertical: 10, horizontal: 20),
  495. child: Row(
  496. children: <Widget>[
  497. Text(I18n.of(context).sent_gift,
  498. textScaleFactor: 1.0,
  499. style: TextStyle(
  500. fontSize: 16,
  501. fontWeight: FontWeight.bold,
  502. color: Constants.BlackTextColor)),
  503. Expanded(
  504. child: SizedBox(),
  505. ),
  506. Image.asset(
  507. R.assetsImagesCoin,
  508. scale: 2,
  509. ),
  510. SizedBox(
  511. width: 5,
  512. ),
  513. fixedText(
  514. I18n.of(context)
  515. .available_balance
  516. .replaceFirst('/s1', ''),
  517. color: Constants.GreyTextColor),
  518. Consumer<MoneyChangeProvider>(
  519. builder: (context,
  520. MoneyChangeProvider counter,
  521. child) =>
  522. fixedText(counter.money.toString(),
  523. color: Color(0xFFDB305D)),
  524. ),
  525. fixedText(I18n.of(context).mask_coin,
  526. color: Color(0xFFDB305D)),
  527. ],
  528. ),
  529. ),
  530. Container(
  531. alignment: Alignment.topCenter,
  532. padding: EdgeInsets.all(10),
  533. height: 230,
  534. child: GiftPage(giftList, 0),
  535. ),
  536. Expanded(child: SizedBox()),
  537. Padding(
  538. padding: EdgeInsets.symmetric(
  539. vertical: 5, horizontal: 20),
  540. child: Row(
  541. children: <Widget>[
  542. Expanded(
  543. child: SizedBox(
  544. height: 36,
  545. child: RaisedButton(
  546. padding:
  547. EdgeInsets.symmetric(horizontal: 5),
  548. child: Text(
  549. I18n.of(context).recharge,
  550. textScaleFactor: 1.0,
  551. maxLines: 1,
  552. style: TextStyle(
  553. fontSize: 16,
  554. fontWeight: FontWeight.bold),
  555. ),
  556. elevation: 2.0,
  557. color: Colors.orangeAccent,
  558. textColor: Colors.white,
  559. onPressed: () {
  560. ChargeMoney.showChargeSheet(context,
  561. () {
  562. setState(() {});
  563. });
  564. },
  565. shape: RoundedRectangleBorder(
  566. borderRadius: BorderRadius.all(
  567. Radius.circular(20)),
  568. ),
  569. ),
  570. )),
  571. SizedBox(width: 20),
  572. Expanded(
  573. flex: 2,
  574. child: Container(
  575. height: 36,
  576. decoration: BoxDecoration(
  577. boxShadow: [
  578. BoxShadow(
  579. blurRadius: 2.0,
  580. color: Colors.white24)
  581. ],
  582. borderRadius: BorderRadius.all(
  583. Radius.circular(20)),
  584. border: Border.all(
  585. color: Colors.red)),
  586. child: Row(
  587. children: <Widget>[
  588. Expanded(
  589. child: DropdownButton(
  590. isExpanded: true,
  591. underline: Container(),
  592. value: curGiftValue,
  593. style: TextStyle(fontSize: 16),
  594. iconEnabledColor:
  595. Colors.redAccent,
  596. onChanged: (newValue) {
  597. setBottomSheetState(() {
  598. curGiftValue = newValue;
  599. });
  600. },
  601. items: <int>[1, 6, 8, 66]
  602. .map<DropdownMenuItem>((v) => DropdownMenuItem(
  603. value: v,
  604. child: Container(
  605. padding:
  606. EdgeInsets.only(
  607. left: 20),
  608. child: fixedText(
  609. v.toString(),
  610. color: v == curGiftValue
  611. ? Colors
  612. .redAccent
  613. : Colors
  614. .black))))
  615. .toList(),
  616. )),
  617. Expanded(
  618. child: InkWell(
  619. child: Container(
  620. decoration: BoxDecoration(
  621. color: Color(0xFFFD6E8F),
  622. borderRadius:
  623. BorderRadius.only(
  624. topRight: Radius
  625. .circular(20),
  626. bottomRight:
  627. Radius.circular(
  628. 20)),
  629. ),
  630. height: 36,
  631. alignment: Alignment.center,
  632. child: Text(
  633. I18n.of(context).give,
  634. textScaleFactor: 1.0,
  635. style: TextStyle(
  636. color: Colors.white,
  637. fontSize: 16,
  638. fontWeight:
  639. FontWeight.bold),
  640. ),
  641. ),
  642. onTap: () {
  643. _sendGift(context);
  644. },
  645. ))
  646. ],
  647. )))
  648. ],
  649. ),
  650. )
  651. ],
  652. ));
  653. },
  654. );
  655. });
  656. }
  657. _sendGift(BuildContext context) async {
  658. int curSelectIndex =
  659. Provider.of<GiftSelectProvider>(context).curSelectIndex;
  660. var curGift = giftList[curSelectIndex];
  661. int price = curGift.price;
  662. int giftId = curGift.id;
  663. int total = curGiftValue * price;
  664. if (total > Provider.of<MoneyChangeProvider>(context).money) {
  665. showToast(I18n.of(context).not_enough);
  666. return;
  667. }
  668. int buyCount = 0;
  669. if (curGiftValue > curGift.amount) {
  670. buyCount = curGiftValue - curGift.amount;
  671. }
  672. Map data = {
  673. "userId": UserData().basicInfo.userId,
  674. "rUserId": friendId,
  675. "id": giftId,
  676. "price": price,
  677. "amount": curGiftValue,
  678. "totalPrice": total,
  679. "payNum": buyCount
  680. };
  681. data['sign'] = TokenMgr().getSign(data);
  682. Response res = await HttpUtil().post('reward/gift', data: data);
  683. if (res == null) {
  684. return;
  685. }
  686. Map resData = res.data;
  687. //showToast(resData['msg']);
  688. if (resData['code'] == 0) {
  689. //赠送成功
  690. print('赠送金额:${resData['data']}');
  691. int receiveAmount = resData['data'];
  692. Navigator.pop(context);
  693. Provider.of<MoneyChangeProvider>(context, listen: false).subMoney(total);
  694. AnimEffect.showEffect(context, giftId);
  695. AnimEffect.showDashangEffect(context, true, curGiftValue, curGift.name);
  696. MsgHandler.sendGiftTo(friendId, giftId, curGiftValue, receiveAmount);
  697. setState(() {});
  698. }
  699. }
  700. //是否开启扬声器
  701. void _isSpeakPhone() {
  702. setState(() {
  703. speakPhone = !speakPhone;
  704. });
  705. AgoraRtcEngine.setEnableSpeakerphone(speakPhone);
  706. }
  707. //退出频道 退出本页面
  708. void _onExit(BuildContext context) {
  709. if (!isQuit) {
  710. if (Navigator.canPop(context)) {
  711. isQuit = true;
  712. if(widget.translateButlerCloseCallBack!=null){
  713. widget.translateButlerCloseCallBack(2);
  714. }else{
  715. Navigator.of(context).pop();
  716. }
  717. SoundUtils().stop();
  718. callingTimer?.cancel();
  719. }
  720. }
  721. }
  722. }