我如何阻止用户在flutter聊天应用程序[firebase]



大家好,我是新手我如何阻止用户在聊天应用程序使用扑动和firebase..功能是什么?

我不知道。

谢谢你的帮助。我将此代码用于阻止和取消阻止用户。它的工作原理。

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
class Chat with ChangeNotifier {
// Block a user
void blockUser({String blockedUserId, String currentUserId}) async {
await FirebaseFirestore.instance
.collection('blockedUsers')
.doc(currentUserId)
.collection('list')
.doc(blockedUserId)
.set({'blockedUserId': blockedUserId}).then((_) async {
Fluttertoast.showToast(
msg: 'Kullancıyı engellediniz..',
fontSize: 18,
);

notifyListeners();
});
;
}

// Check if a user is blocked
Future<bool> isUserBlocked({String blockedUserId, String currentUserId}) {
// Return true if the blocked user ID is present in the current user's "blockedUsers" collection
// You can use this function to disable chat functionality for blocked users
return FirebaseFirestore.instance
.collection('blockedUsers')
.doc(currentUserId)
.collection('list')
.doc(blockedUserId)
.get()
.then((value) => value.exists);
}

// Unblock a user
void unblockUser({String blockedUserId, String currentUserId}) async {
await FirebaseFirestore.instance
.collection('blockedUsers')
.doc(currentUserId)
.collection('list')
.doc(blockedUserId)
.delete()
.then((_) async {
Fluttertoast.showToast(
msg: 'Engellemeyi Kaldırdınız',
fontSize: 18,
);

notifyListeners();
});
}

相关内容

最新更新