网页中的 Flutter Firebase 实时数据库 [英] Flutter firebase realtime database in web

查看:27
本文介绍了网页中的 Flutter Firebase 实时数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的 Flutter 应用程序在浏览器中运行,这取决于 firebase_database.实际上没有任何关于如何执行此操作的文档,但我根据 firebase_core 和 firebase_auth 文档做出了一些假设:

I'm trying to get my flutter app working in the browser and it depends on firebase_database. There is not really any documentation for how to do this, but I'm making some assumptions based off the firebase_core and firebase_auth documentations:

https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_auth/firebase_auth_web

我的应用可以在 iOS 和 android 上运行,但我无法让数据库在 flutter web 中运行.

My app is working on iOS and android, but I'm having trouble getting the database working in flutter web.

我已经设置了我的 index.html:

I've set up my index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Flutter WebRTC Demo</title>
</head>
<body>
    <script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-database.js"></script>
    <script>
        const firebaseConfig = {
            apiKey: '...',
            authDomain: '...',
            databaseURL: '...',
            projectId: '...',
            storageBucket: '...',
            messagingSenderId: '...',
            appId: '...'
        };
        firebase.initializeApp(firebaseConfig);
    </script>
    <script src="main.dart.js" type="application/javascript"></script>
</body>
</html>

但是,当我尝试使用 firebase 数据库时,日志中出现错误:

But, when I try to use the firebase database, I get errors in the logs:

MissingPluginException(No implementation found for method DatabaseReference#set on channel plugins.flutter.io/firebase_database)
package:dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 196:49  throw_
package:flutter/src/services/platform_channel.dart 319:7                              invokeMethod
package:dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 47:50            onValue
package:dart-sdk/lib/async/zone.dart 1381:54                                          runUnary
package:dart-sdk/lib/async/future_impl.dart 139:18                                    handleValue
package:dart-sdk/lib/async/future_impl.dart 680:44                                    handleValueCallback
package:dart-sdk/lib/async/future_impl.dart 709:32                                    _propagateToListeners
package:dart-sdk/lib/async/future_impl.dart 524:5                                     [_completeWithValue]
package:dart-sdk/lib/async/future_impl.dart 554:7                                     callback
package:dart-sdk/lib/async/schedule_microtask.dart 43:11                              _microtaskLoop
package:dart-sdk/lib/async/schedule_microtask.dart 52:5                               _startMicrotaskLoop
package:dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 168:15           <fn>

有什么方法可以让实时数据库在网络上的 Flutter 应用程序中工作?

Is there any way I can get the realtime database working in my flutter app on the web?

推荐答案

UPDATE 2021现在支持对 firebase 数据库的 Web 支持.请参阅PR 此处.

UPDATE 2021 Web support for firebase database is now supported. See PR here.

flutterfire github中的主要README中,有一个"网络?列注意哪些插件可以用于网络.

In the main README in the flutterfire github, there is a "Web?" column that to note which plugins are ready for web.

目前,flutter 网络应用仅支持 firebase_corefirebase_authcloud_firestorefirebase_functions.

Currently, only firebase_core, firebase_auth, cloud_firestore, and firebase_functions are supported in flutter web apps.

正如@Frank van Puffelen 提到的,要在 flutter web 中使用 firebase 的全部功能,请使用 firebase-dart 包装库.

As @Frank van Puffelen mentioned, to use the full functionality of firebase in flutter web, use the firebase-dart wrapper library.

还有一个 Flutter Web Plugins Project Board 显示哪些 Flutter 插件是在路线图上,以及他们处于什么发展阶段.在进行此编辑时,firebase_storage 是网络路线图上的下一个插件.

There is also a Flutter Web Plugins Project Board that shows which flutter plugins are on the roadmap, and what stage of development they are at. At the time of this edit, firebase_storage is the next plugin on the web roadmap.

这篇关于网页中的 Flutter Firebase 实时数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆