简体   繁体   English

在 Flutter Web App 中使用 Firebase 实时数据库

[英]Use Firebase Realtime Database in Flutter Web App

I'm a beginner in Flutter and I want to connect my Flutter Web App to Firbase Realtime Database .我是 Flutter 的初学者,我想将我的Flutter Web 应用程序连接到Firbase 实时数据库 My goal is to add some sample data inside the database when I click a button.我的目标是在单击按钮时在数据库中添加一些示例数据。

At this moment I have added inside the web/index.html file the following此时我在web/index.html文件中添加了以下内容

<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>

<script>
    var firebaseConfig = {
      apiKey: "...",
      authDomain: "...",
      databaseURL: "...",
      projectId: "...",
      storageBucket: "...",
      messagingSenderId: "...",
      appId: "...",
      measurementId: "...",
    };
    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
    firebase.analytics();
</script>

In my pubspec.yaml file I have added the following dependencies:在我的pubspec.yaml文件中,我添加了以下依赖项:

firebase: ^7.3.2
firebase_core: ^0.5.2
firebase_database: ^4.3.0

My main.dart file contains a simple main() function like below我的main.dart文件包含一个简单的main() function 如下所示

void main() {
  runApp(MyApp());
}

And the MyApp() stateless widget.MyApp()无状态小部件。

Do I have to use the .initializeApp() and pass inside it the project's constraints (apiKey, authDomain etc.)?我是否必须使用.initializeApp()并在其中传递项目的约束(apiKey、authDomain 等)?

Can someone give me some hints because i have no idea what to do, i'm pretty much confused at this moment.有人可以给我一些提示,因为我不知道该怎么做,我现在很困惑。

Thank you for your time感谢您的时间

If you look at the platform support table on firebase.flutter.dev , you'll see that the FlutterFire libraries don't support accessing Realtime Database in web apps yet.如果您查看firebase.flutter.dev上的平台支持表,您会发现 FlutterFire 库不支持访问 web 应用程序中的实时数据库。 Work to add support is under way, but there's no estimate on when it will be released.增加支持的工作正在进行中,但没有估计何时发布。

For the moment, if you want to use the Firebase Realtime Database in a Flutter web app, you'll have to use the firebase-dart library .目前,如果您想在 Flutter web 应用程序中使用 Firebase 实时数据库,则必须使用 firebase firebase-dart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM