方法 'allowInterop' 没有为 class 定义...尝试使用 Firestore 时 Dart 控制台应用程序错误

The method 'allowInterop' isn't defined for the class ... Dart console App Error when trying to use Firestore

我正在尝试编写一个使用 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 <email@example.com>

environment:
  sdk: '>=2.1.0 <3.0.0'

#dependencies:
#  path: ^1.4.1

dev_dependencies:
  test: ^1.0.0
  firebase: ^5.0.0

来自 App 的代码段是:

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 库可能也只能在浏览器中使用。 server/console.

仅支持 Firebase 管理员 API

https://github.com/fluttercommunity/firebase_flutter_sdk 是一种纯 Dart 方法,在服务器上应该同样有效,但我不知道状态。

如果此应用仅适用于手机,请移除依赖

火力基地:^5.0.0

这仅适用于网络。