【问题标题】:Flutter:How can we use Firebase database with desktop applicationFlutter:我们如何在桌面应用程序中使用 Firebase 数据库
【发布时间】:2020-10-25 20:39:09
【问题描述】:

我正在考虑使用 dart 和 Flutter 开发桌面应用程序,但我不知道如何将 Firebase 数据库与其集成。 任何建议将不胜感激。 提前致谢

【问题讨论】:

    标签: firebase flutter


    【解决方案1】:

    使用 Firedart 包将 FIrebase 集成到基于桌面的 Flutter 应用程序中。

    https://pub.dev/packages/firedart

    文档说

    这个库试图最小化依赖关系,目的是 使其能够在任何能够执行 dart 的环境中运行 代码。目前已使用 dart 运行时成功测试 (x86-64 和 arm32)以及 Flutter Android、iOS 和桌面。

    【讨论】:

    • 目前似乎没有工作。按照文档中的示例代码,我收到错误Handling error gRPC Error (code: 1, codeName: CANCELLED, message: Disconnecting idle stream. Timed out waiting for new targets
    • 最好写一个新问题而不是评论。因为该错误与此问题无关。
    【解决方案2】:

    main FlutterFire page 有一个表格,显示了哪些 Firebase 产品在哪些环境中工作。

    现在表明这些产品在 macOS 桌面应用程序中受支持:

    • Cloud Firestore
    • 云函数
    • Firebase 身份验证
    • Firebase Crashlytics
    • Firebase 存储

    如果您在完成其中一项工作时遇到问题,请编辑您的问题以包含 minimal information with which we can reproduce where you got stuck 以及您收到的任何错误消息。

    【讨论】:

    • 我可以在windows app中使用这些产品吗?
    • 我链接的文档只提到了 macOS,main Flutter desktop documentation 还说 Windows 和 Linux 正在更积极的开发中。另一方面,this one 之类的帖子表明,有些人已经获得了在 Windows 上运行的 Flutter 应用程序。如果您在使用它时遇到问题,请发布您尝试过的内容以及遇到问题的地方,有人可能会尝试提供帮助。
    • FlutterFire 插件均不支持 Windows 或 Linux;这就是为什么图表中只列出了 macOS。
    • 你检查过firedartpub.dev/packages/firedart 在文档中,它说该包可以在任何基于 dart 的应用程序中使用。
    • @FathahKodag 我查看了整个浏览器历史记录,以便再次找到此评论。我需要在 Flutter - Windows 上使用 Firestore,而 fireart 为我工作。非常感谢!
    【解决方案3】:

    上下文: 截至 2021 年 2 月 24 日,在 Flutter 中支持 Firebase 服务的主要项目可以在 here 找到。如果您查看 GitHub 上提出的这个问题,它会为正在查看支持桌面的“possibility”的项目提供粗略的路线图。

    issue 已打开以提供对 Windows 和 Linux 的支持。

    回答: 现在,将 Firebase 与您的桌面应用程序一起使用的最佳选择是 -

    1. 阅读每个 Firebase 服务的文档,看看它们是否支持 RESTful API 请求以与服务交互。例如Cloud Firestore 支持这个。
    2. firedart 是为某些 Firebase 服务提供 API 的开源尝试。
    3. 等待 ("hopefully") Google 提供一个用 dart 原生编写的包。

    【讨论】:

    • 这个问题现在是一个讨论(功能请求)github.com/FirebaseExtended/flutterfire/discussions/5557
    • 我正在用 Flutter 编写一个 Windows 桌面应用程序,它与运行良好的手机应用程序共享很多代码,在 Firebase.initializeApp 上我得到了臭名昭著的“missingpluginexception(没有找到方法 firebase# 的实现)在通道 plugins.flutter.io/firebase_core) 上初始化内核”错误。显然,这是因为 Windows 尚不支持。我尝试切换到 fireart,这非常好,但它不支持 FirebaseStorage,即存储文件,尤其是图像。 Auth 和 Firebase DB 工作正常,不过,只需对代码进行少量更改。将等待 Windows 支持。
    【解决方案4】:

    【讨论】:

      【解决方案5】:

      我使用 http 方法将 Firebase 与我的 Windows Flutter 应用程序连接起来; 代码和快照如下。 Firebase 实时数据库完美运行。 我按照这个教程 https://medium.com/flutterdevs/http-request-dcc13e885985

      我的代码是:

      import 'dart:convert';
      
      import 'package:flutter/material.dart';
      import 'package:http/http.dart' as http;
      
      void main() => runApp(new MyApp());
      
      class MyApp extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          return new MaterialApp(
            title: 'Flutter Demo',
            theme: new ThemeData(
              primarySwatch: Colors.blue,
            ),
            home: new MyHomePage(),
          );
        }
      }
      
      class MyHomePage extends StatefulWidget {
        @override
        _MyHomePageState createState() => new _MyHomePageState();
      }
      
      
      
      class _MyHomePageState extends State<MyHomePage> {
        int _counter = 0;
      
        void _incrementCounter() {
          setState(() {
            _counter++;
          });
          sendData();
        }
      
        sendData() {
          http.post(
              Uri.parse(
                  "https://rest-12bb2-default-rtdb.firebaseio.com/userprofile.json"),
              body: json.encode({
                'firstName': "b",
                'lastName': "c",
                'email': "f",
              }));
          // setState(() {
          //   userProfile.add(Profile(
          //     firstName: firstname;
          //     lastName: lastname;
          //     email: email;
          //   ));
          // });
        }
      
        @override
        Widget build(BuildContext context) {
          return new Scaffold(
            appBar: new AppBar(
              title: new Text("app"),
            ),
            body: new Center(
              child: new Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  new Text(
                    'You have pushed the button this many times:',
                  ),
                  new Text(
                    '$_counter',
                    style: Theme.of(context).textTheme.display1,
                  ),
                ],
              ),
            ),
            floatingActionButton: new FloatingActionButton(
              onPressed: _incrementCounter,
              tooltip: 'Increment',
              child: new Icon(Icons.add),
            ),
          );
        }
      }
      

      //////////// firebase 快照enter image description here

      【讨论】:

        猜你喜欢
        • 2023-02-07
        • 2021-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-09
        • 1970-01-01
        相关资源
        最近更新 更多