Search code examples
flutterfirebasegoogle-cloud-firestorefirebase-authenticationflutter-web

TypeError: Cannot read properties of undefined (reading 'init') || Flutter web


I have recently upgraded my flutter project from Flutter Beta to Flutter Stable 3.3.8. after upgrading, I also upgraded all the firebase packages to the latest version.

Due to this upgrade on my config function, there is a new parameter of navigatorKey. So I included that like this

class NavKey{
    static final navKey =  GlobalKey<NavigatorState>();
    }

static final Config config = Config(
  navigatorKey: NavKey.navKey,          //new parameter of navigatorKey
  tenant: "xx-3066-xx-xx-xx",
  clientId: "xx-ad66-xx-a6e6-xx",
  scope: "api://xx-xx-422a-a6e6-xx/xx",
  redirectUri:
      "xx://com.example.xx/xx%xx%3D");

Now If I run my project and enter my email id and hit enter it shows this error

TypeError: Cannot read properties of undefined (reading 'init')

on my void main() I have included all my Firebase initialize like this

Future<void> main() async {
  // await dotenv.load();
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
      options: const FirebaseOptions(
          apiKey: "xxx-xx",
          authDomain: "xx-xxx.firebaseapp.com",
          databaseURL: "https://xxx-xx-default-xxx.xx.com",
          projectId: "xxx-xxx",
          storageBucket: "xxx-xx.appspot.com",
          messagingSenderId: "xxx",
          appId: "1:xx:web:xxx3d75b63xxxxe9",
          measurementId: "G-xxxx")
          );

  
  runApp(const MyApp()
      /* MaterialApp(//
  home: MyApp())*/
      );
}

on my index.html I have also included this script as I am running my project on flutter web

<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-functions.js"></script>

These are my all errors

All errors


Solution

  • Well, I am not able to find the solution for the latest package. That's why I rolled back my aad_oauth from ^0.4.0 to ^0.3.0 where it doesn't asked for navigatorKey

    Config(
        navigatorKey: NavKey.navKey,)