Firebase must be initialized before the app UI starts. Calling WidgetsFlutterBinding.ensureInitialized() ensures Flutter is ready, then await Firebase.initializeApp() sets up Firebase. This must happen before runApp().
FirebaseAuth throws a FirebaseAuthException with a specific error code like wrong-password when sign-in fails due to incorrect password. This allows the app to handle errors gracefully.
Flutter hot reload preserves the app state including initialized Firebase instances. This means Firebase does not reinitialize on hot reload, allowing faster development without losing Firebase connection.
You should navigate only after the sign-in completes successfully. Calling Navigator.pushReplacement inside the success callback ensures the user sees the home screen only when authenticated.
The correct way is to make main() async, call WidgetsFlutterBinding.ensureInitialized() before awaiting Firebase.initializeApp(), then call runApp(). This ensures Flutter and Firebase are ready.