"NoSuchMethodError:尝试调用非函数,例如null:'dart.global.firebase.auth'"在Flutter中为Web初始化auth()时 [英] "NoSuchMethodError: tried to call a non-function, such as null: 'dart.global.firebase.auth'" when initializing auth() in flutter for web

查看:41
本文介绍了"NoSuchMethodError:尝试调用非函数,例如null:'dart.global.firebase.auth'"在Flutter中为Web初始化auth()时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Flutter for Web应用程序中的Firebase身份验证来实现登录功能.我已经可以使用Firestore在同一应用中存储/提取数据,而无需登录.

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.

在执行应用程序时,它显示错误"NoSuchMethodError:尝试调用非函数,例如null:'dart.global.firebase.auth'"

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

我认为该错误是由调用 auth()方法引起的.

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

能否请您告诉我该如何解决?还是不支持Flutter for Web的Firebase身份验证??

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

导入的firebase.dart. https://firebase.google.com/docs/reference/js/firebase

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

import'package:firebase/firebase.dart';

使用auth()初始化对象,然后从参数中调用登录方法.

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;
}

推荐答案

您也需要在index.html文件中添加此内容:

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

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

这篇关于"NoSuchMethodError:尝试调用非函数,例如null:'dart.global.firebase.auth'"在Flutter中为Web初始化auth()时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆