What I want to do is to retrieve data from Cloud Firestore just for user Logged into the app. I am using Auth Firebase and I built a method to retrieve some documents from a specific collection called "user" and it works and it show the right Name of the user logged and the user signed up into my form. Now I am collecting with another form another Firestore collection called "shippingAddress" and the documents into the "shippingAddress" collection should be show into the app just for the specific user logged into the app. but this is not happen, any user logged I got the same data from all user except name and email address. this is my code:
final databaseReference = Firestore.instance;
Future<QuerySnapshot> getData() async {
var firebaseUser = await FirebaseAuth.instance.currentUser();
return await Firestore.instance
.collection("user")
.where("email", isEqualTo: firebaseUser.email)
.getDocuments();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: getData(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
return Column(
children: <Widget>[
Stream(),
],
);
});
} else if (snapshot.data == null) {
return Center(child: CircularProgressIndicator());
}
return Center(child: CircularProgressIndicator());
},
);
}
}
class Stream extends StatefulWidget {
@override
_StreamState createState() => _StreamState();
}
class _StreamState extends State<Stream> {
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: Firestore.instance.collection('shippingAddress').snapshots(),
builder: (context, snapshot) {
// if (!snapshot.hasData) return Text('Loading data please Wait');
return Column(
children: <Widget>[
Container(
height: 1000,
child: ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
return Card(
color: Color(0xFF1f2032),
elevation: 15,
child: Container(
width: 60,
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text(
snapshot.data.documents[index]['alias'],
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
],
),
),
);
},
),
),
],
);
},
);
}
}
please help I am stuck into this.
here is the screenshot of my database:
stream: Firestore.instance.collection('shippingAddress').snapshots()
. You'll need to write a query that selects only the shipping addresses for the current user. If that is giving you problems, edit your question to include a screenshot of ashippingAddress
document. - Frank van Puffelenvar user = await FirebaseAuth.instance.currentUser(); Firestore.instance.collection('shippingAddress').document(user.uid).snapshots()
- Frank van Puffelen