0

The code below is what I am trying now. The page works does everything I need but now I need this database reference to use the loanuid, clientuid, and companyName to get to the right directory.

 StreamBuilder<QuerySnapshot>(
        stream: FirebaseFirestore.instance
            .collection('prosperitybank')
            .doc('OHViYK8Zz6XfKGJsSXRL')
            .collection('Project Information')
            .snapshots()```

I need it from my collection.(userCreationRef).doc(loggedinuid) as shown in the picture. I can not figure out how to do this without the stream builders interfering any help would be greatly appreciated. I have tried to using this to help but it did not How can you nest StreamBuilders in Flutter?. I also tried looking at the documentation here https://firebase.flutter.dev/docs/firestore/usage/. Picture of Document I need data fields from

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:photoloanupdated/screens/mains/viewproperties.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    final FirebaseAuth auth = FirebaseAuth.instance;
    final user = auth.currentUser;
    final uid = user?.uid;
    var users = FirebaseFirestore.instance.collection('userCreationRequests');

    var companyname = "";
   
    return Scaffold(
      appBar: AppBar(
        title: Text(companyname),
      ),
      
      body:
        FutureBuilder<DocumentSnapshot>(
      future: users.doc(uid).get(),
      builder:
          (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
        if (snapshot.hasError) {
          return Text("Something went wrong");
        }

        if (snapshot.hasData && !snapshot.data!.exists) {
          return Text("Document does not exist");
        }

        if (snapshot.connectionState == ConnectionState.done) {
          Map<String, dynamic> data =
              snapshot.data!.data() as Map<String, dynamic>;
          return Text("Full Name: ${data['companyName']} ${data['last_name']}");
        }

        return Text("loading");
      },
    );
       StreamBuilder<QuerySnapshot>(
        stream: FirebaseFirestore.instance
            .collection('prosperitybank')
            .doc('OHViYK8Zz6XfKGJsSXRL')
            .collection('Project Information')
            .snapshots(), //key spot fV or email fix
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
              itemCount: snapshot.data?.docs.length,
              itemBuilder: (BuildContext context, int index) {
                QueryDocumentSnapshot<Object?>? documentSnapshot =
                    snapshot.data?.docs[index];
                //for date/time   DateTime mydateTime = documentSnapshot['created'].toDate();
                return InkWell(
                  onTap: () {
                    Navigator.of(context)
                        .push(
                      MaterialPageRoute(
                          builder: (context) => ViewProperties(documentSnapshot,
                              snapshot.data?.docs[index].reference)),
                    )
                        .then((value) {
                      setState(() {});
                    });
                  },
                  child: Card(
                    child: Container(
                      child: Padding(
                        padding: const EdgeInsets.all(15.0),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              "${documentSnapshot!['address']}",
                              style: TextStyle(
                                  fontSize: 24.0,
                                  fontFamily: "lato",
                                  fontWeight: FontWeight.bold,
                                  color: Colors.black),
                            ),
                            Container(
                              alignment: Alignment.centerRight,
                              child: Text(
                                "${documentSnapshot!['projectcomplete'].toString() + "% Complete"}",
                                // for  mydateTime.toString(),
                                style: TextStyle(
                                    fontSize: 17.0,
                                    fontFamily: "lato",
                                    color: Colors.black87),
                              ),
                            )
                          ],
                        ),
                      ),
                    ),
                  ),
                );
              },
            );
          } else {
            return Center(
              child: Text("Loading..."),
            );
          }
        },
      ),
    );
  }
}

1 Answers1

0
  String uuid;
  Future<List<Map<String, dynamic>>> _onQuery() {
    Future<List<Map<String, dynamic>>> res;
    if (uuid != null) {
      res = future.get().then((v) => v.docs
          .map((e) => e.data())
          .where((e) =>
              e['uuid'].toLowerCase().contains(uuid))
          .toList());
    } else {
      res = future.get().then((v) => v.docs.map((e) => e.data()).toList());
    }
    setState(() {});
    return res;
  }
  

now you can use _onQuery as stream.

Lou
  • 73
  • 1
  • 8