I am getting "binding has not yet been initialized" error when trying to connect firebase with flutter

29 views Asked by At

Please, any help would be appreciated and googling doesn't seem to be producing any proper solutions here. What confuses me even more is that this error now appears even when trying to run apps with no firebase or even async functions, making doing anything else in flutter essentially impossible for me now. I have been trying to learn firebase and have followed the steps as shown here without much issues. When googling the solution for the problem I am facing(error message at the end of the post), a common fix I have seen is adding just this line to the main function.


WidgetsFlutterBinding.ensureInitialized();

However I already have it and I still keep getting the same error again. Here is my void main function.

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

Here is the error in question:


Launching lib\main.dart on sdk gphone x86 64 in debug mode...
../../flutter/packages/flutter/lib/src/foundation/binding.dart:309:24: Error: String starting with ' must end with '.
          ErrorSummary('Binding has not yet been iException has occurred.Exception has occurred.
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:93: Error: Expected ',' before this.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:98: Error: Expected ',' before this.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:106: Error: Expected ',' before this.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:110: Error: Expected ',' before this.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:115: Error: Expected ',' before this.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:115: Error: Undefined name 'initialized'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:30: Error: 'done' isn't a type.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                             ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:22: Error: Expected identifier, but got 'this'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                     ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:35: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                  ^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:38: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                     ^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:46: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:90: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                         ^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:93: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:109: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:116: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:122: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:126: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:105: Error: Undefined name 'the'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:109: Error: Undefined name 'latter'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:116: Error: Undefined name 'calls'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:122: Error: Undefined name 'the'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:126: Error: Undefined name 'former'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:145: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:150: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:158: Error: 'done' isn't a type.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:150: Error: Undefined name 'call'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:163: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:163: Error: 'in' can't be used as an identifier because it's a keyword.
Try renaming this to be an identifier that isn't a keyword.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:166: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:170: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:184: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:184: Error: Undefined name 'method'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:196: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^^^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:216: Error: Expected ',' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:226: Error: 'idempotent' isn't a type.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:216: Error: Undefined name 'method'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:310:25: Error: Undefined name 'Binding'.
          FlutterError (Binding has not yet been initialized.
                        ^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:310:33: Error: Undefined name 'has'.
          FlutterError (Binding has not yet been initialized.
                                ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:310:37: Error: Undefined name 'not'.
          FlutterError (Binding has not yet been initialized.
                                    ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:310:41: Error: Undefined name 'yet'.
          FlutterError (Binding has not yet been initialized.
                                        ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:310:45: Error: Undefined name 'been'.
          FlutterError (Binding has not yet been initialized.
                                            ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:26: Error: Undefined name 'getter'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                         ^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:33: Error: Undefined name 'on'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                ^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:36: Error: Undefined name 'the'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                   ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:40: Error: Undefined name 'ServicesBinding'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                       ^^^^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:56: Error: Undefined name 'binding'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                       ^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:78: Error: Undefined name 'available'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                             ^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:88: Error: Undefined name 'once'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                       ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:93: Error: Undefined name 'that'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:98: Error: Undefined name 'binding'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:106: Error: Undefined name 'has'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:311:110: Error: Undefined name 'been'.
          The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:35: Error: Undefined name 'by'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                  ^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:38: Error: Undefined name 'calling'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                     ^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:90: Error: Undefined name 'or'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                         ^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:145: Error: Expected identifier, but got 'this'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:163: Error: Undefined name 'in'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:166: Error: Undefined name 'the'.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:310:24: Error: Too many positional arguments: 1 allowed, but 34 found.
Try removing the extra positional arguments.
          FlutterError (Binding has not yet been initialized.
                       ^
../../flutter/packages/flutter/lib/src/foundation/assertions.dart:789:11: Context: Found this candidate, but the arguments don't match.
  factory FlutterError(String message) {
          ^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:309:23: Error: Too many positional arguments: 1 allowed, but 2 found.
Try removing the extra positional arguments.
          ErrorSummary('Binding has not yet been iException has occurred.Exception has occurred.
                      ^
../../flutter/packages/flutter/lib/src/foundation/assertions.dart:311:3: Context: Found this candidate, but the arguments don't match.
  ErrorSummary(super.message) : super(level: DiagnosticLevel.summary);
  ^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/foundation/binding.dart:312:236: Error: Expected ']' before this.
          Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After ca
                                                                                          ^
Target kernel_snapshot failed: Exception

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\kaust\OneDrive\Documents\Flutter\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' line: 1297

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\kaust\OneDrive\Documents\Flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
Exception: Gradle task assembleDebug failed with exit code 1


Exited (1).

Any help would be appreciated.

As already stated, WidgetsFlutterBinding.ensureInitialized() does not work.

I am not sure if this helps, but I have tried to run the following gradle command :

cd android
./gradlew build --warning-mode all

and get the following output in terminal:

> Task :gradle:compileGroovy FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gradle:compileGroovy'.
> BUG! exception in phase 'semantic analysis' in source unit 'C:\Users\kaust\OneDrive\Documents\Flutter\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' Unsupported class file major version 64

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s
2 actionable tasks: 1 executed, 1 up-to-date

What I find more concerning is that now none of my flutter projects work and all show the same error, even those which do not have firebase connected to them. At this point I am not even sure whether this is an issue with firebase or something else. I am not sure how to interpret this, but I hope someone more knowledgeable than me can help me understand.

1

There are 1 answers

1
Kaustuv On

Ok turns out all I had to do was upgrade flutter.