I am new to flutter and try to retrieve users' information inside a streambuilder which is returned by another streambuilder(Member requests). The problem is only one user data is loaded. How do retrieve all user data?
Though there are two children under 'request' in the database, only one is loading with details. How can I retrieve data from both users?
Database structure:
"-NB3mpmc1uVVriqpBUBs":{
"request": {
"joinReq": {
"-3DklBY2I29hvpHig8ep": {
"id": "00PFRnK8peS53NsogLKM8yzIT3T2"
},
"-NBY2I29hvpHig8epjZa": {
"id": "Xf8XFAMkt8aUUT094xozTUwWGmU2"
}
}
}
}
"users":{
"00PFRnK8peS53NsogLKM8yzIT3T2": {
"email": "anku.6200@gmail.com",
"password": "anku@6200",
"phone": "00PFRnK8peS53NsogLKM8yzIT3T2",
"username": "Abu Ziad"
},
"Xf8XFAMkt8aUUT094xozTUwWGmU2":{
"Phone": "Xf8XFAMkt8aUUT094xozTUwWGmU2",
"email": "redzvfx.official@gmail.com",
"password": "123456",
"username": "RedZApps"
}
My current code:
StreamBuilder<dynamic>(
stream: ref
.child('house')
.child(widget.house)
.child('request')
.child('joinReq')
.orderByChild('id')
.onValue,
builder: (context, snapshot1) {
var nextJoinReq;
final memRequests = Map<String, dynamic>.from(
(snapshot1.data!).snapshot.value);
memRequests.forEach((key, value) {
nextJoinReq = Map<String, dynamic>.from(value);
nextJoinReq['key'] = key;
print(nextJoinReq);
});
print(nextJoinReq);
//return _buildMemReqItem(memRequests: memRequests);
return StreamBuilder<dynamic>(
stream: ref
.child('users')
.orderByChild('phone')
.equalTo(nextJoinReq['id'])
.onValue,
builder: (context, snapshot) {
final tilesList = <Card>[];
if (snapshot.hasData) {
final joinReq = Map<String, dynamic>.from(
(snapshot.data!).snapshot.value);
joinReq.forEach((key, value) {
final nextJoinReq = Map<String, dynamic>.from(value);
nextJoinReq['key'] = key;
final joinTile = Card(
margin: const EdgeInsets.symmetric(
vertical: 5, horizontal: 7),
//elevation: 3,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
nextJoinReq['username'],
style: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 12,
color: Colors.red,
),
),
Text(
nextJoinReq['key'],
style: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 12,
color: Colors.blueAccent,
),
),
const Text(
'Email goes here',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 12,
color: Colors.blueAccent,
),
),
],
),
GestureDetector(
onTap: (() {
Alert(
context: context,
//closeIcon: const Icon(Icons.close),
//title: 'LOG OUT!',
//desc: 'Do you want to log out?',
//content: const CircularProgressIndicator(),
content: Row(
children: [
const Icon(Icons.clear, size: 40),
const SizedBox(
width: 10,
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
'Delete request!',
style: TextStyle(
fontSize: 20,
color: Colors.red,
),
),
SizedBox(
width: 160,
child: Text(
'Do you want to remove \' ${nextJoinReq['id']}s \' request to join?',
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 15,
color: Colors.black,
),
),
),
],
),
],
),
style: const AlertStyle(
backgroundColor: Colors.white,
isCloseButton: false,
// isOverlayTapDismiss: false,
),
buttons: [
DialogButton(
color: Colors.black,
onPressed: () {
Navigator.pop(context);
},
child: const Text(
'No',
style: TextStyle(
color: Colors.white),
),
),
DialogButton(
color: Colors.black,
onPressed: () {
Navigator.pop(context);
ref
.child('house')
.child(widget.house)
.child('request')
.child('joinReq')
.child(nextJoinReq['key'])
.remove()
.whenComplete(() => {
showSnackBar(context,
'Request deleted')
});
},
child: const Text(
'Yes',
style: TextStyle(
color: Colors.white),
),
),
],
).show();
}),
child: const Icon(
Icons.clear,
size: 25.0,
color: Colors.black,
),
),
],
),
),
);
tilesList.add(joinTile);
});
}
return ListView(
children: tilesList,
);
},
);
},
)
