“NoSuchMethodError: tried to call a non-function, such as null: 'dart.global.firebase.auth'” when initializing auth() in flutter for web

被刻印的时光 ゝ 提交于 2020-12-08 06:53:42

问题


I'm trying to implement sign-in function with Firebase Authentication in Flutter for Web app. I can already use Firestore to store/ extract data in the same app without signing-in.

When executing the app, it shows the error "NoSuchMethodError: tried to call a non-function, such as null: 'dart.global.firebase.auth'"

I think the error is caused by calling auth() method.

Can you please advise how I should fix it? Or, is Firebase Authentication not supported Flutter for web yet??

Imported firebase.dart. https://firebase.google.com/docs/reference/js/firebase

import 'package:firebase/firebase.dart';

Initialized an object with auth() and called sign-in method from the parameter.

final Auth _auth = auth();

Future<UserCredential> signIn(String email, String password) async {
  final UserCredential user = await _auth.signInAndRetrieveDataWithEmailAndPassword(email, password);
  return user;
}

回答1:


You need include this in your index.html file too:

<script src="https://www.gstatic.com/firebasejs/7.8.0/firebase-auth.js"></script>


来源:https://stackoverflow.com/questions/57114754/nosuchmethoderror-tried-to-call-a-non-function-such-as-null-dart-global-fir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!