Flutter高仿微信系列共59篇,从Flutter客户端、Kotlin客户端、Web服务器、数据库表结构、Xmpp即时通讯服务器、视频通话服务器、腾讯云服务器全面讲解。
效果图:
实现代码:
//修改群名 void _updateGroupName(){ bool isOwner = false; for(int i = 0; i< _groupUserList.length; i++){ GroupUserBean groupUserBean = _groupUserList[i]; if(account == groupUserBean.account && (groupUserBean.accountType == GroupUserBean.ACCOUNT_TYPE_OWNER|| groupUserBean.accountType == GroupUserBean.ACCOUNT_TYPE_ADMIN)){ isOwner = true; break; } } if(isOwner){ Navigator.push(context, MaterialPageRoute(builder: (context) => GroupUpdateName(groupId: widget.groupId))); } else { LoadingDialogUtils.showTipDialog(context, msg : "当前群聊仅群主/群管理员可以修改群聊名称"); } }
/** * Author : wangning * Email : maoning20080809@163.com * Date : 2022/11/15 14:13 * Description : 修改群名 */ class GroupUpdateName extends StatefulWidget { String groupId; GroupUpdateName({required this.groupId}); @override _GroupUpdateNameState createState() => _GroupUpdateNameState(); } class _GroupUpdateNameState extends State{ TextEditingController? _groupNameController; //修改群名 void _processUpdateName(String groupName) async { bool isNetwork = await CommonNetwork.isNetwork(); if(!isNetwork) { CommonUtils.showNetworkError(context); return; } if(_groupBean!= null){ _groupBean?.groupName = groupName; bool isSuccess = await GroupRepository.getInstance().updateGroupServer(_groupBean!); if(isSuccess){ CommonToast.show(context, "修改成功!"); GroupRepository.getInstance().updateGroup(_groupBean!); eventBus.emit(BaseEvent(BaseEvent.TYPE_REFRESH_GROUP, result: HashMap ())); Navigator.pop(context); } else { CommonToast.show(context, "修改失败!"); } } } GroupBean? _groupBean; //初始化群名 void _initGroup() async{ _groupBean = await GroupRepository.getInstance().findGroupByGroupId(widget.groupId); _groupNameController = TextEditingController(text: "${_groupBean?.groupName}"); setState(() { }); } @override void initState() { super.initState(); _initGroup(); } @override Widget build(BuildContext context) { return Scaffold( appBar: WnAppBar.getAppBar(context, Text("修改群名")), body: Container( height: 200, child: Column( children: [ SizedBox(height: 30,), Expanded( child: Container( margin: EdgeInsets.only(left: 12, right: 12), width: double.infinity, child: Row( children: [ Text("群名:"), Expanded( child:customTextField(defaultValue: '${_groupBean?.groupName}',textEditController: _groupNameController,), ), ], ), ) ), SizedBox(height: 30,), Container( alignment: AlignmentDirectional.center, child: _updateNameWidget(), ), ], ), ), ); } Widget customTextField({ TextEditingController? textEditController, String? hintText, String? defaultValue, }) { return TextField( controller: textEditController, cursorColor: Colors.black, decoration: InputDecoration( //labelText: defaultValue, //hintText: hintText, hintStyle: TextStyle( fontSize: 16, color: Colors.grey.withOpacity(0.8), ), focusedBorder: OutlineInputBorder( borderSide: const BorderSide(color: Colors.black), borderRadius: BorderRadius.circular(5.0), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(5.0), borderSide: BorderSide( color: Colors.grey, ), ), ), style: TextStyle( fontSize: 16, color: Colors.black, fontWeight: FontWeight.w500, ), ); } Widget _updateNameWidget() { return MaterialButton( color: Colors.blue, textColor: Colors.white, padding: EdgeInsets.only(left: 28, top: 8, right: 28, bottom: 8), child: Text('修改', style: TextStyle(fontSize: 16),), onPressed: () { var nickName = _groupNameController?.text??""; _processUpdateName(nickName); }, ); } }