skip to Main Content
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if (kIsWeb) {
    await Firebase.initializeApp(
      options: const FirebaseOptions(
        apiKey: "",
        appId: "",
        messagingSenderId: "",
        projectId: "",
        storageBucket: "",
      ),
    );
  } else {
    await Firebase.initializeApp();
  }
  runApp(const MyApp());
}

Exception has occurred.
PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null))

2

Answers


  1. You should add your Firebase project to your Flutter App.
    Here is the link how to do that https://firebase.google.com/docs/flutter/setup?platform=web.
    After adding it properly, Firebase generates a config file then your code will be

    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(
         options: DefaultFirebaseOptions.currentPlatform,
      );
      runApp(const MyApp());
    }
    

    Hope this helps.

    Login or Signup to reply.
  2. In addition to above answer that’s because

    await Firebase.initializeApp();
    

    is deprecated so becareful (Most of the content is using the old way).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search