Flutter Web - Firebase:没有创建 Firebase App '[DEFAULT]' - 调用 Firebase App.initializeApp() (app/no-app)
Posted
技术标签:
【中文标题】Flutter Web - Firebase:没有创建 Firebase App \'[DEFAULT]\' - 调用 Firebase App.initializeApp() (app/no-app)【英文标题】:Flutter Web - Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app)Flutter Web - Firebase:没有创建 Firebase App '[DEFAULT]' - 调用 Firebase App.initializeApp() (app/no-app) 【发布时间】:2021-07-13 00:37:15 【问题描述】:当我尝试运行 Flutter Web 版本时,我收到此错误消息 No Firebase App '[DEFAULT]' has created,Chrome 在运行 Web 应用程序后是空白的。
我所有的依赖项都是最新的。 firebase_analytics:^7.0.0 firebase_auth:^1.0.0 firebase_storage: ^8.0.0 cloud_firestore: ^1.0.4
我在 Main.dart 上添加了 firebase.initializeApp(),我按照指南 No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase
void main() async
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
final UserDataRepository userDataRepository = UserDataRepository();
final AuthenticationRepository authenticationRepository =
AuthenticationRepository();
runApp(
MultiBlocProvider(
providers: [
BlocProvider<OrdersBloc>(
create: (context) => OrdersBloc(
userDataRepository: userDataRepository,
),
),
BlocProvider<NewOrdersBloc>(
create: (context) => NewOrdersBloc(
userDataRepository: userDataRepository,
),
),
BlocProvider<PushNotificationsBloc>(
create: (context) => PushNotificationsBloc(
userDataRepository: userDataRepository,
),
),
],
child: MyApp(),
),
);
class MyApp extends StatelessWidget
// This widget is the root of your application.
final Future<FirebaseApp> initialization = Firebase.initializeApp();
@override
Widget build(BuildContext context)
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarBrightness: Brightness.dark,
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.light,
));
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Grocery Store Admin',
theme: ThemeData(
primarySwatch: Colors.blue,
primaryColorDark: Color(0xFF090682),
primaryColor: Color(0xFF060453),
accentColor: Color(0xFFF90A0A),
backgroundColor: Colors.white,
canvasColor: Colors.white,
),
initialRoute: '/',
routes:
'/': (context) => SplashScreen(),
'/initial_setup': (context) => InitialSetupScreen(),
'/splash_screen': (context) => SplashScreen(),
'/home': (context) => HomeScreen(),
'/sign_in': (context) => SignInScreen(),
,
);
我相信我的问题可能是在创建 html 以生成我的应用程序的 Web 版本。能否请支持指出在哪里
<!DOCTYPE html>
<html>
<head>
<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="grocery_store_admin">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<title>grocery_store_admin</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.2/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-analytics.js"></script>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator)
window.addEventListener('load', function ()
navigator.serviceWorker.register('flutter_service_worker.js');
);
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/bDUy8.png
【问题讨论】:
【参考方案1】:请将您的 firebase 网络配置文件添加到您的 index.html
例如:
<body>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.2/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-analytics.js"></script>
<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>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator)
window.addEventListener('load', function ()
navigator.serviceWorker.register('flutter_service_worker.js');
);
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
参考https://firebase.flutter.dev/docs/installation/web#initializing-firebase
【讨论】:
现在错误消息如下 -TypeError: dart.global.firebase.firestore is not a function at Object.getFirestoreInstance以上是关于Flutter Web - Firebase:没有创建 Firebase App '[DEFAULT]' - 调用 Firebase App.initializeApp() (app/no-app)的主要内容,如果未能解决你的问题,请参考以下文章
我是 Flutter Web 的新手,如何使用 Firebase 电话身份验证对用户进行身份验证,有没有办法让用户保持登录状态?
如何将 Flutter 项目迁移到 Firebase 版本 9 现代 Web 模块化风格
在没有 android studio 的情况下在本地运行 flutter web 应用程序会引发 firebase 错误
Flutter web firebase/firestore错误运行