654 lines
27 KiB
Dart
654 lines
27 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_debounce_widget.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_compontent.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_tts.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_loading_manager.dart';
|
|
import 'package:aslan/chatvibe_data/sources/repositories/user_repository_impl.dart';
|
|
import 'package:aslan/chatvibe_managers/rtc_manager.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:aslan/chatvibe_ui/components/appbar/chatvibe_appbar.dart';
|
|
import 'package:aslan/chatvibe_ui/components/dialog/dialog_base.dart';
|
|
import 'package:aslan/chatvibe_core/constants/at_screen.dart';
|
|
import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_pick_utils.dart';
|
|
import 'package:aslan/chatvibe_managers/room_manager.dart';
|
|
import 'package:aslan/chatvibe_managers/rtm_manager.dart';
|
|
import '../../../chatvibe_core/utilities/at_lk_dialog_util.dart';
|
|
import '../../../chatvibe_data/models/enum/at_room_info_event_type.dart';
|
|
import '../../../chatvibe_data/sources/repositories/room_repository_imp.dart';
|
|
import '../../../chatvibe_domain/usecases/at_accurate_length_limiting_textInput_formatter.dart';
|
|
import '../../../chatvibe_ui/widgets/pop/pop_route.dart';
|
|
import '../../../chatvibe_ui/widgets/room/pwd/set_room_pwd_page.dart';
|
|
import '../../../chatvibe_ui/widgets/room/room_membership_fee_page.dart';
|
|
import '../../../chatvibe_ui/widgets/room/switch_model/room_mic_switch_page.dart';
|
|
import '../../../main.dart';
|
|
import '../block/blocked_list_page.dart';
|
|
import '../voice_room_route.dart';
|
|
|
|
///编辑房间信息
|
|
class RoomEditPage extends StatefulWidget {
|
|
String needRestCurrentRoomInfo = "false";
|
|
|
|
RoomEditPage({super.key, this.needRestCurrentRoomInfo = "false"});
|
|
|
|
@override
|
|
_RoomEditPageState createState() => _RoomEditPageState();
|
|
}
|
|
|
|
class _RoomEditPageState extends State<RoomEditPage> {
|
|
RtcProvider? rtcProvider;
|
|
bool isEdit = false;
|
|
final TextEditingController _roomNameController = TextEditingController();
|
|
final TextEditingController _roomAnnouncementController =
|
|
TextEditingController();
|
|
final int _roomNameMaxLength = 24;
|
|
int _roomNameCurrentLength = 0;
|
|
String roomCover = "";
|
|
final int _roomAnnouncementMaxLength = 100;
|
|
int _roomAnnouncementCurrentLength = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
rtcProvider = Provider.of<RtcProvider>(context, listen: false);
|
|
_roomNameController.addListener(() {
|
|
setState(() {
|
|
_roomNameCurrentLength = _getActualCharacterCount(
|
|
_roomNameController.text,
|
|
);
|
|
});
|
|
});
|
|
_roomAnnouncementController.addListener(() {
|
|
setState(() {
|
|
_roomAnnouncementCurrentLength = _getActualCharacterCount(
|
|
_roomAnnouncementController.text,
|
|
);
|
|
});
|
|
});
|
|
_roomNameController.text =
|
|
rtcProvider?.currenRoom?.roomProfile?.roomProfile?.roomName ?? "";
|
|
_roomNameCurrentLength = _getActualCharacterCount(_roomNameController.text);
|
|
_roomAnnouncementController.text =
|
|
rtcProvider?.currenRoom?.roomProfile?.roomProfile?.roomDesc ?? "";
|
|
_roomAnnouncementCurrentLength = _getActualCharacterCount(
|
|
_roomAnnouncementController.text,
|
|
);
|
|
roomCover =
|
|
rtcProvider?.currenRoom?.roomProfile?.roomProfile?.roomCover ?? "";
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return WillPopScope(
|
|
onWillPop: () {
|
|
if (!isEdit) {
|
|
ATNavigatorUtils.goBack(context);
|
|
return Future.value(false);
|
|
}
|
|
SmartDialog.show(
|
|
tag: "showConfirmDialog",
|
|
alignment: Alignment.center,
|
|
debounce: true,
|
|
animationType: SmartAnimationType.fade,
|
|
builder: (_) {
|
|
return MsgDialog(
|
|
title: ATAppLocalizations.of(context)!.tips,
|
|
msg: ATAppLocalizations.of(context)!.theModificationsMade,
|
|
onEnsure: () {
|
|
ATNavigatorUtils.goBack(context);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
return Future.value(false);
|
|
},
|
|
child: Stack(
|
|
children: [
|
|
Image.asset(
|
|
"atu_images/person/at_icon_edit_userinfo_bg.png",
|
|
width: ScreenUtil().screenWidth,
|
|
height: ScreenUtil().screenHeight,
|
|
fit: BoxFit.fill,
|
|
),
|
|
Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
backgroundColor: Colors.transparent,
|
|
appBar: ChatVibeStandardAppBar(
|
|
title: ATAppLocalizations.of(context)!.roomSetting,
|
|
onTag: () {
|
|
if (widget.needRestCurrentRoomInfo == "true") {
|
|
Provider.of<RtcProvider>(context, listen: false).currenRoom =
|
|
null;
|
|
}
|
|
Navigator.pop(context);
|
|
},
|
|
actions: [
|
|
GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
child: Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 5.w),
|
|
margin: EdgeInsetsDirectional.only(end: 8.w),
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.save,
|
|
textColor: Colors.black45,
|
|
fontSize: 15.sp,
|
|
),
|
|
),
|
|
onTap: () {
|
|
submit(context);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 35.w),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
GestureDetector(
|
|
child: Stack(
|
|
alignment: Alignment.bottomRight,
|
|
children: [
|
|
netImage(
|
|
url: roomCover,
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(12),
|
|
),
|
|
width: 90.w,
|
|
height: 90.w,
|
|
),
|
|
Icon(Icons.camera_alt, size: 25.w),
|
|
],
|
|
),
|
|
onTap: () {
|
|
ATPickUtils.pickImageProcess(context, (
|
|
bool success,
|
|
String url,
|
|
) {
|
|
if (success) {
|
|
setState(() {
|
|
roomCover = url;
|
|
});
|
|
}
|
|
});
|
|
},
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 25.w),
|
|
Row(
|
|
children: [
|
|
SizedBox(width: 25.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.roomName,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 15.sp,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 10.w),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 25.w),
|
|
padding: EdgeInsets.only(
|
|
left: width(12),
|
|
right: width(12),
|
|
),
|
|
alignment: AlignmentDirectional.centerStart,
|
|
height: 45.w,
|
|
width: ScreenUtil().screenWidth,
|
|
decoration: BoxDecoration(
|
|
color: Color(0xffF2F2F2),
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(height(8)),
|
|
),
|
|
),
|
|
child: TextField(
|
|
controller: _roomNameController,
|
|
onChanged: (text) {
|
|
isEdit = true;
|
|
},
|
|
inputFormatters: [
|
|
ATAccurateLengthLimitingTextInputFormatter(
|
|
_roomNameMaxLength,
|
|
),
|
|
],
|
|
decoration: InputDecoration(
|
|
hintText:
|
|
ATAppLocalizations.of(context)!.enterRoomName,
|
|
hintStyle: TextStyle(
|
|
color: Colors.black45,
|
|
fontSize: 14.sp,
|
|
),
|
|
contentPadding: EdgeInsets.only(top: 0.w),
|
|
counterText: '',
|
|
isDense: true,
|
|
filled: false,
|
|
focusColor: Colors.transparent,
|
|
hoverColor: Colors.transparent,
|
|
border: InputBorder.none,
|
|
enabledBorder: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
disabledBorder: InputBorder.none,
|
|
errorBorder: InputBorder.none,
|
|
focusedErrorBorder: InputBorder.none,
|
|
// enabledBorder: UnderlineInputBorder(
|
|
// borderSide: BorderSide(width: 0.5,color: Colors.white,style: BorderStyle.solid),),
|
|
// focusedBorder: UnderlineInputBorder(
|
|
// borderSide: BorderSide(width: 0.5,color: Colors.white,style: BorderStyle.solid),),
|
|
// prefixIcon: Padding(padding: EdgeInsets.all(8.w), child: Image.asset("images/login/at_icon_phone.png",width: 20.w, height: 20.w,fit: BoxFit.fill,),),
|
|
fillColor: Colors.black45,
|
|
suffix: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(width: 3.w),
|
|
text(
|
|
'$_roomNameCurrentLength/$_roomNameMaxLength',
|
|
textColor: Color(0xFF999999),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
style: TextStyle(
|
|
fontSize: sp(15),
|
|
color: Colors.black,
|
|
textBaseline: TextBaseline.alphabetic,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 15.w),
|
|
Row(
|
|
children: [
|
|
SizedBox(width: 25.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.roomAnnouncement,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 15.sp,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 10.w),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 25.w),
|
|
padding: EdgeInsets.only(
|
|
top: 5.w,
|
|
left: width(12),
|
|
right: width(12),
|
|
),
|
|
alignment: AlignmentDirectional.centerStart,
|
|
height: 110.w,
|
|
width: ScreenUtil().screenWidth,
|
|
decoration: BoxDecoration(
|
|
color: Color(0xffF2F2F2),
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(height(8)),
|
|
),
|
|
),
|
|
child: TextField(
|
|
controller: _roomAnnouncementController,
|
|
onChanged: (text) {
|
|
isEdit = true;
|
|
},
|
|
inputFormatters: [
|
|
ATAccurateLengthLimitingTextInputFormatter(
|
|
_roomAnnouncementMaxLength,
|
|
),
|
|
],
|
|
maxLines: 5,
|
|
decoration: InputDecoration(
|
|
hintText: "",
|
|
hintStyle: TextStyle(
|
|
color: Colors.black45,
|
|
fontSize: 14.sp,
|
|
),
|
|
contentPadding: EdgeInsets.only(top: 0.w),
|
|
counterText: '',
|
|
isDense: true,
|
|
filled: false,
|
|
focusColor: Colors.transparent,
|
|
hoverColor: Colors.transparent,
|
|
border: InputBorder.none,
|
|
enabledBorder: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
disabledBorder: InputBorder.none,
|
|
errorBorder: InputBorder.none,
|
|
focusedErrorBorder: InputBorder.none,
|
|
// enabledBorder: UnderlineInputBorder(
|
|
// borderSide: BorderSide(width: 0.5,color: Colors.white,style: BorderStyle.solid),),
|
|
// focusedBorder: UnderlineInputBorder(
|
|
// borderSide: BorderSide(width: 0.5,color: Colors.white,style: BorderStyle.solid),),
|
|
// prefixIcon: Padding(padding: EdgeInsets.all(8.w), child: Image.asset("images/login/at_icon_phone.png",width: 20.w, height: 20.w,fit: BoxFit.fill,),),
|
|
fillColor: Colors.black45,
|
|
suffix: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(width: 3.w),
|
|
text(
|
|
'$_roomAnnouncementCurrentLength/$_roomAnnouncementMaxLength',
|
|
textColor: Color(0xFF999999),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
style: TextStyle(
|
|
fontSize: sp(15),
|
|
color: Colors.black,
|
|
textBaseline: TextBaseline.alphabetic,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
widget.needRestCurrentRoomInfo != "true"
|
|
? Column(
|
|
children: [
|
|
SizedBox(height: 12.w),
|
|
ATDebounceWidget(
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 25.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.roomTheme2,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 15.sp,
|
|
),
|
|
Spacer(),
|
|
Icon(
|
|
Icons.keyboard_arrow_right,
|
|
color: Colors.black,
|
|
size: 20.w,
|
|
),
|
|
SizedBox(width: 25.w),
|
|
],
|
|
),
|
|
onTap: () {
|
|
ATNavigatorUtils.push(
|
|
context,
|
|
VoiceRoomRoute.roomTheme,
|
|
replace: false,
|
|
);
|
|
},
|
|
),
|
|
SizedBox(height: 12.w),
|
|
ATDebounceWidget(
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 25.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.roomPassword,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 15.sp,
|
|
),
|
|
Spacer(),
|
|
Consumer<RtcProvider>(
|
|
builder: (context, ref, child) {
|
|
return text(
|
|
ref
|
|
.currenRoom
|
|
?.roomProfile
|
|
?.roomSetting
|
|
?.password ??
|
|
"",
|
|
textColor: Color(0xffB1B1B1),
|
|
fontSize: 13.sp,
|
|
);
|
|
},
|
|
),
|
|
|
|
Icon(
|
|
Icons.keyboard_arrow_right,
|
|
color: Colors.black,
|
|
size: 20.w,
|
|
),
|
|
SizedBox(width: 25.w),
|
|
],
|
|
),
|
|
onTap: () {
|
|
_setPwd();
|
|
},
|
|
),
|
|
SizedBox(height: 12.w),
|
|
ATDebounceWidget(
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 25.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.micManagement,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 15.sp,
|
|
),
|
|
Spacer(),
|
|
Icon(
|
|
Icons.keyboard_arrow_right,
|
|
color: Colors.black,
|
|
size: 20.w,
|
|
),
|
|
SizedBox(width: 25.w),
|
|
],
|
|
),
|
|
onTap: () {
|
|
SmartDialog.show(
|
|
tag: "showRoomMicSwitch",
|
|
alignment: Alignment.bottomCenter,
|
|
animationType: SmartAnimationType.fade,
|
|
debounce: true,
|
|
builder: (_) {
|
|
return RoomMicSwitchPage();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
SizedBox(height: 12.w),
|
|
ATDebounceWidget(
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 25.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.blockedList2,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 15.sp,
|
|
),
|
|
Spacer(),
|
|
Icon(
|
|
Icons.keyboard_arrow_right,
|
|
color: Colors.black,
|
|
size: 20.w,
|
|
),
|
|
SizedBox(width: 25.w),
|
|
],
|
|
),
|
|
onTap: () {
|
|
showBottomInBottomDialog(
|
|
context,
|
|
BlockedListPage(
|
|
roomId:
|
|
Provider.of<RtcProvider>(
|
|
context!,
|
|
listen: false,
|
|
)
|
|
.currenRoom
|
|
?.roomProfile
|
|
?.roomProfile
|
|
?.id ??
|
|
"",
|
|
),
|
|
);
|
|
},
|
|
),
|
|
SizedBox(height: 12.w),
|
|
ATDebounceWidget(
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 25.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.roomMemberFee,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 15.sp,
|
|
),
|
|
Spacer(),
|
|
Consumer<RtcProvider>(
|
|
builder: (context, ref, child) {
|
|
return text(
|
|
"${ref.currenRoom?.roomProfile?.roomSetting?.joinGolds}",
|
|
textColor: Color(0xffB1B1B1),
|
|
fontSize: 13.sp,
|
|
);
|
|
},
|
|
),
|
|
Icon(
|
|
Icons.keyboard_arrow_right,
|
|
color: Colors.black,
|
|
size: 20.w,
|
|
),
|
|
SizedBox(width: 25.w),
|
|
],
|
|
),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
PopRoute(child: RoomMembershipFeePage()),
|
|
);
|
|
},
|
|
),
|
|
SizedBox(height: 15.w),
|
|
],
|
|
)
|
|
: Container(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
int _getActualCharacterCount(String text) {
|
|
return text.characters.length;
|
|
}
|
|
|
|
void submit(BuildContext context) async {
|
|
if (_roomNameController.text.trim().isEmpty) {
|
|
ATTts.show("Room name not empty!");
|
|
return;
|
|
}
|
|
if (_roomAnnouncementController.text.trim().isEmpty) {
|
|
ATTts.show("Room announcement not empty!");
|
|
return;
|
|
}
|
|
ATLoadingManager.exhibitOperation(context: context);
|
|
var roomInfo = await AccountRepository().editRoomInfo(
|
|
rtcProvider?.currenRoom?.roomProfile?.roomProfile?.id ?? "",
|
|
roomCover,
|
|
_roomNameController.text,
|
|
_roomAnnouncementController.text,
|
|
ATRoomInfoEventType.AVAILABLE.name,
|
|
);
|
|
Provider.of<ChatVibeRoomManager>(
|
|
context,
|
|
listen: false,
|
|
).updateMyRoomInfo(roomInfo);
|
|
if (widget.needRestCurrentRoomInfo == "true") {
|
|
///需要创建群组
|
|
var c = await Provider.of<RtmProvider>(
|
|
context,
|
|
listen: false,
|
|
).createRoomGroup(
|
|
rtcProvider?.currenRoom?.roomProfile?.roomProfile?.roomAccount ?? "",
|
|
rtcProvider?.currenRoom?.roomProfile?.roomProfile?.roomName ?? "",
|
|
);
|
|
if (c.code == 0) {
|
|
ATLoadingManager.veilRoutine();
|
|
ATNavigatorUtils.goBack(context);
|
|
Provider.of<RtcProvider>(
|
|
context,
|
|
listen: false,
|
|
).joinRoom(context, roomInfo.id ?? "", clearRoomData: true);
|
|
} else {
|
|
ATLoadingManager.veilRoutine();
|
|
ATTts.show("${c.code}");
|
|
}
|
|
} else {
|
|
Provider.of<RtcProvider>(
|
|
context,
|
|
listen: false,
|
|
).loadRoomInfo(roomInfo.id ?? "");
|
|
ATLoadingManager.veilRoutine();
|
|
ATNavigatorUtils.goBack(context);
|
|
}
|
|
}
|
|
|
|
void _setPwd() {
|
|
if (Provider.of<RtcProvider>(
|
|
context,
|
|
listen: false,
|
|
).currenRoom!.roomProfile!.roomSetting!.password !=
|
|
null &&
|
|
Provider.of<RtcProvider>(
|
|
context,
|
|
listen: false,
|
|
).currenRoom!.roomProfile!.roomSetting!.password!.isNotEmpty) {
|
|
SmartDialog.show(
|
|
tag: "showConfirmDialog",
|
|
alignment: Alignment.center,
|
|
debounce: true,
|
|
animationType: SmartAnimationType.fade,
|
|
builder: (_) {
|
|
return MsgDialog(
|
|
title: ATAppLocalizations.of(context)!.tips,
|
|
msg: ATAppLocalizations.of(context)!.cancelRoomPassword,
|
|
btnText: ATAppLocalizations.of(context)!.confirm,
|
|
onEnsure: () {
|
|
ChatRoomRepository()
|
|
.roomUnlocked(
|
|
Provider.of<RtcProvider>(
|
|
context,
|
|
listen: false,
|
|
).currenRoom?.roomProfile?.roomProfile?.id ??
|
|
"",
|
|
)
|
|
.whenComplete(() {
|
|
Provider.of<RtcProvider>(
|
|
navigatorKey.currentState!.context,
|
|
listen: false,
|
|
).loadRoomInfo(
|
|
Provider.of<RtcProvider>(
|
|
navigatorKey.currentState!.context,
|
|
listen: false,
|
|
).currenRoom?.roomProfile?.roomProfile?.id ??
|
|
"",
|
|
);
|
|
});
|
|
},
|
|
);
|
|
},
|
|
);
|
|
} else {
|
|
Navigator.push(context, PopRoute(child: SetRoomPwdPage()));
|
|
}
|
|
}
|
|
}
|