我正在尝试编写一个使用 firestore 数据库作为持久层的控制台 Dart 应用程序,但是当我尝试运行基本示例时,firebase 抛出了这种内部库错误:
file:///home/alexandre/.pub-cache/hosted/pub.dartlang.org/firebase-5.0.2/lib/src/auth.dart:274:25: Error: The method 'allowInterop' isn't defined for the class '#lib1::Auth'.
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var nextWrapper = allowInterop((firebase_interop.UserJsImpl user) {
我的 pubspec.yaml 是:
name: flix_backend_dart
description: A sample command-line application.
# version: 1.0.0
# homepage: https://www.example.com
# author: alexandre <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e3b333f37321e3b263f332e323b703d3133" rel="noreferrer noopener nofollow">[email protected]</a>>
environment:
sdk: '>=2.1.0 <3.0.0'
#dependencies:
# path: ^1.4.1
dev_dependencies:
test: ^1.0.0
firebase: ^5.0.0
应用程序的片段是:
import 'package:firebase/firebase.dart';
import 'package:flix_backend_dart/domain/repository.dart';
import 'package:flix_backend_dart/network/load_movies.dart';
import 'package:flix_backend_dart/network/service.dart';
main(List<String> arguments) {
const _query = 'get:new21';
const _startYear = 1900;
const _endYear = 2019;
const _startNetflixRate = 0.0;
const _endNetflixRate = 5.0;
const _startImdbRate = 0.0;
const _endImdbRate = 10.0;
const _genreId = 0;
const _vtype = 'movie';
const _audio = 'Any';
const _subtitle = 'Any';
const _imdbVotes = 100;
const _downloadable = '';
final queryParameters = {
'q':
'${_query}-!${_startYear},${_endYear}-!${_startNetflixRate},${_endNetflixRate}-!${_startImdbRate},${_endImdbRate}-!${_genreId}-!${_vtype}-!${_audio}-!${_subtitle}-!${_imdbVotes}-!${_downloadable}',
't': 'ns',
'cl': '29',
'st': 'adv',
'ob': "Relevance",
'sa': 'and',
'p': '1'
};
var app = initializeApp(
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
authDomain: 'xxxxxxxxxxxxxxxxirebaseapp.com',
databaseURL: 'xxxxxxxxxxxxxxxxxxxxxx.firebaseio.com',
projectId: 'xxxxxxxxxx7012',
storageBucket: 'storageBucket',
messagingSenderId: 'xxxxxxxxxx18'
);
var ref = firestore(app).collection("movies");
ref.get().then((snapshot){
snapshot.forEach((doc){
var imdbid = doc.data()['imdbid'];
print("imdbid: $imdbid");
});
});
var r =
GetNewMoviesImpl.instance(FetchMovieServiceImpl(), FirebaseRepository());
r.execute(queryParameters).then((r) {
print(r);
});
}
我能够从控制台 kotlin 应用程序访问此数据库。我有什么错吗?
最佳答案
浏览器之外没有allowInterop
。此功能特别适用于 Dart-js-interop 调用。您使用的 firebase 库可能也只能在浏览器中使用。服务器/控制台仅支持 Firebase 管理 API。
https://github.com/fluttercommunity/firebase_flutter_sdk是一种纯 Dart 方法,应该在服务器上同样工作,但我不知道状态。
关于firebase - 未为该类定义方法 'allowInterop' ...尝试使用 Firestore 时出现 Dart 控制台应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54067013/