当我为flutter web添加firebase时,我的应用程序将无法运行
Posted
技术标签:
【中文标题】当我为flutter web添加firebase时,我的应用程序将无法运行【英文标题】:When I add firebase for flutter web My App will not run 【发布时间】:2020-06-19 17:04:50 【问题描述】:我的应用程序运行顺利。当我添加 firebase: ^7.2.1 以支持 Flutter Web 时。为 Web 构建工作正常,但为 android 构建总是失败。
我的依赖。
flutter_timer: ^0.0.6
http: any
intl: ^0.16.1
firebase: ^7.2.1 ```
---------------------------
These are Console message:
Launching lib/main.dart on SM G920L in debug mode...
Running Gradle task 'assembleDebug'...
Invalid depfile: /Users/mac/Developer/Flutter/FlutterProjects/podio/.dart_tool/flutter_build/c4534ac7f6d60d954ed69c0226286dfd/kernel_snapshot.d
Invalid depfile: /Users/mac/Developer/Flutter/FlutterProjects/podio/.dart_tool/flutter_build/c4534ac7f6d60d954ed69c0226286dfd/kernel_snapshot.d
Compiler message:
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/top_level.dart:1:8: Error: Not found: 'dart:html'
import 'dart:html';
^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.1+1/lib/js.dart:8:1: Error: Not found: 'dart:js'
export 'dart:js' show allowInterop, allowInteropCaptureThis;
^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.1+1/lib/js_util.dart:8:1: Error: Not found: 'dart:js_util'
export 'dart:js_util';
^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/auth.dart:306:25: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
- 'Auth' is from 'package:firebase/src/auth.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var nextWrapper = allowInterop((firebase_interop.UserJsImpl user)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/auth.dart:310:26: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
- 'Auth' is from 'package:firebase/src/auth.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var errorWrapper = allowInterop((e) => _changeController.addError(e));
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/auth.dart:340:25: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
- 'Auth' is from 'package:firebase/src/auth.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var nextWrapper = allowInterop((firebase_interop.UserJsImpl user)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/auth.dart:345:11: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
- 'Auth' is from 'package:firebase/src/auth.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((e) => _idTokenChangedController.addError(e));
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart:164:9: Error: The method 'allowInterop' isn't defined for the class 'DatabaseReference<T>'.
- 'DatabaseReference' is from 'package:firebase/src/database.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((update) => jsify(transactionUpdate(dartify(update))));
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart:166:26: Error: The method 'allowInterop' isn't defined for the class 'DatabaseReference<T>'.
- 'DatabaseReference' is from 'package:firebase/src/database.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var onCompleteWrap = allowInterop(
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart:301:24: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
- 'Query' is from 'package:firebase/src/database.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var callbackWrap = allowInterop((database_interop.DataSnapshotJsImpl data,
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart:325:30: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
- 'Query' is from 'package:firebase/src/database.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
jsObject.once(eventType, allowInterop(
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart:402:22: Error: The method 'allowInterop' isn't defined for the class 'DataSnapshot'.
- 'DataSnapshot' is from 'package:firebase/src/database.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var actionWrap = allowInterop((d) => action(DataSnapshot.getInstance(d)));
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart:72:27: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
- 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final nextWrapper = allowInterop((payload)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart:75:28: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
- 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final errorWrapper = allowInterop((e)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart:87:27: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
- 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final nextWrapper = allowInterop((payload)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart:97:27: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
- 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final nextWrapper = allowInterop((_) => null);
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart:98:28: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
- 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
final errorWrapper = allowInterop((e)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/storage.dart:317:11: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
- 'UploadTask' is from 'package:firebase/src/storage.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((storage_interop.UploadTaskSnapshotJsImpl data)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/storage.dart:321:26: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
- 'UploadTask' is from 'package:firebase/src/storage.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var errorWrapper = allowInterop((e) => _changeController.addError(e));
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/storage.dart:322:26: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
- 'UploadTask' is from 'package:firebase/src/storage.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var onCompletion = allowInterop(() => _changeController.close());
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/top_level.dart:194:7: Error: Method not found: 'hasProperty'.
if (js.hasProperty(error, 'message'))
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/top_level.dart:195:19: Error: Method not found: 'getProperty'.
var message = js.getProperty(error, 'message');
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:29:7: Error: Method not found: 'hasProperty'.
if (util.hasProperty(jsObject, 'firestore') &&
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:30:7: Error: Method not found: 'hasProperty'.
util.hasProperty(jsObject, 'id') &&
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:31:7: Error: Method not found: 'hasProperty'.
util.hasProperty(jsObject, 'parent'))
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:37:7: Error: Method not found: 'hasProperty'.
if (util.hasProperty(jsObject, 'latitude') &&
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:38:7: Error: Method not found: 'hasProperty'.
util.hasProperty(jsObject, 'longitude') &&
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:44:15: Error: Method not found: 'getProperty'.
var proto = util.getProperty(jsObject, '__proto__');
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:46:7: Error: Method not found: 'hasProperty'.
if (util.hasProperty(proto, 'toDate') &&
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:47:7: Error: Method not found: 'hasProperty'.
util.hasProperty(proto, 'toMillis'))
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:52:7: Error: Method not found: 'hasProperty'.
if (util.hasProperty(proto, 'isEqual') &&
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:53:7: Error: Method not found: 'hasProperty'.
util.hasProperty(proto, 'toBase64'))
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:67:24: Error: Method not found: 'getProperty'.
map[key] = dartify(util.getProperty(jsObject, key));
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:91:17: Error: Method not found: 'newObject'.
var jsMap = util.newObject();
^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:93:7: Error: Method not found: 'setProperty'.
util.setProperty(jsMap, key, jsify(value));
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:116:12: Error: Method not found: 'allowInterop'.
return allowInterop(dartObject);
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:124:5: Error: Method not found: 'callMethod'.
util.callMethod(jsObject, method, args);
^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:139:19: Error: Method not found: 'promiseToFuture'.
value = await util.promiseToFuture(thenable);
^^^^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:141:9: Error: Method not found: 'hasProperty'.
if (util.hasProperty(e, 'code'))
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:152:27: Error: Method not found: 'allowInterop'.
return PromiseJsImpl<S>(allowInterop((
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:165:5: Error: Method not found: 'allowInterop'.
allowInterop(c.completeError);
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:173:22: Error: Method not found: 'getProperty'.
String get code => util.getProperty(_source, 'code');
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:176:25: Error: Method not found: 'getProperty'.
String get message => util.getProperty(_source, 'message');
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:179:22: Error: Method not found: 'getProperty'.
String get name => util.getProperty(_source, 'name');
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:182:32: Error: Method not found: 'getProperty'.
Object get serverResponse => util.getProperty(_source, 'serverResponse');
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/utils.dart:185:23: Error: Method not found: 'getProperty'.
String get stack => util.getProperty(_source, 'stack');
^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart:105:30: Error: The method 'allowInterop' isn't defined for the class 'Firestore'.
- 'Firestore' is from 'package:firebase/src/firestore.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var updateFunctionWrap = allowInterop((transaction) =>
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart:306:11: Error: The method 'allowInterop' isn't defined for the class 'DocumentReference'.
- 'DocumentReference' is from 'package:firebase/src/firestore.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((firestore_interop.DocumentSnapshotJsImpl snapshot)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart:310:26: Error: The method 'allowInterop' isn't defined for the class 'DocumentReference'.
- 'DocumentReference' is from 'package:firebase/src/firestore.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var errorWrapper = allowInterop((e) => controller.addError(e));
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart:445:9: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
- 'Query' is from 'package:firebase/src/firestore.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((firestore_interop.QuerySnapshotJsImpl snapshot)
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart:449:24: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
- 'Query' is from 'package:firebase/src/firestore.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
var errorWrapper = allowInterop((e) => controller.addError(e));
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart:775:9: Error: The method 'allowInterop' isn't defined for the class 'QuerySnapshot'.
- 'QuerySnapshot' is from 'package:firebase/src/firestore.dart' ('../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
allowInterop((s) => callback(DocumentSnapshot.getInstance(s)));
^^^^^^^^^^^^
../../SDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.2.1/lib/src/interop/js_interop.dart:17:7: Error: Method not found: 'hasProperty'.
if (util.hasProperty(jsObject, 'toDateString'))
^^^^^^^^^^^
../../SDK/flutter/packages/flutter/lib/src/painting/_network_image_web.dart:64:12: Error: Method not found: 'webOnlyInstantiateImageCodecFromUrl'.
return ui.webOnlyInstantiateImageCodecFromUrl(resolved) as Future<ui.Codec>; // ignore: undefined_function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ahtml; message=StandardFileSystem only supports file:* and data:* URIs)
#0 StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1 asFileUri (package:vm/kernel_front_end.dart:604:37)
#2 writeDepfile (package:vm/kernel_front_end.dart:799:21)
<asynchronous suspension>
#3 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:474:15)
<asynchronous suspension>
#4 _FlutterFrontendCompiler.compile (package:flutter_frontend_server/server.dart:38:22)
#5 starter (package:flutter_frontend_server/server.dart:149:27)
#6 main (file:///b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:8:30)
#7 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#8 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
* Where:
Script '/Users/mac/Developer/Flutter/SDK/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 801
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/mac/Developer/Flutter/SDK/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 32s
Finished with error: Gradle task assembleDebug failed with exit code 1
当我在 Flutter 中添加 web 之前运行代码时。它在 Android 中运行良好。但是当我在颤动中添加了 web 的 firebase 时。 它停止在 Android 上运行,但在 Web 上运行良好。
【问题讨论】:
请在此处也发布您的flutter doctor
回复...
这个问题已经有将近 2 个月了……还没有找到解决办法……
【参考方案1】:
我发现@davidmcharo 的回答非常有帮助,但想提供更新。
1) Firebase 有一些包可以从一个代码库同时用于移动和网络,但实时数据库不是一个。 (正如@Dazza5000 所说。)我建议改用 cloud_firestore。
2) 现在这些软件包支持移动和网络,您无需将 firebase 依赖项添加到您的 pubspec.yaml。这种依赖关系是导致上述问题的原因。但是,如果您以前依赖它,那么在将其从 pubspec.yaml 中删除后简单地运行 pub get 将无法消除此错误。您必须导航到上述@davidmcharo 描述的路径(flutter/.pub-cache/hosted/pub.dartlang.org/)并使用他的说明删除 firebase-7.3.0 文件夹。完成此操作后,您的移动应用程序应该会运行。
3) 有一些文章详细介绍了如何使用 Firebase 构建 Web 和移动跨平台应用程序,但它们很快就会过时。我能够在不使用 kIsWeb 全局指定 firebase 包的情况下让我的应用正常工作。
另一个注意事项:我遇到的一个问题是我可以让我的移动应用程序运行,但我的网络应用程序仍然存在问题,直到我从我的应用程序中删除实时数据库。我不小心在树中留下了一个访问我旧实时数据库的 StreamProvider,它阻止了 Web 应用程序正常运行。当您从 RTB 转换到 Cloud Firestore 时,请警惕任何挥之不去的实时数据库调用。
【讨论】:
【参考方案2】:Firebase 实时数据库无法在移动设备和网络上运行 - firestore、auth 和其他一些数据库可以。
您可以在此处找到移动设备和网络支持的 Firebase 库:
https://github.com/FirebaseExtended/flutterfire
【讨论】:
这意味着,我必须删除 firebase_database。如果我想在 Flutter Web 中使用 Firebase? 是的...或者您可以在网页上使用网页版,在手机上使用移动版。 好的!但是,你说的网页版/手机版具体是什么意思!!你能再解释一下吗! @JEEALI 他的意思是你必须开发两个单独的颤振应用程序。一个用于使用此插件的 ios/Android:pub.dev/packages/firebase_database,另一个用于使用此包的 Flutter Web:pub.dev/packages/firebase。不过,您可以很容易地在两个 Flutter 应用程序之间共享您的大部分代码库/小部件......(可以遵循符号链接)。 绝对不会..您只构建一个带有条件导入的应用程序..这意味着Stub
文件..a Switcher
仅包含方法声明和两个不同的实现文件WebRepository
文件(使用firebase
包)并包含web 包的所有方法覆盖,并且包含相同方法的DeviceRepository
覆盖但Android/iOS firebase_database
包。另外,当使用firebase
包(WEB)时,我使用Singleton
来初始化firebase..【参考方案3】:
Firebase 不适用于网络和移动设备。您将必须有两个独立的项目,一个用于 web 的具有 firebase 7.2.1 的项目,另一个用于移动设备的项目将没有 firebase 7.2.1。因此,为了使您的手机(android 和 iOS)正常工作,您必须从项目中卸载或删除 firebase 7.2.1。如果您想这样做,请执行以下操作:
1.转到您的 pubspec.yaml 文件,在其中的依赖项下,删除 firebase 7.2.1,或者如果您将其更新到 firebase 7.3.0 并且您拥有这两个依赖项,请删除它们。
2.然后,使用终端删除文件夹 firebase-7.2.1 和 firebase-7.3.0(如果您在 pub.dartlang.org 中同时拥有这两个文件夹)。以及如何删除它,是通过打开终端,然后转到您的颤振文件夹,然后在颤振文件夹中通过 cd .pub-cache 转到 .pub-cache,然后 cd hosts,然后 cd pub.dartlang.org。这是 pub.dartlang.org 的路径:flutter/.pub-cache/hosted/pub.dartlang.org/。然后在 pub.dartlang.org 中,键入以下命令删除文件夹 firebase-7.2.1,即:rm -r firebase-7.2.1,如果您有文件夹 firebase,则再输入 rm -r firebase-7.3.0 -7.3.0。
- 从上述步骤 2 中删除 firebase-7.2.1 和 firebase-7.3.0 文件夹后,运行 flutter clean,然后使用 android 或 iOS 模拟器再次运行您的应用,现在应该可以正常运行了。李>
【讨论】:
我开始使用 Firestore 而不是实时数据库。它解决了一切:) @JEEALI 如果您只需要可用于 WEB 和 Device 的包而不是全部排序,但如果您需要使用一些尚不支持的包(如我所做的),像Remote Config
你必须使用firebase
。稍后我会给出一个答案来展示整个过程..有一些样板代码要编写,但它可以工作..
好吧..实际上你可以在这里查看我自己的答案中的整个过程..***.com/questions/59670753/…以上是关于当我为flutter web添加firebase时,我的应用程序将无法运行的主要内容,如果未能解决你的问题,请参考以下文章
带有 Firebase 托管的 Flutter web 无法从存储中加载图片
Flutter web firebase/firestore错误运行
Flutter Web 在 Firebase 托管中不起作用
在 Flutter Web App 中使用 Firebase 实时数据库