Flutter firebase realtime database getting user details from join request key

Viewed 41

I am new to flutter. Seeking help with flutter and firebase real-time database. In the first image of my 'request' child, I want to retrieve all requests to a list and display the user details from the 'users' child using that list.

[request child]

[users child]:

Currently, I am using a streambuilder to get the keys but I want to show the user details under the keys. What is the best way to do that?

[Current streambuilder]

Current code

StreamBuilder<dynamic>(
            stream: ref
                .child('house')
                .child(widget.house)
                .child('request')
                .child('joinReq')
                .orderByChild('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: [
                          Text(
                            nextJoinReq['id'],
                            style: const TextStyle(
                              fontWeight: FontWeight.w500,
                              fontSize: 12,
                              color: Colors.red,
                            ),
                          ),
                          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,
              );
            },
          )
0 Answers
Related