在我的 flutter 项目中安装 firebase 后我在运行应用程序时遇到问题问题是应用程序没有启动

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

flutter 应用程序不再启动以在我的模拟器中查看 在我的代码中没有检测到错误我认为问题与 firebase 有关但我实际上不知道

这里是代码:

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:test123/routes.dart';
import 'package:test123/theme.dart';



// Import the firebase_core plugin

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 {
  

  @override
  State<App> 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 Text('error');
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return MaterialApp(
            routes: appRoutes,
            theme: appTheme,
            );
          
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return Text('loading');
      },
    );
  }
}


import 'package:test123/profile/profile.dart';
import 'package:test123/login/login.dart';
import 'package:test123/home/home.dart';
import 'package:test123/topics/topics.dart';
import 'package:test123/about/about.dart';

var appRoutes = {
  '/': (context) => const HomeScreen(),
  '/login': (context) => const AboutScreen(),
  '/topics': (context) => const ProfileScreen(),
  '/profile': (context) => const TopicsScreen(),
  '/about': (context) => const LoginScreen(),
};
import 'package:flutter/material.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({ Key? key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          child: Text('about'),
          onPressed: () => Navigator.pushNamed(context, '/about'),
        ),
      ),
    );
  }
}

我想知道我的问题在哪里 我认为问题与我设置 firebase 项目的 bundle ID 有关,但我似乎没有在 runner.xcworkspace 中找到我的项目的 Bundle ID

flutter firebase visual-studio-code
© www.soinside.com 2019 - 2024. All rights reserved.