1

I have a landing page and a collection in firestore that i save some information about a user in (e.g if he passed the On Boarding Screen or not). The next time i open the app, i want to check if the user passed the onboarding. If they did: I redirect to another screen; if not, then redirect to onboarding.

All the examples are reading a collection and get all documents, but i need to read only one document which i know the documentid .

i have tried to get the data like this, but did not work.

class LandingPage extends StatelessWidget { // LandingPage({@required this.auth}); // final AuthBase auth; @override Widget build(BuildContext context) { final auth = Provider.of<AuthBase>(context, listen: false); return StreamBuilder<User>( stream: auth.onAuthStateChanged, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.active) { User user = snapshot.data; if (user == null) { return ChooseLanguage( // auth: auth, ); } // he i need to do a call to a ducment in the firestore //if the retuen is true then i go to page 1 else go to page 2 } else { return Scaffold( body: Center(child: CircularProgressIndicator()), ); } }, ); } } 

do i have to do -iama beginner in flutter

0

1 Answer 1

2

To get one document do the following:

getData()async{ await Firestore.instance.collection("users").document(id).get().then((value){ print(value.data['name']); }); } 

You need to use the correct collection name, value.data will contain the data of that document which you can access using the [] operator.


According to your edit, you are checking if checkonboarding() is null, but since it returns a future you need to use await:

 void sendData()async{ bool value = await checkonBoarding(user); if (value != null) { return Provider<Database>( create: (_) => new FireStoreDatabase(uid: user.uid), child: Dashboard(usr: user, auth: auth), ); } else { return Provider<Database>( create: (_) => new FireStoreDatabase(uid: user.uid), child: Onboarding(usr: user, auth: auth), ); } } 
Sign up to request clarification or add additional context in comments.

7 Comments

bool checkonBoarding(User user) { bool x = false; Firestore.instance .collection("users") .document(user.uid) .get() .then((value) { if (value.data['onboarding']) { user.onBoardingValue = value.data['onBoardingvalue']; x = true; } else { x = false; } }); return x; } thi sisithe code i use , its reaches " .then((value) {' the jumbs to return x and iam sure that there os data
i want to put the code in a function that return bool but it is not working " if (checkonBoarding(user) == true)" its gives me :"Equality operator == invocation with references of unrelated types."
but what is this problem and how can i solve it if u know
if you are using async then it will return a Future, so you should do getData.then((val){if(!val){...});
@ peter i have edited the question will full code can u check it
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.