简体   繁体   English

angulardart firestore引发错误“ firebase.firestore不是函数”

[英]angulardart firestore throw error “firebase.firestore is not a function”

Sorry, newbie question here. 抱歉,新手问题在这里。 Here is my firebase_service.dart 这是我的firebase_service.dart

import 'package:firebase/firebase.dart' as fb;
import 'package:firebase/firestore.dart' as fs;
import 'dart:async';
import 'package:angular/angular.dart';

@Injectable()
class FirebaseService {
  fb.User user;
  fs.DocumentReference reference;

  FirebaseService() {
    fb.initializeApp(
        apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        authDomain: "xxxxxx.firebaseapp.com",
        databaseURL: "https://xxxxxx.firebaseio.com",
        projectId: "xxxxxxx",
        storageBucket: "xxxxxxxxxxxx.appspot.com",
        messagingSenderId: "xxxxxxxxxx"
    );

    fb.auth().onAuthStateChanged.listen(_authChanged);
  }

    void _authChanged(fb.User event) => user = event;

  Future signIn() async {
    try {
      await fb.auth().signInWithPopup(new fb.GoogleAuthProvider());
    }
    catch (e) {
      print("$runtimeType::login() -- $e");
    }
  }

  void signOut() => fb.auth().signOut();

  Future submitName(id, name) async {
    reference = fb.firestore().doc('userdata/$id');
    try {
        await reference.set(id(name));
      } catch (e) {
        print('error submitting: $e');
      }
  }
}

I am trying to submit user name and user id to firestore by calling 我正在尝试通过调用将用户名和用户ID提交到Firestore

fbService.submitName(id, name);

but I got this error 但是我得到这个错误

error submitting: NoSuchMethodError: method not found: 'call$1' (id.call$1 is not a function)

I don't know whats wrong with my code. 我不知道我的代码有什么问题。 I have tried looking for some angulardart firestore tutorial but got no luck. 我曾尝试寻找一些angulardart firestore教程,但没有运气。 I am using dart-sdk 1.24.3, angular 4.0.0+2 and firebase 4.4.0 我正在使用dart-sdk 1.24.3,angular 4.0.0 + 2和firebase 4.4.0

I have tried using this based on pub website 我已经尝试过根据酒吧网站使用它

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

and this 和这个

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

but still got the same error 但仍然有相同的错误

Looks like you are missing one or both of the following script tags in index.html 看起来您在index.html中缺少以下一个或两个脚本标记

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

The Dart Firebase package is just a wrapper over the JS implementation and therefore this needs to be loaded before it can be used from Dart. Dart Firebase包只是JS实现的包装,因此需要先加载此文件,然后才能从Dart使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM