Search code examples
flutterfirebasegoogle-cloud-firestoreflutter-web

New Firebase connection to Flutter application not connecting


I just created a new flutter application and trying to connect a newly made firebase Firestore. Cli has been added and flutterfire config has been ran.

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
   await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform
  );
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FutureBuilder(builder: ((context, snapshot) {
        if(snapshot.hasError){
          print('Error');
        }
        if(snapshot.connectionState == ConnectionState.done){
          return const MyHomePage(title: 'WOWZA',);
        }
        return CircularProgressIndicator();
      }
      )
      )
    );
  }
}

When breaking at the if(snapshot.connectionState == ConnectionState.done) is says connectionState is .none and unsure as to why.

Can anyone help?


Solution

  • missing future initialization -

    From:

    home: FutureBuilder(builder: ((context, snapshot) {
    
        if(snapshot.hasError){
          print('Error');
        }
        if(snapshot.connectionState == ConnectionState.done){
          return const MyHomePage();
        }
        return CircularProgressIndicator();
      }
      )
      )

    To:

    home: FutureBuilder(
            future: _initialization,
            builder: ((context, snapshot) {
            if(snapshot.hasError){
              print('Error');
            }
            if(snapshot.connectionState == ConnectionState.done){
              return const MyHomePage();
            }
            return CircularProgressIndicator();
          }
          )
          )