How to solve this issue? I need to check the user is logged in or not
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized. E/flutter (21284): If you're running an application and need to access the binary messenger before
runApp()
has been called (for example, during plugin initialization), then you need to explicitly call theWidgetsFlutterBinding.ensureInitialized()
first. E/flutter (21284): If you're running a test, you can call theTestWidgetsFlutterBinding.ensureInitialized()
as the first line in your test'smain()
method to initialize the binding. E/flutter (21284): #0 defaultBinaryMessenger. (package:flutter/src/services/binary_messenger.dart:76:7) E/flutter (21284): #1 defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:89:4) E/flutter (21284): #2 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:140:62) E/flutter (21284): #3 MethodChannel.setMethodCallHandler (package:flutter/src/services/platform_channel.dart:368:5) E/flutter (21284): #4 new FirebaseAuth._ (package:firebase_auth/src/firebase_auth.dart:15:13) E/flutter (21284): #5 FirebaseAuth.instance (package:firebase_auth/src/firebase_auth.dart:25:53) E/flutter (21284): #6 FirebaseAuth.instance (package:firebase_auth/src/firebase_auth.dart:25:29) E/flutter (21284): #7 main (package:alqaiser/main.dart:44:36) E/flutter (21284): #8 _runMainZoned.. (dart:ui/hooks.dart:239:25) E/flutter (21284): #9 _rootRun (dart:async/zone.dart:1126:13) E/flutter (21284): #10
_CustomZone.run (dart:async/zone.dart:1023:19) E/flutter (21284): #11 _runZoned (dart:async/zone.dart:1518:10) E/flutter (21284): #12 runZoned (dart:async/zone.dart:1502:12) E/flutter (21284): #13
_runMainZoned. (dart:ui/hooks.dart:231:5) E/flutter (21284): #14 _startIsolate. (dart:isolate-patch/isolate_patch.dart:307:19) E/flutter (21284): #15 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12) E/flutter (21284):
This is my man function
void main() async {
FirebaseAuth auth = FirebaseAuth.instance;
auth.currentUser().then((u) {
if (u == null?true:u.phoneNumber==null?true:false) {
runApp(MaterialApp(
home: PhoneAuth(),
));
} else {
runApp(MyApp());
}
}).catchError((e) {
print(e);
runApp(MyAppT2(e.toString() + ";"));
});
}