Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve information specifically for the present user using Flutter and Firestore, you can follow these steps:

  1. First, you need to get the current user's unique identifier. You can use Firebase Auth to get this identifier.
import 'package:firebase_auth/firebase_auth.dart';
FirebaseUser user = await FirebaseAuth.instance.currentUser();
String uid = user.uid;
  1. Then, you can use Firestore to query for documents that match the user's unique identifier.
import 'package:cloud_firestore/cloud_firestore.dart';
QuerySnapshot snapshot = await Firestore.instance.collection('users').where('uid', isEqualTo: uid).getDocuments();
  1. Finally, you can extract the data from the document using the data property.
Map<String, dynamic> userData = snapshot.documents[0].data;

Note: You need to make sure that you have set up the Firestore rules to only allow the current user to access their own data.