如何根据风格(环境或构建变体)将 Flutter Web 配置到 Firebase 托管?

问题描述 投票:0回答:1

我一直致力于将基于 Flutter 风格的 Firebase 项目分离为开发、暂存和生产。我已经阅读了很多文章,并为 ios 和 android(目前只有两个环境)设置了用于 staging 和 prod 的 Firebase 项目。但是,我在集成到Firebase Hosting时遇到了一个问题,

<meta name="google-signin-client_id" content="MY_GOOGLE_SIGNIN_CLIENT_ID" />
无法根据环境进行相应设置。
这是我的 web 文件夹下的index.html。 (网页/index.html)

<!DOCTYPE html>
<html>
<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    This is a placeholder for base href that will be replaced by the value of
    the `--base-href` argument provided to `flutter build`.
  -->
  <base href="$FLUTTER_BASE_HREF">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">
  // whichever placed first below recognized as the targeted google signin client id
  <meta name="google-signin-client_id" content="MY_GOOGLE_SIGNIN_CLIENT_ID_FOR_STAGING" />
  <meta name="google-signin-client_id" content="MY_GOOGLE_SIGNIN_CLIENT_ID_FOR_PROD" />

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="MY_PROJECT_NAME">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>MY_PROJECT_NAME</title>
  <link rel="manifest" href="manifest.json">

  <script>
    // The value below is injected by flutter build, do not touch.
    const serviceWorkerVersion = "{{flutter_service_worker_version}}";
  </script>
  <!-- This script adds the flutter initialization JS code -->
  <script src="flutter.js" defer></script>
</head>
<body>
  <script src="flutter_bootstrap.js" async></script>
</body>
</html>

与我为 Android 和 ios 分离环境所做的工作不同,我在任何地方都找不到任何使用 Firebase Hosting for Flutter Web 分离环境的线索(实际上我发现它使用脚本文件here管理多个 index.hteml 文件,其中我不喜欢)。
我想实现根据风格将 Flutter Web 配置到 Firebase 托管。 如果有人可以帮助我提供详细说明,我将非常感激。

flutter firebase firebase-hosting android-flavors
1个回答
0
投票

您不能在 Web 应用程序中使用风味功能,这只是 Android 和 iOS 功能:https://docs.flutter.dev/deployment/flavors

在这种情况下我能看到的唯一解决方案:准备单独的脚本来构建开发/登台。在构建之前,您的脚本需要使用 firebase 相关配置内容替换/符号链接文件。

© www.soinside.com 2019 - 2024. All rights reserved.