[FrameWork]Flutter

[Flutter]파이어 베이스 초기화시 화면 안나옴

sungwoo 2023. 5. 13. 01:08
반응형

 

서론

플러터에 파이어베이스를 연동하려고 하는데 초기화 코드를 작성하니 디버그 콘솔에서 처리되지 않은 예외가 있다고 하고 위젯이 로딩되지 않는 현상이 있다.

관련 메시지를 검색하니 아래의 스택오버플로우 Q&A가 나왔고 이를 통해 해결했다

Flutter: Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized

 

Flutter: Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized

Any solution to solve this problem? Stacktrace: [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized. If y...

stackoverflow.com

 

결론

결론은 파이어 베이스를 초기화 하기 전에 아래의 코드를 추가해주면 된다

WidgetsFlutterBinding.ensureInitialized();

 

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

아래의 아키텍처 확인 바람

아키텍처
플러터 아키텍처 레이어

2022.12.06 - [[FrameWork]Flutter/FireBase] - [FireBase] Flutter 프로젝트와 FireBase 연동하기

 

[FireBase] Flutter 프로젝트와 FireBase 연동하기

작업공간 준비 Firebase CLI 설치 및 로그인(firebase login 실행) 2022.12.06 - [Flutter(플러터)/FireBase] - [FireBase] 파이어베이스 CLI 설치하기 Flutter SDK 설치 Flutter 프로젝트 만들기(flutter create 실행) [FireBase] 파

ai-sw.tistory.com

 

반응형