Flutter高仿微信系列共59篇,从Flutter客户端、Kotlin客户端、Web服务器、数据库表结构、Xmpp即时通讯服务器、视频通话服务器、腾讯云服务器全面讲解。

 详情请查看

效果图:

实现代码:

//删除对话框(单聊、群聊)
Future<void> _showDeleteDialog(ChatTempBean chatTempBean) async {
  String title = "确定要删除该消息吗?";
  if(chatTempBean.chatType == ChatTempBean.TYPE_GROUP_CHAT){
    title = "确定要清空该群的消息吗?";
  }
  return showDialog<Null>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text(title, style: new TextStyle(fontSize: 17.0)),
          actions: <Widget>[
            MaterialButton(
              child: Text('取消'),
              onPressed: (){
                Navigator.of(context).pop();
              },
            ),
            MaterialButton(
              child: Text('确定'),
              onPressed: (){
                Navigator.pop(context);
                if(chatTempBean.chatType == ChatTempBean.TYPE_GROUP_CHAT){
                  //删除群聊
                  _deleteGroupChatByGroupId(chatTempBean.account);
                } else {
                  //删除单聊
                  _deleteChatByFromToAccount(chatTempBean);
                }
              },
            )
          ],
        );
      }
  );
}

//删除单聊信息
_deleteChatByFromToAccount(ChatTempBean chatTempBean) async{
  String fromAccount = chatTempBean.account;
  String toAccount = SpUtils.getString(CommonUtils.LOGIN_ACCOUNT);

  //根据账号信息全部删除记录
  await ChatRepository.getInstance().deleteChatByFromToAccount(fromAccount, toAccount);
  CommonToast.show(context, "删除成功!");
  eventBus.emit(BaseEvent(BaseEvent.TYPE_UPDATE_CHAT_STATUS, result: HashMap<String, Object>()));
  //删除完成重新加载
  _getData();
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐