Home > Back-end >  Flutter code doesn't run when firebase is initialized
Flutter code doesn't run when firebase is initialized

Time:12-27

So I have this code when I run it without initializing firebase; it works, but once I initialize firebase on the main.dart, it returns a black screen and some error:

Error:

Error: Assertion failed:

file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_web-2.0.2/lib/src/firebase_core_web.dart:228:11

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/\_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49  throw\_

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/\_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed

packages/firebase_core_web/src/firebase_core_web.dart 228:18                                                               initializeApp

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/\_internal/js_dev_runtime/patch/async_patch.dart 45:50            \<fn\>

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1653:54                                          runUnary

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 147:18                                    handleValue

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 766:44                                    handleValueCallback

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 795:13

\_propagateToListeners

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 566:5                                     \[\_completeWithValue\]C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future.dart 528:22                                         \<fn\>

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1653:54                                          runUnary

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 147:18                                    handleValue

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 766:44                                    handleValueCallback

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 795:13

\_propagateToListeners

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 566:5                                     \[\_completeWithValue\]C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 639:7                                     callback

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11                              \_microtaskLoop

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5                               \_startMicrotaskLoop

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/\_internal/js_dev_runtime/patch/async_patch.dart 166:15           \<fn\>

Here is the code:

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:snow_chat/splash_screen.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
    runApp(const MyApp());
  });
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    // ignore: prefer_const_constructors
    return ScreenUtilInit(
        designSize: const Size(375, 812),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (context, child) {
          return MaterialApp(
            debugShowCheckedModeBanner: false,
            title: 'Chat app',
            theme:
                ThemeData(primaryColor: const Color.fromRGBO(88, 110, 158, 1)),
            home: const SplashScreen(),
          );
        });
  }
}

I have not tried anything cause I have not found a solution on how to fix this issue. Can someone please help out?

CodePudding user response:

Make sure you are using flutterfire configure cmd to proper firebase setup in your flutter project

follow the steps given there

https://firebase.google.com/docs/flutter/setup?platform=android

  • Related