0

I was learning flutter from the book flutter projects by simone(published at packt).

and I found this code which is a little bit different from the book as some of the keywords are changed now(I guess).

Future testData() async {

  print('here'); // I can see this in debug

  FirebaseFirestore db = FirebaseFirestore.instance; // book says Firestore instead of FirebaseFirestore

  print('now here'); // but I can't see this , So, I think there is some issue with above lines.

  var data = await db.collection('event_details').get(); // it has getDocuments()

  var details = data.docs.toList(); //it has documents instead of docs

  details.forEach((d) {
    print(d.id); // it has documentID rather than just id

  });

}

The output should be the Id which looks something like this 'nasfs3rasfsd...'

please help where I am going wrong. and thanks for the help!! ^^

An Android
  • 149
  • 1
  • 6
  • 1
    Can you check the debug console? Are there any erros? – Andrej Mar 07 '21 at 07:34
  • No, actually it has to print the Id or say document id which was auto selected on the firebase web site, do you get it, (and yes it prints blank line instead of that id and it doesn't even print the line 'now here'). Do you need screenshots or anything thing as such? – An Android Mar 07 '21 at 12:05

1 Answers1

0

Finally I figured it out how to fix, and this is a similar question to an already answered question on Stackoverflow, if you are facing the same issue and haven't got any solutions yet then this will help you for sure, atleast it helped me.

just import firebase core library and then add this lines in void main.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase

here you can find more details regarding the issue I faced.

hope this helps will you!!

An Android
  • 149
  • 1
  • 6