为了支持单个环境,以下代码在我的flutter web index.html中运行良好
<html>
...
<body>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<!-- Firebase Configuration -->
<script>
var firebaseConfig = {
apiKey: "...",
authDomain: "[YOUR_PROJECT].firebaseapp.com",
databaseURL: "https://[YOUR_PROJECT].firebaseio.com",
projectId: "[YOUR_PROJECT]",
storageBucket: "[YOUR_PROJECT].appspot.com",
messagingSenderId: "...",
appId: "1:...:web:...",
measurementId: "G-...",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
</body>
</html>
但是,如何在Flutter Web中支持多个Firebase环境?
例如,除了上述内容之外,我还希望有两个名为
dev
和
preprod
对于Dev,请使用不同的配置:
var firebaseConfigDev = {
apiKey: "...",
authDomain: "[YOUR_PROJECT_DEV].firebaseapp.com",
databaseURL: "https://[YOUR_PROJECT_DEV].firebaseio.com",
projectId: "[YOUR_PROJECT_DEV]",
storageBucket: "[YOUR_PROJECT_DEV].appspot.com",
messagingSenderId: "...",
appId: "1:...:web:...",
measurementId: "G-...",
};
对于预印本,另一种配置
var firebaseConfigPreprod = {
apiKey: "...",
authDomain: "[YOUR_PROJECT_PREPROD].firebaseapp.com",
databaseURL: "https://[YOUR_PROJECT_PREPROD].firebaseio.com",
projectId: "[YOUR_PROJECT_PREPROD]",
storageBucket: "[YOUR_PROJECT_PREPROD].appspot.com",
messagingSenderId: "...",
appId: "1:...:web:...",
measurementId: "G-...",
};
我在互联网和StackOverflow上到处搜索,找不到如何实现这一点的例子。然而,我在Android上找到了它,它很容易
How to maintain two google-services.json, production and debug
以及使用构建风格。
但在flutter web中,什么是build flavores和google服务json的等价物?