Browse Source

聊天页面的返回键优化

master
ZHR007 2 months ago
parent
commit
4b24fd61fe
3 changed files with 33 additions and 15 deletions
  1. 6
      lib/controller/message/chat_controller.dart
  2. 2
      lib/pages/discover/live_room_page.dart
  3. 40
      lib/pages/message/chat_page.dart

6
lib/controller/message/chat_controller.dart

@ -38,7 +38,7 @@ class ChatController extends GetxController {
// //
final RxBool isSendingVideo = RxBool(false); final RxBool isSendingVideo = RxBool(false);
final RxString sendingStatus = RxString(''); final RxString sendingStatus = RxString('');
var isDialogShowing = false.obs;
// //
final RxBool isSendingVoice = RxBool(false); final RxBool isSendingVoice = RxBool(false);
@ -121,6 +121,10 @@ class ChatController extends GetxController {
} }
} }
void setDialogDismiss(bool flag){
isDialogShowing.value = flag;
}
/// 线 /// 线
Future<void> subscribeUserPresence() async { Future<void> subscribeUserPresence() async {
try { try {

2
lib/pages/discover/live_room_page.dart

@ -246,7 +246,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
return Obx(() { return Obx(() {
return PopScope( return PopScope(
canPop: !_roomController.isDialogShowing.value, canPop: !_roomController.isDialogShowing.value,
onPopInvokedWithResult: (bool didPop, Object? result) async {
onPopInvokedWithResult: (bool didPop, Object? result) {
// SmartDialog.dismiss(); // SmartDialog.dismiss();
// print('256>22>>' + didPop.toString()); // print('256>22>>' + didPop.toString());
// if (didPop) return; // if (didPop) return;

40
lib/pages/message/chat_page.dart

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:im_flutter_sdk/im_flutter_sdk.dart'; import 'package:im_flutter_sdk/im_flutter_sdk.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../controller/message/call_controller.dart'; import '../../controller/message/call_controller.dart';
import '../../controller/message/chat_controller.dart'; import '../../controller/message/chat_controller.dart';
@ -137,7 +138,7 @@ class _ChatPageState extends State<ChatPage> {
// LiveRoomPage // LiveRoomPage
_refreshRoseBalance(); _refreshRoseBalance();
_controller.setDialogDismiss(true);
SmartDialog.show( SmartDialog.show(
builder: (context) { builder: (context) {
return ChatGiftPopup( return ChatGiftPopup(
@ -154,7 +155,10 @@ class _ChatPageState extends State<ChatPage> {
}, },
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
animationType: SmartAnimationType.centerFade_otherSlide, animationType: SmartAnimationType.centerFade_otherSlide,
maskColor: Colors.black.withOpacity(0.5),
maskColor: TDTheme.of(context).fontGyColor2,
onDismiss: () {
_controller.setDialogDismiss(false);
},
maskWidget: GestureDetector( maskWidget: GestureDetector(
onTap: () => SmartDialog.dismiss(), onTap: () => SmartDialog.dismiss(),
child: Container(color: Colors.transparent), child: Container(color: Colors.transparent),
@ -179,12 +183,10 @@ class _ChatPageState extends State<ChatPage> {
} }
// //
void _showCallTypeSelectionDialog(
ChatController controller, {
List<ChatAudioProductModel>? products,
}) {
void _showCallTypeSelectionDialog(ChatController controller, {List<ChatAudioProductModel>? products}) {
// //
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
_controller.setDialogDismiss(true);
SmartDialog.show( SmartDialog.show(
builder: (context) { builder: (context) {
return CallTypeSelectionDialog( return CallTypeSelectionDialog(
@ -225,7 +227,10 @@ class _ChatPageState extends State<ChatPage> {
}, },
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
animationType: SmartAnimationType.centerFade_otherSlide, animationType: SmartAnimationType.centerFade_otherSlide,
maskColor: Colors.black.withOpacity(0.5),
maskColor: TDTheme.of(context).fontGyColor2,
onDismiss: () {
_controller.setDialogDismiss(false);
},
maskWidget: GestureDetector( maskWidget: GestureDetector(
onTap: () => SmartDialog.dismiss(), onTap: () => SmartDialog.dismiss(),
child: Container(color: Colors.transparent), child: Container(color: Colors.transparent),
@ -238,13 +243,18 @@ class _ChatPageState extends State<ChatPage> {
return GetBuilder<ChatController>( return GetBuilder<ChatController>(
init: _controller, init: _controller,
builder: (controller) { builder: (controller) {
return WillPopScope(
onWillPop: () async {
return PopScope(
canPop: !controller.isDialogShowing.value,
onPopInvokedWithResult: (bool didPop, Object? result) async {
// 退 // 退
if (controller.isDialogShowing.value) {
SmartDialog.dismiss();
return; //
}
await VoicePlayerManager.instance.stop(); await VoicePlayerManager.instance.stop();
//
SmartDialog.dismiss();
return true;
if (!didPop) {
Get.back();
}
}, },
child: Scaffold( child: Scaffold(
backgroundColor: Color(0xffF5F5F5), backgroundColor: Color(0xffF5F5F5),
@ -719,9 +729,13 @@ class _ChatPageState extends State<ChatPage> {
onTap: () { onTap: () {
// //
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
_controller.setDialogDismiss(true);
SmartDialog.show( SmartDialog.show(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
maskColor: Colors.black.withOpacity(0.5),
maskColor: TDTheme.of(context).fontGyColor2,
onDismiss: () {
_controller.setDialogDismiss(false);
},
builder: (_) => const LiveRechargePopup(), builder: (_) => const LiveRechargePopup(),
); );
}, },

Loading…
Cancel
Save