How to give 1 firebase id to 2 users in flutter? - firebase

I'm trying to make chat app in flutter using firebase. And i want to know, can i make chat using users id? I mean chatID=user1ID+user2ID, is it possible?

I think you can add a field of type array to your chat document and name it as chat _user and just pass the two users ids to it as like this =>

Related

How to store additional data in Flutter and firebase Authentication method

Good Morning,
I have a simple query, I am using firebase Authentication as a sign-in/ signup method to my flutter app, what is the right method if I want to store additional data, such as name, age and etc...
If you look at the class User that is defined in User.dart for instance that ships with the Firebase SDK for Flutter, you'll see various properties of the User class, including but not limited to:
String? get displayName
String? get email
bool get emailVerified
bool get isAnonymous
UserMetadata get metadata
You might see the metadata property and think Aha! Maybe I can put my extra data there, but if you look at that class' properties and code you'll soon realize that it's not going to allow you to store additional properties in it either.
So the User in Firebase is not the right place to store additional information about that user itself! That's the take-away I want you to get from this answer.
The right way to go about doing this is to store your additional information per user inside your Firestore Database. Create a simple collection and name it something along the lines of UserInfo and in there per user-id, store the additional information that you need per user, and add a field to every object in that collection named user-id and store the user.id in that field. That way you can always do a look-up of user information per user.id.
As i understand your problem to store additional data of a user after login. For this you can use Firestore database and create collections for the fields like- name, age and etc...
https://pub.dev/packages/cloud_firestore
Have a look into this library.
https://medium.com/firebase-developers/cloud-firestore-basics-in-flutter-68c7ec42eeca
To understand firestore go through this article.

Flutter : open a chat room for 2 users based on condition

hello I am building a chat app with firebase , and I already know how to make the chat room and make users chat with each other .
in my app i have a Cupertino picker which have some values , what iam looking for is
1 - if 2 users have selected the same value a chat room document will be created and both of them will chat with each other , what are the possible solutions for that ? .
2 - notifications based on topic that are dynamic should be by using cloud functions and typescript with onCreate method right ?
1 - you could do something like creating an object like this
users_waiting_for_connection -> user_id, selected_value, creation_time, ...
So when a user pick a value you check for elements in the list for the same selected_value.. if found you create the room and delete the object from the list, if not found you create the element in the list
2 - yup, you can find any info in the documentation
https://firebase.flutter.dev/docs/functions/overview/

Flutter: How to send notifications to users when a document with specific field values is created. (how to subscribe to topic with condition)

I want to add a "Notify me" function in my flutter app where the user enters a date and other values so when a document is created with those values, the user can get a notification. I'm unable to add any conditions in fcm.subscribeToTopic();.TIA.
You can create a cloud function and deploy it to firebase Functions, and in that function specify the path of collection (in which your document is creating) and it will trigger when a new document is created (write function for that. example ). in order to send notifications to that user store that user's device Token. you can find cloud Firestore Functions here.
some articles that help: firebase tiggers
Subscriptions to a topic are unconditional. The simplest way I can think of to implement this use-case is to create topics that contain the specific conditions that you are interested in, like date_20210823_value_yourvalue.

How to set Firebase Custom DocID using Dart

I'm using Flutter/Dart in my app, I can register users with de next sentence
Firestore.instance.collection('users').add(toMap(user));
but Firebase, creates the document with an automatic id, I want to create the document with the username to perfom the queries based on the username. (Find the products using the username)
I tried set the id in the User DTO but Firebase save it with automatic id.
Use the user's id to create the document like this
Firestore.instance.collection('users').document(user.uid).setData(toMap(user));

Limit the retrieve of documents from Firebase on Flutter

I would like to learn how can I limit the retrieved document from Firestore quantity for each user. Is there any possible way to achieve this with shared preferences? Because I do not use a login or registration protocol for the user. I am using shared preferences in order to recognize the user.
Single user should retrieve only 1 document each day. This is what I want to implement.
Also I would like to learn that how can I save and show fetching date of the document?
You can do the following in Firebase:
Query query = cities.orderBy("name").limit(3); // descending order
Query query = cities.whereGreaterThan("population", 2500000L).orderBy("population").limit(2); // ascending order
You can take a look at the documentation, there are the corresponding methods.
https://firebase.google.com/docs/firestore/query-data/order-limit-data

Resources