(SOLVED) No Firebase App ’[DEFAULT]’ has been created - call Firebase.initializeApp() Error in Flutter
I have encountered an error while creating an app stating that there is no firebase app. I checked on what the issue might be from my code and went to the internet for solutions to solve the problem but the solution provided does not solve my issue. The solution states that I should check whether I have properly initialized my app in the main.dart file(which I did) but I still get the error when I try to register a user. Any idea on how to sort this out? Here is my main.dart code
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:insta_leafy/responsive/mobile_screen_layout.dart';
import 'package:insta_leafy/responsive/responsive_layout_screen.dart';
import 'package:insta_leafy/responsive/web_screen_layout.dart';
import 'package:insta_leafy/screens/signup_screen.dart';
import 'package:insta_leafy/utils/colors.dart';
import 'package:insta_leafy/screens/login_screen.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
name: 'insta_leafy',
options: const FirebaseOptions(
//added the details
),
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Instagram Clone',
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: mobileBackgroundColor,
),
// home: const ResponsiveLayout(
// mobileScreenLayout: MobileScreenLayout(),
// webScreenLayout: WebScreenLayout(),
// ),
home: SignUpScreen(),
);
}
}
"leafy-clone.appspot.com",
Error -
E/flutter (19978): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
E/flutter (19978): #0 MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:193:5)
E/flutter (19978): #1 Firebase.app (package:firebase_core/src/firebase.dart:56:41)
E/flutter (19978): #2 FirebaseAuth.instance (package:firebase_auth/src/firebase_auth.dart:38:47)
E/flutter (19978): #3 new AuthMethods (package:insta_leafy/resources/auth_methods.dart:7:43)
E/flutter (19978): #4 _SignUpScreenState.build.<anonymous closure> (package:insta_leafy/screens/signup_screen.dart:121:38)
E/flutter (19978): #5 _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1183:21)
E/flutter (19978): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:275:24)
E/flutter (19978): #7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:652:11)
E/flutter (19978): #8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:309:5)
E/flutter (19978): #9 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:242:7)
E/flutter (19978): #10 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:630:9)
E/flutter (19978): #11 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
E/flutter (19978): #12 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:143:9)
E/flutter (19978): #13 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
E/flutter (19978): #14 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
E/flutter (19978): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
E/flutter (19978): #16 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:488:19)
E/flutter (19978): #17 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:468:22)
E/flutter (19978): #18 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:439:11)
E/flutter (19978): #19 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:413:7)
E/flutter (19978): #20 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:376:5)
E/flutter (19978): #21 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:323:7)
E/flutter (19978): #22 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:292:9)
E/flutter (19978): #23 _invoke1 (dart:ui/hooks.dart:328:13)
E/flutter (19978): #24 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:410:7)
E/flutter (19978): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31)
E/flutter (19978):
Solution:
First try this,
await Firebase.initializeApp(
name: 'insta_leafy',
options: const FirebaseOptions(
//added the details
),
);
If it hasn't worked, try this; it will work,
await Firebase.initializeApp(
name: 'your-app',
options: const FirebaseOptions(
apiKey: 'your api key',
appId: 'appId',
messagingSenderId: '',
projectId: 'your-app',
));
You can find all this details (apiKey, appId...) in google-services.json file.
Comments
Post a Comment