【问题标题】:Start with an existing cloud functions Flutter Project从现有的云功能 Flutter 项目开始
【发布时间】:2021-05-18 04:32:31
【问题描述】:

我用firebase云函数初始化了一个Flutter项目,并选择typescript作为我的Node12文件的语言,我的同事需要拉Github repo和分支,他初始化云函数的正确步骤是什么?他应该执行常规的初始化命令吗?因为在尝试部署更改时出现以下错误

【问题讨论】:

  • 你完成here列出的步骤了吗?
  • 是的,已初始化并在我这边 100% 工作,当我的同事拉出他无法使用的 repo 时,我们认为他也必须在他这边进行初始化,我们按照初始化步骤使用没有运气
  • 好的,谢谢分享。在 Android 上,我们还需要启用明文流量,否则请求将被阻止。在 iOS 上,我们还需要在 ATS 中允许本地网络。你试过吗?
  • 我有,我已经为我们的问题列出了一个快照,应用程序运行良好但无法部署云功能
  • 好的,其他用户的文件路径是否正确?

标签: firebase flutter google-cloud-functions


【解决方案1】:

通常,只要您已将初始化的应用程序推送到版本控制,您就不需要运行所有初始化步骤两次。只需flutter run 在新机器上应该没问题。如果您已经运行了两次初始化,则删除该本地副本,重新克隆并执行flutter run

如果这不起作用,那么您可能需要深入研究。根据平台(Web、iOS 或 Android)以及您是在 Firebase 模拟器还是实际端点上运行,您可能需要更改一些设置。您还可以检查您的网络连接。

  1. 在调试 iOS 应用程序时使用 Firebase 模拟器时,您可能会收到有关 App Transport Security 的错误消息。要修复它,您需要在Info.plist 中设置允许本地网络:

  2. 在 Android 上,如果不在 AndroidManifest.xml 中启用此功能,您将无法请求 8.0+:

<application
  android:usesCleartextTraffic="true"
/>
  1. 在Web上,还需要将依赖添加到index.html

<html>
  <body>
    <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-functions.js"></script>
  </body>
</html>

如果您仍然遇到问题,那么值得将调试器附加到进程并在初始化时捕获错误:

例如:

import 'package:flutter/material.dart';

// Import the firebase_core plugin
import 'package:firebase_core/firebase_core.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(App());
}

class App extends StatelessWidget {
  // Create the initialization Future outside of `build`:
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      // Initialize FlutterFire:
      future: _initialization,
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          print(snapshot.error.toString()); // <---- Print the error out here.
          return SomethingWentWrong();
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return MyAwesomeApp();
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return Loading();
      },
    );
  }
}

如果这不能解决您的问题,请提供有关您的设置的更多详细信息。

【讨论】:

  • 很抱歉没有提供有关该问题的更多具体细节,应用程序本身在运行 Flutter run 时运行良好,当我的同事尝试编辑云函数的主 ts 文件并出现错误时出现此问题尝试部署时,我会将错误的快照放在问题中。非常感谢
猜你喜欢
  • 2021-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-11
  • 2018-12-03
  • 1970-01-01
  • 2020-05-21
相关资源
最近更新 更多