728x90

시작에 앞서.

 

많은 bloc강의가 있지만

Flutter Korea 오픈채팅 커뮤니티에서 추천을 받은 [유튜버 헤비프랜님] 의 강의로 시작했다.

BLoC 패턴이란?

BLoC (business Logic Component)는 파올로 소아레스와 콩 후이라는 개발자에 의해 디자인되었고

2018년 DartConf에서 발표되었습니다.

BLoC는 Presentation Layer와 business Logic을 분리하여 코드를 작성할 수 있도록 해줍니다.

 

https://beomseok95.tistory.com/312

 

 

 

헤비프랜(HeavyFan) - Flutter

flutter_bloc 6.x.x

https://youtu.be/JqbV4OtKAtA

더보기

 

 

 

 

카운터앱

  • Cubit
  • Bloc

BlocProvider -> MultiBlocProvider 메인에 선언해서 배열안에 여러개 씀.

BlocObserver로 전역에서 큐빗과 블락을 트래킹한다. ( 디버깅유용함 )

 

## 자 그럼 언제 큐빗을 쓰고 언제 블락을 쓸까?

>>  이벤트 등록이 큐빗으로 먼저 진행하고 나중에 블락으로 리팩토링.. 하는걸 추천한다고함. 근... 나중에 리팩토링....?

리덕스(?)도 훌륭한 대한이 될수 있음.

공식문서에는 Why Bloc? 에 대해 이렇게 설명한다.

Why Bloc?

더보기

Bloc makes it easy to separate presentation from business logic, making your code fast, easy to test, and reusable.

When building production quality applications, managing state becomes critical.

As developers we want to:

  • know what state our application is in at any point in time.
  • easily test every case to make sure our app is responding appropriately.
  • record every single user interaction in our application so that we can make data-driven decisions.
  • work as efficiently as possible and reuse components both within our application and across other applications.
  • have many developers seamlessly working within a single code base following the same patterns and conventions.
  • develop fast and reactive apps.

Bloc was designed to meet all of these needs and many more.

There are many state management solutions and deciding which one to use can be a daunting task. There is no one perfect state management solution! What's important is that you pick the one that works best for your team and your project.

Bloc was designed with three core values in mind:

  • Simple: Easy to understand & can be used by developers with varying skill levels.
  • Powerful: Help make amazing, complex applications by composing them of smaller components.
  • Testable: Easily test every aspect of an application so that we can iterate with confidence.

Overall, Bloc attempts to make state changes predictable by regulating when a state change can occur and enforcing a single way to change state throughout an entire application.

 


 

느낌

코드량이 많았다. (강사도 이런 긴 코드량 때문에 진입장벽을 느끼는것 같다고 함)

사실 이것만 봐서 뭐가 장점인지 확실하게는 모르겠다.

Getx로 다 되는거 아니야? 라는 심정

뭔가 느낌적인 느낌으로는 Cubit, Bloc 이라는 오브젝트에 모든 상태를 넣고 필요할때 꺼내서 쓸수 있는 느낌??? 잘 모르겠다.

카운터 예제만으로는 명확하게 어떤점때문에 블락을 써야하는지 모르겠다

결론, 튜토리얼 예제말고 구조가 좀더 있는 앱으로 다뤄봐야 겠다.

그리고, 큐빗이 블락보다 좀더 간편하게 쓸수있는것 같고, 블락은 그에 반해 원칙에 충실한 우직한 녀석인것 같다

막판에 앱 전역에 BlocObserver를 달았더니 인터렉션이 상세히 로깅되는걸 볼수있었다.

 

 

아무래도 이런점이 서비스가 점점 복잡하고 커질수록 강점이 되는 한 부분같다. 

 

실습환경

dart 2.0.7 (널세이프티 이전버전)

bloc 6.0.1

flutter_bloc 6.0.1

 

배워야 하는 단어

abstract class [ 앱스트랙트 ] - 추상클래스***

async* - [어싱크 스타] - 함수를 리턴으로 종료시키지않고 계속해서 이벤트를 수신대기한다. ( 

yield [이-일드]

yield* [일드 스타]

리덕스?

 

 

ref. 헤비프랜(HeavyFan)

+ Recent posts