- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在初始化 Firebase 和 Flutter 项目时遇到问题,而我刚刚更新了我的 firebase-tools
和 firebase
到 version 9 这是 modern web modular style 已经一个星期了,没有任何帮助 flutter 的文档仍然是根据 version 8 这是旧式兼容类型当我遵循 firebase 文档时,它更新了它的抛出错误。我需要你的帮助,firebase 和 flutter 专家请提供一些解决方案。
我得到的两个错误是,
core.dart:56 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'app')
at Object.app$ [as app] (core.dart:56)
at initializeApp (firebase_core_web.dart:68)
at initializeApp.next (<anonymous>)
at runBody (async_patch.dart:84)
at Object._async [as async] (async_patch.dart:123)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (firebase_core_web.dart:28)
at initializeApp (firebase.dart:42)
at initializeApp.next (<anonymous>)
at runBody (async_patch.dart:84)
at Object._async [as async] (async_patch.dart:123)
at Function.initializeApp (firebase.dart:38)
at main$ (main.dart:9)
at main$.next (<anonymous>)
at runBody (async_patch.dart:84)
at Object._async [as async] (async_patch.dart:123)
at main$ (main.dart:7)
at main (web_entrypoint.dart:19)
at main.next (<anonymous>)
at async_patch.dart:45
at _RootZone.runUnary (zone.dart:1613)
at _FutureListener.thenAwait.handleValue (future_impl.dart:155)
at handleValueCallback (future_impl.dart:707)
at Function._propagateToListeners (future_impl.dart:736)
at _Future.new.[_completeWithValue] (future_impl.dart:542)
at future.dart:401
at _RootZone.runUnary (zone.dart:1613)
at _FutureListener.then.handleValue (future_impl.dart:155)
at handleValueCallback (future_impl.dart:707)
at Function._propagateToListeners (future_impl.dart:736)
at _Future.new.[_completeWithValue] (future_impl.dart:542)
at async._AsyncCallbackEntry.new.callback (future_impl.dart:580)
at Object._microtaskLoop (schedule_microtask.dart:40)
at _startMicrotaskLoop (schedule_microtask.dart:49)
at async_patch.dart:166
和
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
js_primitives.dart:30 The following JSNoSuchMethodError was thrown building MyApp(dirty):
js_primitives.dart:30 TypeError: Cannot read properties of undefined (reading 'app')
js_primitives.dart:30
js_primitives.dart:30 The relevant error-causing widget was:
js_primitives.dart:30 MyApp file:///C:/Users/Neha/AndroidStudioProjects/devcom/lib/main.dart:10:10
js_primitives.dart:30
js_primitives.dart:30 When the exception was thrown, this was the stack:
js_primitives.dart:30 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49 throw_
js_primitives.dart:30 packages/firebase_core_web/firebase_core_web.dart 73:3 _catchJSError
js_primitives.dart:30 packages/firebase_core_web/src/firebase_core_web.dart 138:13 app
js_primitives.dart:30 packages/firebase_core/src/firebase.dart 55:41 app
js_primitives.dart:30 packages/firebase_auth/src/firebase_auth.dart 38:47 get instance
js_primitives.dart:30 packages/devcom/auth.dart 12:51 new
js_primitives.dart:30 packages/devcom/main.dart 17:13 build
js_primitives.dart:30 packages/flutter/src/widgets/framework.dart 4648:28 build
js_primitives.dart:30 packages/flutter/src/widgets/framework.dart 4574:15 performRebuild
js_primitives.dart:30 packages/flutter/src/widgets/framework.dart 4267:5 rebuild
js_primitives.dart:30 packages/flutter/src/widgets/framework.dart 4553:5 [_firstBuild]
js_primitives.dart:30 packages/flutter/src/widgets/framework.dart 4548:5 mount
js_primitives.dart:30 packages/flutter/src/widgets/framework.dart 3611:13 inflateWidget
js_primitives.dart:30 packages/flutter/src/widgets/framework.dart 3363:18 updateChild
js_primitives.dart:30 packages/flutter/src/widgets/binding.dart 1189:16 [_rebuild]
js_primitives.dart:30 packages/flutter/src/widgets/binding.dart 1159:5 mount
js_primitives.dart:30 packages/flutter/src/widgets/binding.dart 1104:16 <fn>
js_primitives.dart:30 packages/flutter/src/widgets/framework.dart 2535:19 buildScope
js_primitives.dart:30 packages/flutter/src/widgets/binding.dart 1103:12 attachToRenderTree
js_primitives.dart:30 packages/flutter/src/widgets/binding.dart 936:24 attachRootWidget
js_primitives.dart:30 packages/flutter/src/widgets/binding.dart 917:7 <fn>
js_primitives.dart:30 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19 internalCallback
js_primitives.dart:30
js_primitives.dart:30 ════════════════════════════════════════════════════════════════════════════════════════════════════
main.dart
:
import 'package:flutter/material.dart';
import 'package:devcom/auth.dart';
import 'package:devcom/auth_provider.dart';
import 'package:devcom/root_page.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AuthProvider(
auth: Auth(),
child: MaterialApp(
title: 'Flutter login demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: RootPage(),
),
);
}
}
index.html
:
<!DOCTYPE html>
<html>
<head>
<!-- <script src="https://www.gstatic.com/firebasejs/9.0.1/firebase-app.js" type = "module"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.1/firebase-analytics.js" type = "module"> </script>
<script src="https://www.gstatic.com/firebasejs/9.0.1/firebase-auth.js" type = "module"></script> -->
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!-- 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="devcom">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png" />
<title>Devcom</title>
<link rel="manifest" href="manifest.json">
</head>
<body >
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.0.1/firebase-app.js';
import { } from 'https://www.gstatic.com/firebasejs/9.0.1/firebase-auth.js';
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.0.1/firebase-analytics.js";
const firebaseConfig = {
apiKey: "...",
authDomain: "......",
databaseURL: ".....",
projectId: "...",
storageBucket: "",
messagingSenderId: "",
measurementId: "",
appId: "1:.........:web:...........",
};
const app = initializeApp({ firebaseConfig });
// const app = getAnalytics({ firebaseConfig })
</script>
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = 'main.dart.js';
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
}
if ('serviceWorker' in navigator) {
// Service workers are supported. Use them.
window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state == 'activated') {
console.log('Installed new service worker.');
loadMainDartJs();
}
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing ?? reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('Loading app from service worker.');
loadMainDartJs();
}
});
// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
</script>
</body>
</html>
最佳答案
您的 flutter 代码不遵循文档建议的内容,尤其是在何处以及如何执行 Firebase.initializeApp();
被称为。
这是直接来自 docs 的片段:
import 'package:flutter/material.dart';
// Import the firebase_core plugin
import 'package:firebase_core/firebase_core.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(App());
}
/// We are using a StatefulWidget such that we only create the [Future] once,
/// no matter how many times our widget rebuild.
/// If we used a [StatelessWidget], in the event where [App] is rebuilt, that
/// would re-initialize FlutterFire and make our application re-enter loading state,
/// which is undesired.
class App extends StatefulWidget {
// Create the initialization Future outside of `build`:
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
/// The future is part of the state of our widget. We should not call `initializeApp`
/// directly inside [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) {
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();
},
);
}
}
如您所见,该函数在 runApp(App());
之后被调用已被调用。不仅 Firebase.initializeApp();
返回 Future<FirebaseApp>
(您的代码中没有 await
),它是主要小部件状态的一部分。
关于firebase - 如何将 Flutter 项目迁移到 Firebase version-9 modern web modular style,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69077745/
我最近开始从事一个 Sails 项目。它目前在迁移表下具有以下格式的迁移。 20160826122004-create_users_table.js 'use strict'; module.expo
当我尝试迁移时 doctrine:migrations:migrate ,我收到此异常:“元数据存储不是最新的,请运行 sync-metadata-storage 命令来解决此问题。”。这仅在尝试在生
我在 ec2 linux 7 上有一个 MarkLogic 服务器。我想将它迁移到 linux 6。我将 ebs 移动到新的 linux 6 并将其安装在 /var/opt/MarkLogic . 我
我对 OpenID 很好奇。虽然我同意统一凭证的想法很棒,但我有一些保留意见。什么是防止 OpenID 提供商发疯并持有他们拥有的 OpenID 帐户直到您支付 n 美元?如果我决定不喜欢这个提供商,
使用 SQL 很容易做到这一点,但我需要编写一个我不熟悉的 Knex 迁移脚本。以下代码在 order 表中行的末尾添加了 order_id 列。我想在 id 之后添加 order_id。我该怎么做?
使用 SQL 很容易做到这一点,但我需要编写一个我不熟悉的 Knex 迁移脚本。以下代码在 order 表中行的末尾添加了 order_id 列。我想在 id 之后添加 order_id。我该怎么做?
我想通过在 Yii2 中的迁移添加一个新列,使用以下代码: public function up() { $this->addColumn('news', 'priority', $this-
我正在尝试在 SQLDelight 的表中添加更多列。我做了一个迁移文件 1.sqm .在迁移文件中,它给出了找不到表的错误。 我的 build.gradle.kts: sqldelight {
我有一个与 Flyway DB 迁移相关的问题。通常如何管理处理相同 DB 模式的多个项目(微服务)。每个项目中的 Flyway 迁移脚本如果被其他项目修改,则不允许启动。他们是否有任何文档或最佳实践
我是 Laravel 的新手。我做了一份待办事项申请作为一项学校作业。我们必须使用迁移来创建我们的数据库。 我使用迁移创建了 2 个表。我的问题是:如果你第一次在你的电脑上运行这个项目,有没有办法自动
我正在尝试在 Laravel 中创建外键,但是当我使用 artisan 迁移表时,出现以下错误: [Illuminate\Database\QueryException] SQLSTATE[HY000
我从 Django 1.7 升级到 Django 1.9。我有多次迁移。升级后我无法再创建新的数据库。 问题是“django manage.py migrate”运行检查。检查导入应用程序 URL。这
我在创建数据迁移方面遇到了困难。我的应用程序使用两个数据库。我在 settings.py 中配置了数据库,并创建了一个像 Django docs 中一样的路由器. # settings.py DB_H
我有一个像这样的sql结构: CREATE TABLE resources ( id SERIAL PRIMARY KEY, title TEXT NOT NULL, created_at
我正在尝试使用模式构建器向表添加枚举选项(不丢失当前数据集)。 我真正能够找到的关于列更改的唯一信息是 http://www.flipflops.org/2013/05/25/modify-an-ex
我尝试转移到一些 CMake 程序中,并且有一个从 xml 生成头文件的函数。 生成文件.am adaptor_glue.hpp: dbus_introspect.xml $(DBUSXX_X
我想将文件移至我的 iOS 应用程序的 CoreData 存储 ../Library/Application Support/MyApp/ 至 ../Documents/Stores/ 我可以使用 N
有没有人对数据迁移进出 NetSuite 有丰富的经验?我必须将 DB2 表导出到 MySQL,处理数据,然后导出到一个 CSV 文件中。然后获取帐户的 CSV 文件并再次操作数据以使帐户从我们的旧系
我正在尝试在 Django 上建立一个博客。我已经走到了创建模型的地步。他们在这里: from django.db import models import uuid class Users(mode
我最近使用 bluehost 上的 AutoSSL 工具将网站迁移到 HTTPS。我在内容中看到一些失真,例如缺少背景颜色、表格位移、缺少_logos 等。 有谁知道 HTTPS 迁移效果如何影响样式
我是一名优秀的程序员,十分优秀!