My code show error Firebase has not been correctly initialized.?
**Usually this means you've attempted to use a Firebase service before calling `Firebase.initializeApp`.
E/flutter (25616):
E/flutter (25616): View the documentation for more information: https://firebase.flutter.dev/docs/overview#initialization
E/flutter (25616):
E/flutter (25616): #0 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:99:9)
E/flutter (25616): <asynchronous suspension>
E/flutter (25616): #1 Firebase.initializeApp (package:firebase_core/src/firebase.dart:42:31)
E/flutter (25616): <asynchronous suspension>
E/flutter (25616): #2 main (package:a_store_online_shop/main.dart:11:3)
E/flutter (
25616): <asynchronous suspension>
E/flutter (25616):
It is our main.dart file which in occure error code firebase has not been correctly initialized.....................................................................................................................................................?
main.dart
import 'dart:async';
import 'package:firebase_core/firebase_core.dart';
import 'package:a_store_online_shop/Screens/main_screen.dart';
import 'package:a_store_online_shop/Screens/on_boarding_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_storage/get_storage.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await GetStorage.init();
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: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const SplashScreen(),
initialRoute: SplashScreen.id,
routes: {
SplashScreen.id: (context) => const SplashScreen(),
OnBoardingScreen.id: (context) => const OnBoardingScreen(),
},
);
}
}
class SplashScreen extends StatefulWidget {
const SplashScreen({Key? key}) : super(key: key);
static const String id = "splash-screen";
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
final store = GetStorage();
@override
void initState() {
Timer(const Duration(seconds: 3), () {
bool? _boarding = store.read('onBoarding');
_boarding == null
? Navigator.pushReplacementNamed(context, OnBoardingScreen.id)
: _boarding == true
? Navigator.pushReplacementNamed(context, MainScreen.id)
: Navigator.pushReplacementNamed(context, OnBoardingScreen.id);
});
super.initState();
}
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge, overlays: []);
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Image.asset("assets/images/logo.jpg"),
),
);
}
}
CodePudding user response:
So for everybody else getting this error I figured it out myself, for IOS, the line
Firebase.initializeApp()
it needs an option:
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform)
for that follow the instructions on this link: