Getting Error screen while data loading Flutter/Dart/FireBase


I have 3 dart files in my page . I have 2 page.
When i get data from firebase for second page , im getting a error screen for a second than my data loading. I checked error message it says my data null.
I tried Circular progress indicator like this

return StreamBuilder(
    stream: Firestore.instance.collection(UserInformation).document(user.uid).snapshots(),
    builder: (context, snapshot) {
    //==========show progress============
     if (!snapshot.hasData) {
        return CircularProgressIndicator()            
      var userDocument =;
      // User userDocument here ..........

but it didn’t work.

This is the area which i get my data from firebase;

class GuessPage extends StatefulWidget {
  late String topicname;
  GuessPage({required this.topicname});
  setType(String topic) {
    var questionsOf;
    CollectionReference questionsRef =  FirebaseFirestore.instance.collection('questionSports');
    if (topic=='Sports'){
       questionsOf =  questionsRef.doc('questionS');
    }else if(topic=='Magazine'){
       questionsOf =  questionsRef.doc('questionM');
    return questionsOf;

  State<GuessPage> createState() => _GuessPageState();

and this is my main dart file which i initialize my firebase

void main() async {
  await Firebase.initializeApp();

class MyApp extends StatelessWidget {
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData.dark(),
        home: FutureBuilder(
            future: _initialization,
            builder: (context, snapshot) {
              if (snapshot.hasError) {
                return Center(
                  child: Text('Unexpected Error'),
              } else if (snapshot.hasData) {
                return InputPage();
              } else {
                return Center(
                  child: CircularProgressIndicator(),


I guess you’re using an old version of the Firestore package.

Get the latest version of Firestore from, right here:

And then check usage of the package from here:

Answered By – Sreelal TS

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *