Hi everyone, I'm trying to make a chat between two user that concern a specific ads on my app.
when i click on tchat i have a flow with this function that check if the chat exist. if it exist it's supposed to update an appstate variable
then the flow had a conditionnal action that sais that if the app state varable is set, navigate to the chat
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
Future<void> checkIfChatExist(String adsReference, String userAOwner,
String userBAuthenticatedUser) async {
FirebaseFirestore firestore = FirebaseFirestore.instance;
String chatId = '$adsReference-$userAOwner-$userBAuthenticatedUser';
final QuerySnapshot chatReferenceSnapshot = await firestore
.collection('chats')
.where('joinedChatID', isEqualTo: chatId)
.limit(1)
.get();
// Vérification de la présence de documents dans le snapshot
if (chatReferenceSnapshot.docs.isNotEmpty) {
DocumentReference chatDocumentReference =
chatReferenceSnapshot.docs[0].reference;
FFAppState().chatreference = chatDocumentReference;
} else {}
;
}
---------------------------------------------------------------
if it doesn't exist it's create the chat document with a specific chat id that concatenate those 3 arguments :'$adsReference-$userAOwner-$userBAuthenticatedUser';
As of know nothing happened when i click my chat button, why? thanks
Custom function not working
2
2 replies