skip to Main Content

I have used

 WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

in main function it is giving exception while debugging and emulator displays blank screen when it is runned without debugging

It is showing following exception ->
Exception has occurred.
PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null))

I have updated dependencies, also added firebase core and also updated it please help me in this problem

IMAGE OF MY CODE WHERE IT IS SHOWING ERROR

output of pub outdated

[*] indicates versions that are not the latest available.

Package Name              Current   Upgradable  Resolvable  Latest   

direct dependencies: all up-to-date.

dev_dependencies: all up-to-date.

transitive dependencies:
string_scanner            *1.1.0    *1.1.0      *1.1.0      1.2.0
term_glyph                *1.2.0    *1.2.0      *1.2.0      1.2.1
test_api                  *0.4.9    *0.4.9      *0.4.9      0.4.17
vector_math               *2.1.2    *2.1.2      *2.1.2      2.1.4
all dependencies are up-to-date.```

3

Answers


  1. Did you also run flutter clean and flutter pub get again?

    Otherwise can you run flutter pub outdated ans share the output?

    Login or Signup to reply.
  2. 1.Add to pubspec.yaml

    firebase_core :
    

    2.Add to main.dart

    import 'package:firebase_core/firebase_core.dart';
    
    void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    runApp(MyApp());
    }
    
    Login or Signup to reply.
  3. Check your Firebase SDK dependencies in Project build.gradle file and Application build.gradle file

    buildscript {
      repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
      }
      dependencies {
        ...
        // Add this line
        classpath 'com.google.gms:google-services:4.3.13'
      }
    }
    
    allprojects {
      ...
      repositories {
        // Check that you have the following line (if not, add it):
        google()  // Google's Maven repository
        ...
      }
    }
    

    And in your app level build.grandle:

    apply plugin: 'com.android.application'
    // Add this line
    apply plugin: 'com.google.gms.google-services'
    
    dependencies {
      // Import the Firebase BoM
      implementation platform('com.google.firebase:firebase-bom:30.2.0')
    
      // Add the dependency for the Firebase SDK for Google Analytics
      // When using the BoM, don't specify versions in Firebase dependencies
      implementation 'com.google.firebase:firebase-analytics'
    
      // Add the dependencies for any other desired Firebase products
      // https://firebase.google.com/docs/android/setup#available-libraries
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search