抱歉,这里有新手问题。这是我的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');
}
}
}
我正在尝试通过调用
将用户名和用户ID提交到firestorefbService.submitName(id, name);
但是我收到了这个错误
error submitting: NoSuchMethodError: method not found: 'call$1' (id.call$1 is not a function)
我不知道我的代码有什么问题。我试过寻找一些angulardart firestore教程,但没有运气。我使用的是dart-sdk 1.24.3,angular 4.0.0 + 2和firebase 4.4.0
我已尝试使用基于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>
和这个
<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>
但仍然有同样的错误
答案 0 :(得分:0)
您似乎缺少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>
Dart Firebase软件包只是JS实现的一个包装器,因此需要在从Dart中使用之前加载它。