Flutter 应用程序在集成 Firebase 后显示空白屏幕

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

该应用程序仍然只显示空白屏幕。这是我的主要应用程序代码:

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';

void main() async {
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Firebase Integration')),
        body: Center(child: Text('Hello, Firebase!')),
      ),
    );
  }
}

任何帮助或建议将不胜感激!

flutter firebase dart
1个回答
0
投票

看起来您缺少 WidgetsFlutterBinding.ensureInitialized();在初始化 Firebase 之前:

void main() async {
  WidgetsFlutterBinding.ensureInitialized(); // Add this line
  await Firebase.initializeApp();
  runApp(MyApp());
}
© www.soinside.com 2019 - 2024. All rights reserved.