[Flutter] BlocListener

Raon·2023년 4월 29일
0

Flutter

목록 보기
14/24
post-thumbnail

BlocListener

BlocListener위젯의 형태는 아래와 같이 생겼다.

BlocListener<Bloc, State>(
  listener: (context, state) {
  	// some functions
  },
  child: SomeWidget(),
)

제네릭으로 선언된 Bloc(또는 Cubit)과 State를 통해 상태 값이 변하는 것을 감지하고 그에 따라 listener함수를 실행한다.

이 위젯의 좋은 점은 child에 선언된 위젯은 Bloc의 상태가 변경되도 다시 그려지지 않는다는 것이다.

나는 주로 state가 변하는 것에 따라 라우팅을 실행해야하는 경우 주로 쓰고 있다.

profile
Flutter 개발자

0개의 댓글